mirror of https://github.com/Chizi123/Scripts.git

Joel Grunbaum
2020-06-21 49eec38386652d9f57fd56ff24b23057e9228622
commit | author | age
81705d 1 #!/bin/sh
JG 2
3 if [ $EUID != 0 ]; then
4     sudo "$0" "$@"
5     exit $?
6 fi
7
8 export BORG_REPO=/backup/borg
9
10 # add --list to view files as they're added to the backup
11 borg create \
12      --verbose \
13      --stats \
14      --compression zstd,22 \
15      --one-file-system \
16      --exclude-caches \
17      --exclude /var/cache \
18      \
19      ::"$(date +%F)" \
20      /
21
22 BACKUP_EXIT=$?
23
24 borg prune \
25      --list \
26      --keep-daily 7 \
27      --keep-monthly 2
28
29 PRUNE_EXIT=$?
30
31 GLOBAL_EXIT=$(( BACKUP_EXIT > PRUNE_EXIT ? BACKUP_EXIT : PRUNE_EXIT ))
32
33 if [ $GLOBAL_EXIT -eq 0 ]; then
34     echo "Backup and Prune finished with successfully"
35 elif [ $GLOBAL_EXIT -eq 1 ]; then
36     echo "Backup and/or Prune finshed with warnings"
37 else
38     echo "Backup and/or Prune finished with errors"
39 fi
40
41 exit $GLOBAL_EXIT