Last active
August 25, 2016 14:30
-
-
Save obilodeau/9f0fecdcad023ea4d7ea797d2aa73245 to your computer and use it in GitHub Desktop.
Borg backup cron script with libnotify desktop notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Borg backup script with desktop notifications | |
# Meant to be run as root | |
# configuration | |
USER=olivier | |
REPOSITORY= | |
COMPRESSION=zlib,5 | |
# derived information | |
export BORG_CACHE_DIR=/home/$USER/.cache/borg/ | |
USERID=`id -u $USER` | |
borg create -v --stats \ | |
--compression $COMPRESSION \ | |
$REPOSITORY::'{hostname}-{now:%Y-%m-%d}' \ | |
/home/$USER/ | |
if [[ $? == 0 ]]; then | |
MSG="Backup success" | |
ICON=document-send | |
else | |
MSG="Backup failed... See root's dead.letter for details." | |
ICON=dialog-warning | |
fi | |
sudo -u $USER DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USERID/bus notify-send 'BorgBackup' "$MSG" --icon=$ICON | |
# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly | |
# archives of THIS machine. The '{hostname}-' prefix is very important to | |
# limit prune's operation to this machine's archives and not apply to | |
# other machine's archives also. | |
borg prune -v $REPOSITORY --prefix '{hostname}-' \ | |
--keep-daily=7 --keep-weekly=4 --keep-monthly=6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment