Are there some example scripts, how to manage weekly/daily backups with forgetting and pruning and checking? This would be very helpful for new users like me! I found http://www.sharons.org.uk/restic4.html but I am not sure if that is the way to go with password, check script and everything.
So in short, I would appreciate some example configurations of how you back up (and check/forget) e.g. your home dir via SFTP using a simple script that you can use via cron.
Thank you!
I’m lazy. I just back up manually when I want to, using e.g. restic -r sftp://hostname/backup/restic folder1 folder2 folder3
.
Every now and then I do a restic check, but it’s honestly rather rarely, since the storage is using ZFS.
You might find this helpful: https://github.com/alphapapa/restic-runner
I run something like the following script via cron. It’s could be improved, but it works. You’ll need to manually check the log or write another script to watch for restic check results.
#!/bin/bash
#This will run Restic backups and remove snapshots according to a policy
export RESTIC_REPOSITORY=/Users/matt/backup/restic/
# need to securely provide password: https://restic.readthedocs.io/en/latest/faq.html#how-can-i-specify-encryption-passwords-automatically
#Define a timestamp function
timestamp() {
date "+%b %d %Y %T %Z"
}
# insert timestamp into log
printf "\n\n"
echo "-------------------------------------------------------------------------------" | tee -a /Users/matt/Documents/logs/restic.log
echo "$(timestamp): restic.sh started" | tee -a /Users/matt/Documents/logs/restic.log
# Run Backups
restic backup /Users/matt/Documents --exclude /Users/matt/Documents/Exclude
# Remove snapshots according to policy
# If run cron more frequently, might add --keep-hourly 24
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 7 | tee -a /Users/matt/Documents/logs/restic.log
# Remove unneeded data from the repository
restic prune
# Check the repository for errors
restic check | tee -a /Users/matt/Documents/logs/restic.log
# insert timestamp into log
printf "\n\n"
echo "-------------------------------------------------------------------------------" | tee -a /Users/matt/Documents/logs/restic.log
echo "$(timestamp): restic.sh finished" | tee -a /Users/matt/Documents/logs/restic.log
I also run a second cron job to backup my repo directory to Google Cloud Storage:
#!/bin/bash
#This rsyncs Restic backup to Google Cloud Storage
/usr/local/bin/google-cloud-sdk/bin/gsutil -m rsync -d -r /Users/matt/backup/restic/ gs://my-bucketp/restic/ 2>&1
That bucket is configured with the following lifecycle rule to change the storage class for files older than 30 days to nearline.
{
"lifecycle": {
"rule": [
{
"action": {
"type": "SetStorageClass",
"storageClass": "NEARLINE"
},
"condition": {
"age": 30,
"matchesStorageClass": ["REGIONAL", "STANDARD", "DURABLE_REDUCED_AVAILABILITY"]
}
}
]
}
}
Have you tried running restores with files that have been moved to nearline?
Maybe the following helps: https://gist.github.com/rolfn/5637ba74fdc152ea38eaa99fa3fa1bda (in german; not finished). I use systemd instead of cron and simple scripts.
I have not. Since I backup locally and then sync the repo, I typically restore from the local repo. During a catastrophic case (local not available), I would not use Restic to access the bucket contents directly. I’d download directly from Google Cloud and then point Restic to the local download.
It has been a while and I don’t remember if nearline was in use when I tested, but I have pulled my bucket contents back down via gsutil to confirm I could restore in the manner above.
I don’t know if it’s a best practice but I did my own script for Mac user directory inspired by all the above. It mainly builds an axclude list inspired by Apple’s one. You can see it on
hope this helps
Instead of using scripts, I created a tool for managing the automatic creation and purge of Restic backups based on time and retention policies. Maybe you can make a good use of it…
I’m no developer or anything related but I’ve manage to make a script. At first it was very simple but as time passed I was needing new options, so from time to time I was able to make this. Everyone is welcome to use it, modify it or whatever you want to do with this. This is the first time doing something like this for me. Six months ago I didn’t even knew how a bash script works. I know maybe there are some things in my script that can be done different or more easy, but like I said, I don’t know anything about this, I’m not a programmer or developer or anything related, I’m just a regular user who wanted to do something that helped me to use restic and challenged myself to do this.
Sharing my macos backup script: https://github.com/HazCod/restimac.sh
If only backups up while on the wireless network you specify and uses exclusions like TimeMachine does.