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

Joel Grunbaum
2020-06-17 81705dbdd023f896a447a43c8decc64c3aa1e776
Added scripts to backup system with borg
3 files added
59 ■■■■■ changed files
system_backup.service 9 ●●●●● patch | view | raw | blame | history
system_backup.sh 41 ●●●●● patch | view | raw | blame | history
system_backup.timer 9 ●●●●● patch | view | raw | blame | history
system_backup.service
New file
@@ -0,0 +1,9 @@
[Unit]
Description=Backup system with Borg
[Service]
Type=simple
ExecStart=/root/system_backup.sh
[Install]
RequiredBy=multi-user.target
system_backup.sh
New file
@@ -0,0 +1,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
system_backup.timer
New file
@@ -0,0 +1,9 @@
[Unit]
Description=System backup with Borg Timer
[Timer]
OnCalendar=Daily
Persistent=true
[Install]
WantedBy=timers.target