summaryrefslogtreecommitdiff
path: root/backup-dataset.sh
blob: b1553e5bb7995949c0051162bc838e2840071780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh -euf

SNAPSHOT_DIRECTORY="/var/backups/dataset-snapshots"

usage() (
	echo "backup-dataset.sh <dataset> <duplicity destination> <signing key> <encryption key> [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" 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