-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathduplicacy-autobackup.sh
executable file
·83 lines (72 loc) · 2.18 KB
/
duplicacy-autobackup.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
PRE_BACKUP_SCRIPT="/scripts/pre-backup.sh"
POST_BACKUP_SCRIPT="/scripts/post-backup.sh"
cd /wd
do_init() {
: ${BACKUP_NAME:?'Missing BACKUP_NAME'}
: ${BACKUP_LOCATION:?'Missing BACKUP_LOCATION'}
if [[ ! -z "$BACKUP_ENCRYPTION_KEY" ]]; then
echo "This backup will be encrypted."
export DUPLICACY_INIT_OPTIONS="-encrypt $DUPLICACY_INIT_OPTIONS"
fi
duplicacy init $DUPLICACY_INIT_OPTIONS $BACKUP_NAME "$BACKUP_LOCATION"
if [[ $? != 0 ]]; then
echo "duplicacy init command failed. Aborting" >&2
rm -rf .duplicacy
exit 1
fi
}
do_backup() {
status=0
if [[ -f $PRE_BACKUP_SCRIPT ]]; then
echo "Running pre-backup script"
sh $PRE_BACKUP_SCRIPT
status=$?
fi
if [[ $status != 0 ]]; then
echo "Pre-backup script exited with status code $status. Not performing backup." >&2
return
fi
duplicacy backup $DUPLICACY_BACKUP_OPTIONS
if [[ -f $POST_BACKUP_SCRIPT ]]; then
echo "Running post-backup script"
sh $POST_BACKUP_SCRIPT
status=$?
echo "Post-backup script exited with status $status"
fi
}
do_prune() {
if [[ ! -z "$DUPLICACY_PRUNE_OPTIONS" ]]; then
echo "Running prunning"
duplicacy -log prune $DUPLICACY_PRUNE_OPTIONS
fi
}
export DUPLICACY_PASSWORD=$BACKUP_ENCRYPTION_KEY
export DUPLICACY_S3_ID=$AWS_ACCESS_KEY_ID
export DUPLICACY_S3_SECRET=$AWS_SECRET_KEY
export DUPLICACY_B2_ID=$B2_ID
export DUPLICACY_B2_KEY=$B2_KEY
export DUPLICACY_HUBIC_TOKEN=$HUBIC_TOKEN_FILE
export DUPLICACY_SSH_PASSWORD=$SSH_PASSWORD
export DUPLICACY_SSH_KEY_FILE=$SSH_KEY_FILE
export DUPLICACY_DROPBOX_TOKEN=$DROPBOX_TOKEN
export DUPLICACY_AZURE_KEY=$AZURE_KEY
export DUPLICACY_GCD_TOKEN=$GCD_TOKEN
export DUPLICACY_GCS_TOKEN=$GCS_TOKEN_FILE
export DUPLICACY_ONE_TOKEN=$ONEDRIVE_TOKEN_FILE
export DUPLICACY_ODB_TOKEN=$ONEDRIVE_BUSINESS_TOKEN_FILE
export DUPLICACY_WASABI_KEY=$WASABI_KEY
export DUPLICACY_WASABI_SECRET=$WASABI_SECRET
if [[ "$1" == "init" ]]; then
if [[ ! -d .duplicacy ]]; then
do_init
else
echo 'This folder has already been initialized with duplicacy. Not initializing again'
fi
elif [[ "$1" == "backup" ]]; then
do_backup
elif [[ "$1" == "prune" ]]; then
do_prune
else
echo "Unknown command: $1" >&2
fi