summaryrefslogtreecommitdiff
path: root/bin/workstation-duplicity
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2019-08-11 18:43:28 +0100
committerSean Whitton <spwhitton@spwhitton.name>2019-08-11 18:43:43 +0100
commit99f235e7abd9f59578d91f59470c6843583a4a4c (patch)
tree45afbef660e3ee476ad18ee1a31dba2c1389d998 /bin/workstation-duplicity
parent06f378f75b0733f236f6119e9a833ce92c82b608 (diff)
downloaddotfiles-99f235e7abd9f59578d91f59470c6843583a4a4c.tar.gz
new workstation-duplicity script
Based on old propellor config.
Diffstat (limited to 'bin/workstation-duplicity')
-rwxr-xr-xbin/workstation-duplicity57
1 files changed, 57 insertions, 0 deletions
diff --git a/bin/workstation-duplicity b/bin/workstation-duplicity
new file mode 100755
index 00000000..55c4c847
--- /dev/null
+++ b/bin/workstation-duplicity
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+set -e
+
+. $HOME/.shenv
+
+FLAG_FILE="$HOME/local/duplicity-flag-file"
+DUPLY_PROFILE="$(hostname -s)-$USER-home"
+
+# ensure only one copy of this script is ever running at once
+[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" ||:
+
+# ensure that the duply profile we want to use exists -- it's an error
+# if it doesn't because this script shouldn't be in our crontab if it
+# doesn't
+if ! [ -e "$HOME/.duply/$DUPLY_PROFILE/conf" ]; then
+ echo >&2 "workstation-duplicity: duply configuration missing"
+ exit 1
+fi
+
+# check when we last ran; don't run if it was less than four hours ago
+if [ -e "$FLAG_FILE" ] \
+ && [ -n "$(find $FLAG_FILE -newermt '4 hours ago')" ]; then
+ echo "flag file too new; not backing up"
+ exit 0
+fi
+
+# don't bother if we're not online
+if offline; then
+ echo "not online; not backing up"
+ exit 0
+fi
+
+# don't try to backup immediately; we might not be online for long
+sleep 600
+
+# confirm we're still online
+if offline; then
+ echo "not online; not backing up"
+ exit 0
+fi
+
+if [ -e "$FLAG_FILE" ]; then
+ # attempt an incremental backup
+ duply $DUPLY_PROFILE backup_purge --force
+else
+ # interpret lack of flag file to mean this host's OS has been
+ # reinstalled. Do a full backup, as doing an incremental backup
+ # against the old host's filesystem is not useful. This full
+ # backup won't be purged immediately (MAX_FULL_BACKUPS is 2), in
+ # case files need to be restored
+ duply $DUPLY_PROFILE full
+fi
+
+# if it was successful, update flag file so we don't do this again for
+# four hours
+touch $FLAG_FILE