summaryrefslogtreecommitdiff
path: root/images/backup/duplicity/backup.sh
blob: 38223e3c80e990e96d3ef9bdbde709b949e8c80b (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
#!/bin/sh -xe
set -x
set -e

ls -lah /data

CONNECTION_OPTIONS="--use-agent \
          --verbosity $LOG_LEVEL \
          --num-retries 3 \
          --encrypt-key $FINGERPRINT \
          --log-file /dev/stdout \
          --archive-dir /cache/archive \
          --ssh-options=-oIdentityFile=/ssh_keys/backup \
          --gpg-options --passphrase=$PASSPHRASE \
          --gpg-options --no-tty \
          --gpg-options --batch \
          --gpg-options --pinentry-mode=loopback"

# Import and trust the GPG Keys
gpg --passphrase $PASSPHRASE --no-tty --batch --import /gpg_keys/*.priv.asc
echo "$FINGERPRINT:6:" | gpg --import-ownertrust

mkdir -p /cache/archive

# Make the actual backup
duplicity --asynchronous-upload \
          --volsize 250 \
          --full-if-older-than 1M \
          $CONNECTION_OPTIONS \
	        $EXCLUDE_DIRS \
	        /data/ "$BACKUP_STORAGE"

# Clean up broken backups
duplicity cleanup $CONNECTION_OPTIONS \
          "$BACKUP_STORAGE"

# Clean up old backups
duplicity remove-all-but-n-full 1 $CONNECTION_OPTIONS \
          "$BACKUP_STORAGE"