-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup
More file actions
executable file
·93 lines (75 loc) · 1.88 KB
/
backup
File metadata and controls
executable file
·93 lines (75 loc) · 1.88 KB
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
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
export BORG_REPO=/mnt/backup/borg-backup
export BORG_PASSCOMMAND='rbw get borg-passphrase'
usage() {
cat <<EOF > /dev/stderr
Usage: $(basename $0) [hbli]
h: help
b: backup
l: list
i: info
EOF
exit 1
}
# some helpers and error handling:
info() {
printf "\n[%s] %s\n\n" "$(date)" "$*" >&2
}
trap "echo [$(date)] Backup interrupted >&2; exit 2" INT TERM
backup() {
info "Starting backup"
# Backup the most important directories into an archive named after
# the machine this script is currently running on:
borg create \
--filter AME \
--list \
--stats \
--show-rc \
--compression lz4 \
--exclude-caches \
--exclude *~ \
--exclude *.pyc \
--exclude /home/phil/var/log\
--exclude /home/phil/tmp \
--exclude /home/phil/src/aur/chroot\
--exclude /home/phil/var/steam\
--exclude-if-present '.nobackup' \
\
::'{hostname}-{now}' \
/home/phil \
backup_exit=$?
info "Pruning repository"
# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
# archives of THIS machine. The '{hostname}-' prefix is very important to
# limit prune's operation to this machine's archives and not apply to
# other machines' archives also:
borg prune \
--list \
--glob-archives '{hostname}-' \
--show-rc \
--keep-hourly 6 \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 12 \
--keep-yearly 6 \
prune_exit=$?
# use highest exit code as global exit code
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
if [ ${global_exit} -eq 1 ];
then
info "Backup and/or Prune finished with a warning"
fi
if [ ${global_exit} -gt 1 ];
then
info "Backup and/or Prune finished with an error"
fi
}
main() {
case $1 in
b) backup ;;
l) borg list $BORG_REPO ;;
i) borg info $BORG_REPO ;;
*) usage ;;
esac
}
main $@