6 ms·
Oh yeah, restic is awesome _backup_prepare () { export $(sudo cat <protected_credentials_file> | xargs) } _backup_remove_old_snapshots () { rest
by pawelduda 5y ago
Oh yeah, restic is awesome
_backup_prepare () {
export $(sudo cat <protected_credentials_file> | xargs)
}
_backup_remove_old_snapshots () {
restic forget -r <repo_name> --keep-weekly 10
}
_backup_verify () {
restic check -r <repo_name>
}
backup () {
echo "---------------Scheduled backup time---------------"
echo ""
_backup_prepare
restic -r <repo_name> --verbose --exclude="$HOME/snap" --exclude="$HOME/Android" --exclude="$HOME/.android" --exclude="$HOME/ApkProjects" backup ~/
echo ""
echo "---------------Backup done, removing old snapshots---------------"
echo ""
_backup_remove_old_snapshots
echo ""
echo "---------------Old snapshots removed, verifying the data is restorable---------------"
echo ""
_backup_verify
echo ""
echo "---------------Backup done and verified!---------------"
}
Then in cron I just have this entry:
20 \* \* \* DISPLAY=:0 kitty -- /bin/zsh --login -c 'source ~/.zshrc; backup; read'
So every time my PC is on @ 20:00, a shell window will pop-up, asking me for password and runs the backup :). Since they are incremental, it takes maybe 10-15 minutes top.
- kkjjkgjjgg 5y agoMy eyes immediately glazed over seeing the code, tbh. Not what I expected from a super simple backup solution.
- number6 5y agoThe relevant restic part is: restic -r <repo_name> --verbose --exclude="$HOME/snap" --exclude="$HOME/Android" --exclude="$HOME/.android" --exclude="$HOME/ApkProjects" backup ~/
- pawelduda 5y agoNever mentioned it's super simple. It's DIY that I stitched together in 1-2 hrs of incremental upgrades and it's been running like this for months. To me it's simple enough but YMMV
- kkjjkgjjgg 5y agoSorry it wasn't meant as a criticism of your work. I just had hoped for something simpler from the "Backups Done Right" headline. To me if it requires complicated shell commands it is not really "done right".
- gnubison 5y ago> complicated The snippet GP mentioned includes only shell functions, invocations of restic, and echo commands. How could it be simpler?
- deleted 5y ago[deleted]
- cvs268 5y agosimple/fun vs. complicated/scary depends on the target user. Simple for someone who is comfortable with the terminal. Scary for those who are oyherwise familiar with GUIs only.
- bccdee 5y agoSure, but if I'm not comfortable with the terminal, I probably shouldn't be too loud with my criticisms of shell scripts.
- kkjjkgjjgg 5y agoIt just seems a pity that knowledge of shell scripts is necessary to do backups.
- bccdee 5y agoYeah I bet there are good GUI tools out there, but I always want to go for the stuff I can script myself, so I can hook desktop notifications into it and such. It makes it hard for me to recommend backup tools to the non-technical people in my life, because they're looking for GUI solutions with the corners rounded off, and I want something crunchy and scriptable.
- _h9mb 5y agoIt kind is, simple but effective. For comparison, take a look at my over-engineered backup script: https://github.com/danisztls/arbie/blob/main/arbie https://github.com/danisztls/arbie/blob/main/arbie
- kkjjkgjjgg 5y agoWow :-)
- krick 5y agoWell, to be fair, your does a bit more than the simple solution above. If you backup system configs and stuff with restic it wouldn't be much shorter than what you do here.
- mellavora 5y agoLove seeing a code example. It's one thing to hear "restic is fantastic, super easy to set up", it is another to see an example of HOW simple it is. Thank you for sharing.
- Abishek_Muthian 5y agoYou might be also interested in how I use restic to backup PostgreSQL and other data onto Backblaze for security and to save cloud costs as Cloud providers charge exuberant fees for backups[1]. [1] https://abishekmuthian.com/backup-postgresql-to-cloud/ https://abishekmuthian.com/backup-postgresql-to-cloud/
- CGamesPlay 5y agoNote that `restic check` only verifies that the repository metadata is correct, and doesn't detect, say, bit swaps in actual packfiles, which would render your backup unrestorable. You might be interested in the `--read-data` or `--read-data-subset` flags to help double check your backups!
- pawelduda 5y agoOoh I just checked this and you're right! Thanks for the heads up, I'll have to incorporate this into the script. Relevant manual page in case anyone's interested: https://restic.readthedocs.io/en/latest/045_working_with_repos.html#checking-integrity-and-consistency https://restic.readthedocs.io/en/latest/045_working_with_rep...
- wehnsdaefflae 5y agoNot sure if sarcasm...
- _h9mb 5y agoSuggestion: You can use pass to securely store and pipe your password, no superuser required.
- zaphirplane 5y agoAre you sure you want to remove old backups unconditional to the success of the backups
- OJFord 5y agoI've never seen/used xargs (/export) like: export $(sudo cat <protected_credentials_file> | xargs) Is that the same as sudo cat f | xargs export? If so, I think an important difference is that mine won't hide the exit code, and you can then answer a sibling commenter (on forgetting without checking) with 'I omitted set -e at the top'.
- jedbrown 5y agoexport is a shell builtin -- it can't be executed by xargs and even if it could, wouldn't be in the context of the shell you want.
- OJFord 5y agoTrue. `sh -c export` then, with `set -o allexport` ;)
- gizdan 5y agoThe sibling comment said. It looks like in this example it's used simply to trim whitespace. E.g. $ echo ' hello ' | xargs hello