by pawelduda · 5y ago · 0 comments
_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.Relevant manual page in case anyone's interested: https://restic.readthedocs.io/en/latest/045_working_with_rep...
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'.
It looks like in this example it's used simply to trim whitespace. E.g.
$ echo ' hello ' | xargs
hellorestic -r <repo_name> --verbose --exclude="$HOME/snap" --exclude="$HOME/Android" --exclude="$HOME/.android" --exclude="$HOME/ApkProjects" backup ~/
To me if it requires complicated shell commands it is not really "done right".
The snippet GP mentioned includes only shell functions, invocations of restic, and echo commands. How could it be simpler?
# tar cvf /dev/st0 .
restic -r reponame /path-to-files-to-be-backuped
Everything else in the mentioned script is optional stuff for scheduling, removing old backups, etc.