Created
May 18, 2019 19:49
-
-
Save MatthewVance/19fd0d9e3ff05c06ad01c5a2d6ddfa56 to your computer and use it in GitHub Desktop.
Restic daily and hourly backup scripts with systemd timers.
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/bash | |
#: Title : restic | |
#: Date : July 15 2018 | |
#: Author : Matt Vance | |
#: Version : 1.1 | |
#: Description : Script to fully sytem backlup | |
#: License : MIT License (MIT) | |
# Copyright (C) 2019 Matthew Vance | |
export RESTIC_REPOSITORY=/Volumes/storage/matt/backup/repos/shared/ | |
export RESTIC_PASSWORD_FILE=/etc/restic/restic-pw.txt | |
HOST=host_name | |
CACERT=/etc/restic/host_name-bundle.pem | |
CACHE=/home/restic/.cache | |
EXCLUDE=/etc/restic/restic-exclude.txt | |
LOG=/var/log/restic/restic.log | |
RESTIC=/usr/local/bin/restic | |
TAG=full | |
#Define a timestamp function | |
timestamp() { | |
date "+%b %d %Y %T %Z" | |
} | |
# Add timestamp | |
echo "$(timestamp): restic.sh started" | tee -a $LOG | |
echo "-------------------------------------------------------------------------------" | tee -a $LOG | |
# Run Backups | |
$RESTIC backup \ | |
--cacert $CACERT \ | |
--cache-dir $CACHE \ | |
--exclude-file $EXCLUDE \ | |
--host $HOST \ | |
--quiet \ | |
--tag $TAG \ | |
/ | tee -a $LOG | |
# Add timestamp | |
echo "-------------------------------------------------------------------------------" | tee -a $LOG | |
echo "$(timestamp): restic.sh finished" | tee -a $LOG | |
printf "\n" | tee -a $LOG |
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/bash | |
#: Title : restic | |
#: Date : July 7 2018 | |
#: Author : Matt Vance | |
#: Version : 1.0 | |
#: Description : Script to run regular restic backups | |
#: License : MIT License (MIT) | |
# Copyright (C) 2018 Matthew Vance | |
export RESTIC_REPOSITORY=/Volumes/storage/matt/backup/repos/shared/ | |
export RESTIC_PASSWORD_FILE=/etc/restic/restic-pw.txt | |
# cacert is only needed if using REST with my own CA. | |
HOST=host_name | |
CACERT=/etc/restic/host_name-bundle.pem | |
CACHE=/home/restic/.cache | |
EXCLUDE=/etc/restic/restic-exclude.txt | |
INCLUDE=/etc/restic/restic-include.txt | |
LOG=/var/log/restic/restic.log | |
RESTIC=/usr/local/bin/restic | |
#Define a timestamp function | |
timestamp() { | |
date "+%b %d %Y %T %Z" | |
} | |
# Add timestamp | |
echo "$(timestamp): restic.sh started" | tee -a $LOG | |
echo "-------------------------------------------------------------------------------" | tee -a $LOG | |
# Run Backups | |
$RESTIC backup \ | |
--cacert $CACERT \ | |
--cache-dir $CACHE \ | |
--exclude-file $EXCLUDE \ | |
--files-from $INCLUDE \ | |
--host $HOST \ | |
--quiet | tee -a $LOG | |
# Check the repository for errors | |
# $RESTIC check | tee -a $LOG | |
# Add timestamp | |
echo "-------------------------------------------------------------------------------" | tee -a $LOG | |
echo "$(timestamp): restic.sh finished" | tee -a $LOG | |
printf "\n" | tee -a $LOG |
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
[Unit] | |
Description=Runs daily restic backup script | |
[Service] | |
Type=oneshot | |
ExecStart=/etc/restic/restic-backup-daily.sh | |
User=restic |
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
[Unit] | |
Description=Run restic-daily.service | |
[Timer] | |
Unit=restic-daily.service | |
OnCalendar=*-*-* 00:30:00 | |
[Install] | |
WantedBy=timers.target |
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
[Unit] | |
Description=Runs hourly restic backup script | |
# Conflicts= ... | |
[Service] | |
Type=oneshot | |
ExecStart=/etc/restic/restic-backup-hourly.sh | |
User=restic |
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
[Unit] | |
Description=Run restic-hourly.service | |
[Timer] | |
Unit=restic-hourly.service | |
OnCalendar=*-*-* *:00:00 | |
# Run every 4th hour between 6 am and 11 pm | |
OnCalendar=*-*-* 06..23/4:00:00 | |
# tell systemd to run the service immediately after booting if the server was | |
# down when it was supposed to run | |
# Persistent=true | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment