]> gitweb.fluxo.info Git - borger.git/commitdiff
Support for local backups
authorSilvio Rhatto <rhatto@riseup.net>
Wed, 23 May 2018 15:44:36 +0000 (12:44 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Wed, 23 May 2018 15:44:36 +0000 (12:44 -0300)
README.md
borger

index 55398d1a90c95a6261afa2e044ac563c6442ffc9..c3589879cb76d65416052a35dc73eec80ac93151 100644 (file)
--- a/README.md
+++ b/README.md
@@ -12,35 +12,58 @@ A script for home folder backups using [Borg](https://borgbackup.readthedocs.io)
 
 Create a config for your `servername` destination at `~/.config/borger/servername`:
 
-     # Backup destination
-     export SSH_SERVER="user@host"
-     export SSH_PORT="2202"
+    # Backup destination
+    export SSH_SERVER="user@host"
+    export SSH_PORT="2202"
   
-     # Repository path
-     export BORG_REPO_DIR="/var/backups/users/$USER/borg"
-     export BORG_REPO="ssh://$SSH_SERVER:$SSH_PORT/$BORG_REPO_DIR"
+    # Repository path
+    export BORG_REPO_DIR="/var/backups/users/$USER/borg"
+    export BORG_REPO="ssh://$SSH_SERVER:$SSH_PORT/$BORG_REPO_DIR"
   
-     # Setting one of those, so you won't be asked for your repository passphrase:
-     #export BORG_PASSPHRASE='HACKME'
-     #export BORG_PASSCOMMAND='pass show backup'
-     #export BORG_PASSCOMMAND='keyringer default decrypt borg 2> /dev/null'
+    # Setting one of those, so you won't be asked for your repository passphrase:
+    #export BORG_PASSPHRASE='HACKME'
+    #export BORG_PASSCOMMAND='pass show backup'
+    #export BORG_PASSCOMMAND='keyringer default decrypt borg 2> /dev/null'
   
-     # Backup config
-     keepdaily="7"
-     keepweekly="4"
-     keepmonth="6"
-     encryption="keyfile"
-     placeholder="{user}"
+    # Backup config
+    keepdaily="7"
+    keepweekly="4"
+    keepmonth="6"
+    encryption="keyfile"
+    placeholder="{user}"
 
 Then run borger:
 
     borger servername
 
+If you want to backup to local folder or a locally-mounted USB disk, use the
+following config at `~/.config/borger/my-disk`:
+
+    # Repository path
+    export BORG_REPO="/media/my-disk/backups/users/$USER/borg"
+
+    # Setting one of those, so you won't be asked for your repository passphrase:
+    #export BORG_PASSPHRASE='HACKME'
+    #export BORG_PASSCOMMAND='pass show backup'
+    #export BORG_PASSCOMMAND='keyringer default decrypt borg 2> /dev/null'
+
+    # Backup config
+    keepdaily="7"
+    keepweekly="4"
+    keepmonth="6"
+    encryption="keyfile"
+    placeholder="{user}"
+
+Then run borger normally:
+
+    borger my-disk
+
 # Checking your backups
 
 As simply as
 
     borger servername --check
+    borger mydisk     --check
 
 # WARNING
 
diff --git a/borger b/borger
index 2148986cf27edcb59c081c368f1a41649616d22e..0b1ac29c4206e0fc2616febbd87918d7475c23a7 100755 (executable)
--- a/borger
+++ b/borger
@@ -88,14 +88,29 @@ function borger_trap {
 
 # Initialize
 function borger_init {
-  if ! ssh $SSH_SERVER -p $SSH_PORT test -f $BORG_REPO_DIR/config; then
-    info "Initializing borg repository at $BORG_REPO..."
-    borg init --encryption=$encryption $BORG_REPO
+  if [ ! -z "$SSH_SERVER" ]; then
+    # Remote backup over SSH
+    if ! ssh $SSH_SERVER -p $SSH_PORT test -f $BORG_REPO_DIR/config; then
+      info "Initializing borg repository at $BORG_REPO..."
+      borg init --encryption=$encryption $BORG_REPO
 
-    init_exit=$?
+      init_exit=$?
 
-    if [ "$init_exit" != "0" ]; then
-      fatal "Error initializing repository"
+      if [ "$init_exit" != "0" ]; then
+        fatal "Error initializing repository"
+      fi
+    fi
+  else
+    # Local backup
+    if [ ! -f "$BORG_REPO/config" ]; then
+      info "Initializing borg repository at $BORG_REPO..."
+      borg init --encryption=$encryption $BORG_REPO
+
+      init_exit=$?
+
+      if [ "$init_exit" != "0" ]; then
+        fatal "Error initializing repository"
+      fi
     fi
   fi
 }