Skip to content

Instantly share code, notes, and snippets.

@rafikt1992
Forked from MatthewVance/restic-backup-weekly.sh
Created February 15, 2022 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafikt1992/a5dfd86dce77d35632e00ec293cb0833 to your computer and use it in GitHub Desktop.
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.
#!/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
[Unit]
Description=Runs weekly restic backup script
[Service]
Type=oneshot
ExecStart=/home/pi/.restic/restic-backup-weekly.sh
User=restic
[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