-
-
Save rafikt1992/a5dfd86dce77d35632e00ec293cb0833 to your computer and use it in GitHub Desktop.
Script to backup a Raspberry Pi weekly to a Restic over the network via REST.
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 : October 13, 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=rest:https://user:your_password@192.168.1.2:8889 | |
export RESTIC_PASSWORD_FILE=/home/pi/.restic/restic-pw.txt | |
HOST=rasberry_pi | |
CACERT=/home/pi/.restic/host_server_name-bundle.pem | |
CACHE=/home/restic/.cache | |
EXCLUDE=/home/pi/.restic/restic-exclude.txt | |
INCLUDE=/home/pi/.restic/restic-include.txt | |
LOG=/home/pi/.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 | |
# 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 weekly restic backup script | |
[Service] | |
Type=oneshot | |
ExecStart=/home/pi/.restic/restic-backup-weekly.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-weekly.service every Friday | |
[Timer] | |
Unit=restic-weekly.service | |
OnCalendar=Fri *-*-* 08:25: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