aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2018-05-23 09:18:15 -0300
committerSilvio Rhatto <rhatto@riseup.net>2018-05-23 09:18:15 -0300
commitd3d8a9da90091ec1d53cfc975f1a1fe5134ce54b (patch)
tree7650a81eb594b699970f485c8f1050fc8dade249
parentda0ec3522804ae7148f7617314cffa36ab0499e1 (diff)
downloadscripts-d3d8a9da90091ec1d53cfc975f1a1fe5134ce54b.tar.gz
scripts-d3d8a9da90091ec1d53cfc975f1a1fe5134ce54b.tar.bz2
Borger: support multiple destinations
-rwxr-xr-xborger73
1 files changed, 52 insertions, 21 deletions
diff --git a/borger b/borger
index 33c313c..240de36 100755
--- a/borger
+++ b/borger
@@ -3,21 +3,50 @@
# Borg script for home folder backups.
# Adapted from https://borgbackup.readthedocs.io/en/stable/quickstart.html#automating-backups
#
-# Stuff to put in your config:
+# Example config to be put at ~/.config/borger/destination-name:
#
-# Backup destination
-#export SSH_SERVER="user@host"
-#export SSH_PORT="2202"
-# Setting this, so you won't be asked for your repository passphrase:
-#export BORG_PASSPHRASE='HACKME'
-# or this to ask an external program to supply the passphrase:
-#export BORG_PASSCOMMAND='pass show backup'
-#export BORG_PASSCOMMAND='keyringer default decrypt pessoal/backups/borg 2> /dev/null'
+# # 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"
+#
+# # Setting this, 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 pessoal/backups/borg 2> /dev/null'
+#
+# # Backup config
+# keepdaily="7"
+# keepweekly="4"
+# keepmonth="3"
+# encryption="keyfile"
# Parameters
-CONFIG="$HOME/.config/borger"
+BASENAME="`basename $0`"
+DESTINATION="$1"
+BASE_CONFIG="$HOME/.config/borger"
+CONFIG="$BASE_CONFIG/$DESTINATION"
HOSTNAME=`cat /etc/hostname`
+# Some helpers and error handling:
+info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
+fatal() { info $*; exit 1; }
+
+# Ensure we have our base config folder
+mkdir -p $BASE_CONFIG
+
+# List available targets
+if [ -z "$DESTINATION" ]; then
+ echo "usage: $BASENAME <destination> [--check]"
+ echo -n "available destinations from $BASE_CONFIG: "
+ ls $BASE_CONFIG
+ exit 1
+fi
+
+# Ensure we have an username
if [ -z "$USER" ]; then
USER="`whoami`"
fi
@@ -38,26 +67,29 @@ encryption="keyfile"
# Config
if [ -e "$CONFIG" ] ; then
source $CONFIG
+else
+ fatal "No such config $CONFIG"
fi
# Setting this, so the repo does not need to be given on the commandline:
-export BORG_REPO="ssh://$SSH_SERVER:$SSH_PORT//var/backups/users/$USER/borg"
-
-# Some helpers and error handling:
-info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
-fatal() { info $*; exit 1; }
-trap 'info $( date ) Backup interrupted >&2; exit 2' INT TERM
+if [ -z "$BORG_REPO" ]; then
+ export BORG_REPO_DIR="/var/backups/users/$USER/borg"
+ export BORG_REPO="ssh://$SSH_SERVER:$SSH_PORT/$BORG_REPO_DIR"
+fi
# Check
-if [ "$1" == "--check" ]; then
+if [ "$2" == "--check" ]; then
borg list
exit $?
fi
+# Our trap
+trap 'info $( date ) Backup interrupted >&2; exit 2' INT TERM
+
# Initialize
-if ! ssh $SSH_SERVER -p $SSH_PORT test -f /var/backups/users/$USER/borg/config; then
- info "Initializing borg repository at ssh://$SSH_SERVER:$SSH_PORT//var/backups/users/$USER/borg..."
- borg init --encryption=$encryption ssh://$SSH_SERVER:$SSH_PORT//var/backups/users/$USER/borg
+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=$?
@@ -97,7 +129,6 @@ info "Pruning repository..."
borg prune \
--list \
- --prefix '{hostname}-' \
--show-rc \
--keep-daily $keepdaily \
--keep-weekly $keepweekly \