-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup-external.zsh
executable file
·58 lines (46 loc) · 1.71 KB
/
backup-external.zsh
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
#!/bin/zsh
# shellcheck shell=bash
export BORG_REPO="/run/media/swerner/BACKUP/$(hostname)"
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
trap "echo $( date ) Backup interrupted >&2; exit 2" INT TERM
if [ -z "$BORG_PASSPHRASE" ]; then
echo -n 'Repo passphrase:'
read -s BORG_PASSPHRASE
export BORG_PASSPHRASE
echo
fi
info "Starting backup"
borg create \
--stats \
--verbose \
--filter AME \
--list \
--show-rc \
--compression zstd,15 \
--exclude-caches \
--exclude-nodump \
--exclude-from $HOME/.borg-exclude \
\
::'{hostname}-{now}' \
"${HOME}" \
backup_exit=$?
info "Pruning repository"
borg prune \
--verbose \
--list \
--prefix '{hostname}-' \
--show-rc \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 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 0 ]; then
info "Backup and Prune finished successfully"
elif [ ${global_exit} -eq 1 ]; then
info "Backup and/or Prune finished with warnings"
else
info "Backup and/or Prune finished with errors"
fi
exit ${global_exit}