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

Joel Grunbaum
2020-06-17 305b169e0390b1d86fd673e27a1d21f463b2cc72
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