summaryrefslogtreecommitdiffstats
path: root/backup.sh
blob: 09f68b4a05b0b45f766cd23c86bbfdbcbbab5373 (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
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
#
# This is a simple backup script using duplicity. It's supposed to serve as a
# starting point and to be adjusted to your system.
#
# Important steps:
#  - define a host "backup" in root's .ssh/config
#  - create the globbing filters or remove the argument to backup()
#  - read the script and adjust to your needs

if [[ $UID != 0 ]]; then
	echo "Error: need root, restarting with sudo" >&2
	exec sudo "$0" "$@"
fi

export HOME=/root

# if you want to encrypt the backups remove --no-encryption in the duplicity call
# and uncomment the lines that contain PASSPHRASE
#PASSPHRASE="randomstringhere"

backup() {
	src=$1
	dest=$2
	shift 2

	#export PASSPHRASE
	duplicity \
		--exclude-other-filesystems \
		-v2 \
		--volsize 50 \
		--allow-source-mismatch \
		--asynchronous-upload \
		--full-if-older-than 30D \
		--ssh-backend pexpect \
		--no-encryption \
		"$@" "$src" "$dest"

	duplicity --ssh-backend pexpect --force remove-older-than 120D "$dest"
	#export PASSPHRASE=""
}

backup / sftp://backup/$HOSTNAME-backup/root/ --exclude-globbing-filelist /root/duplicity_root_filter
backup /home/ sftp://backup/$HOSTNAME-backup/home/ --exclude-globbing-filelist /root/duplicity_home_filter
backup /boot/ sftp://backup/$HOSTNAME-backup/boot/