diff options
Diffstat (limited to 'bin/workstation-duplicity')
-rwxr-xr-x | bin/workstation-duplicity | 57 |
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 |