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

Joel Grunbaum
2020-06-21 cc5c5da0ff1a2aca9f9c3785a90f857d08a27a90
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
#!/bin/sh
 
if [ $EUID != 0 ]; then
    sudo "$0" "$@"
    exit $?
fi
 
export BORG_REPO=/backup/borg
 
# add --list to view files as they're added to the backup
borg create \
     --verbose \
     --stats \
     --compression zstd,22 \
     --one-file-system \
     --exclude-caches \
     --exclude /var/cache \
     \
     ::"$(date +%F)" \
     /
 
BACKUP_EXIT=$?
 
borg prune \
     --list \
     --keep-daily 7 \
     --keep-monthly 2
 
PRUNE_EXIT=$?
 
GLOBAL_EXIT=$(( BACKUP_EXIT > PRUNE_EXIT ? BACKUP_EXIT : PRUNE_EXIT ))
 
if [ $GLOBAL_EXIT -eq 0 ]; then
    echo "Backup and Prune finished with successfully"
elif [ $GLOBAL_EXIT -eq 1 ]; then
    echo "Backup and/or Prune finshed with warnings"
else
    echo "Backup and/or Prune finished with errors"
fi
 
exit $GLOBAL_EXIT