#!/bin/sh -euf SNAPSHOT_DIRECTORY="/var/backups/dataset-snapshots" usage() ( echo "backup-dataset.sh [duplicity options]" echo echo "Performs a duplicity incremental backup of the specified dataset." echo "An atomic snapshot of the dataset is taken prior to backing up." echo ) backup_dataset() ( DATASET="$1" DESTINATION="$2" SIGNING_KEY="$3" ENCRYPTION_KEY="$4" DUPLICITY_OPTIONS="$5" sudo snap.sh snap "$DATASET" PASSPHRASE="null" SIGN_PASSPHRASE="null" \ duplicity $DUPLICITY_OPTIONS \ --sign-key="$SIGNING_KEY" --encrypt-key="$ENCRYPTION_KEY" \ "$SNAPSHOT_DIRECTORY/$DATASET" "$DESTINATION" sudo snap.sh free "$DATASET" ) case "${1:-help}" in "help") usage;; *) backup_dataset "$1" "$2" "$3" "$4" "${5:-incremental}";; esac