forked from bebehei/backup-with-borg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup
executable file
·69 lines (57 loc) · 1.71 KB
/
backup
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
#!/bin/bash
die(){ echo "$*" >&2; exit 1; }
BACKUP="$0"
BACKUP_CONF="${BACKUP_CONF:-default}"
if [ -r "$HOME/.config/backup/${BACKUP_CONF}.env" ]; then
CONFIG_BASE="$HOME/.config/backup"
elif [ -r "/etc/backup/${BACKUP_CONF}.env" ]; then
CONFIG_BASE="/etc/backup"
else
die "Configuration '${BACKUP_CONF}' does not exist."
fi
if [ -e "${CONFIG_BASE}/${BACKUP_CONF}.exclude" ]; then
EXCLUDE_FILE="${CONFIG_BASE}/${BACKUP_CONF}.exclude"
fi
. "${CONFIG_BASE}/${BACKUP_CONF}.env" || die "Could not read envfile."
: "${CMD_BORG:=borg}"
command -v "${CMD_BORG}" &>/dev/null \
|| die "Cannot find '${CMD_BORG}' executable! Verify the CMD_BORG variable."
case "$1" in
do-create)
$CMD_BORG create \
-x \
${OPT_BORG} ${OPT_BORG_CREATE} \
${EXCLUDE_FILE:+--exclude-from=${EXCLUDE_FILE}} \
${OPT_BORG_EXCLUDE_CACHES} \
${OPT_BORG_EXCLUDE_IF_PRESENT} \
::'{hostname}'${SUFFIX}'-{now:%Y-%m-%dT%H:%M:%S}' \
${SOURCES[@]:-/}
;;
do-prune)
$CMD_BORG prune \
${OPT_BORG} ${OPT_BORG_PRUNE} \
--glob-archives='{hostname}'${SUFFIX}'-*' \
${KEEP_WITHIN:+--keep-within=${KEEP_WITHIN}} \
${KEEP_HOURLY:+--keep-hourly=${KEEP_HOURLY}} \
${KEEP_DAILY:+--keep-daily=${KEEP_DAILY}} \
${KEEP_WEEKLY:+--keep-weekly=${KEEP_WEEKLY}} \
${KEEP_MONTHLY:+--keep-monthly=${KEEP_MONTHLY}} \
${KEEP_YEARLY:+--keep-yearly=${KEEP_YEARLY}} \
${KEEP_LAST:+--keep-last=${KEEP_LAST}}
;;
do-compact)
$CMD_BORG compact \
${OPT_BORG} ${OPT_BORG_COMPACT}
;;
run|"")
"${BACKUP}" do-create \
|| die "borg failed to create archive."
"${BACKUP}" do-prune \
|| die "borg failed to prune archives."
"${BACKUP}" do-compact \
|| die "borg failed to compact archives."
;;
*)
borg ${OPT_BORG} $*
;;
esac