News for hackers. Stuff that matters.
Re:Restic – Backups Done Right by pawelduda on Saturday November 13, 2021 @10:26AM (#29210379)
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.
Re:Restic – Backups Done Right by CGamesPlay on Saturday November 13, 2021 @12:21PM (#29211426)
Note 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!
Re:Restic – Backups Done Right by pawelduda on Saturday November 13, 2021 @01:22PM (#29211956)
Ooh 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_rep...

Re:Restic – Backups Done Right by mellavora on Saturday November 13, 2021 @12:20PM (#29211422)
Love 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.
Re:Restic – Backups Done Right by Abishek_Muthian on Sunday November 14, 2021 @02:35AM (#29215919)
You 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/

Re:Restic – Backups Done Right by lobocinza on Saturday November 13, 2021 @07:56PM (#29214595)
Suggestion: You can use pass to securely store and pipe your password, no superuser required.
Re:Restic – Backups Done Right by zaphirplane on Saturday November 13, 2021 @08:40PM (#29214784)
Are you sure you want to remove old backups unconditional to the success of the backups
Re:Restic – Backups Done Right by OJFord on Saturday November 13, 2021 @09:02PM (#29214867)
I'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'.

Re:Restic – Backups Done Right by jedbrown on Saturday November 13, 2021 @11:04PM (#29215280)
export 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.
Re:Restic – Backups Done Right by OJFord on Tuesday November 16, 2021 @04:58AM (#29238789)
True. `sh -c export` then, with `set -o allexport` ;)
Re:Restic – Backups Done Right by gizdan on Sunday November 14, 2021 @04:56AM (#29216310)
The sibling comment said.

It looks like in this example it's used simply to trim whitespace. E.g.

    $ echo '  hello  ' | xargs
    hello
Re:Restic – Backups Done Right by wehnsdaefflae on Saturday November 13, 2021 @06:11PM (#29213977)
Not sure if sarcasm...
Re:Restic – Backups Done Right by kkjjkgjjgg on Saturday November 13, 2021 @11:05AM (#29210712)
My eyes immediately glazed over seeing the code, tbh. Not what I expected from a super simple backup solution.
Re:Restic – Backups Done Right by number6 on Saturday November 13, 2021 @11:13AM (#29210783)
The relevant restic part is:

restic -r <repo_name> --verbose --exclude="$HOME/snap" --exclude="$HOME/Android" --exclude="$HOME/.android" --exclude="$HOME/ApkProjects" backup ~/

Re:Restic – Backups Done Right by pawelduda on Saturday November 13, 2021 @11:43AM (#29211076)
Never 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
Re:Restic – Backups Done Right by kkjjkgjjgg on Saturday November 13, 2021 @12:25PM (#29211463)
Sorry 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".

Re:Restic – Backups Done Right by gnubison on Saturday November 13, 2021 @12:37PM (#29211567)
> complicated

The snippet GP mentioned includes only shell functions, invocations of restic, and echo commands. How could it be simpler?

Re:Restic – Backups Done Right by cvs268 on Saturday November 13, 2021 @01:05PM (#29211804)
simple/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.

Re:Restic – Backups Done Right by bccdee on Saturday November 13, 2021 @10:35PM (#29215191)
Sure, but if I'm not comfortable with the terminal, I probably shouldn't be too loud with my criticisms of shell scripts.
Re:Restic – Backups Done Right by kkjjkgjjgg on Sunday November 14, 2021 @05:31AM (#29216449)
It just seems a pity that knowledge of shell scripts is necessary to do backups.
Re:Restic – Backups Done Right by bccdee on Sunday November 14, 2021 @11:39AM (#29218276)
Yeah 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.

Re:Restic – Backups Done Right by kkjjkgjjgg on Saturday November 13, 2021 @01:20PM (#29211926)
With a GUI. I think it could also be less error prone if the user interface guides through the configuration.
Re:Restic – Backups Done Right by nsv on Saturday November 13, 2021 @05:37PM (#29213778)
You won't find much support for an opinion like that on a site named "hacker" news, haha.

A lot of backup services (tarsnap comes to mind) prioritize scriptability, as I imagine many people run backups from cron or a systemd timer.

Re:Restic – Backups Done Right by ccakes on Saturday November 13, 2021 @01:31PM (#29212040)
Then it’s less scriptable. Many of us would prefer a CLI-based solution for that reason
Re:Restic – Backups Done Right by xook on Saturday November 13, 2021 @05:44PM (#29213831)
It doesn't have to be one or the other. The GUI would be for one-off or intermittent usage, and the CLI program would still come in as the primary tool for scripting or recurring use.
Re:Restic – Backups Done Right by gnubison on Saturday November 13, 2021 @03:28PM (#29212898)
Would it really be simpler to have 100 lines of GUI setup and tear down, obscuring the most important part (the commands being run)?
Re:Restic – Backups Done Right by Dudeman112 on Sunday November 14, 2021 @06:25AM (#29216622)
Both sounds good as opposed to instead.

GUIs for simple stuff and 99% of the population, CLIs for hackermans who need the advanced stuff.

Re:Restic – Backups Done Right by kkjjkgjjgg on Sunday November 14, 2021 @05:30AM (#29216447)
Depending on the GUI, it seems possible. You can also verify input in a GUI
Re:Restic – Backups Done Right by jcelerier on Sunday November 14, 2021 @09:13AM (#29217254)
I'd personally put the threshold for "complicated" at "do you need a keyboard to be able to use it". So it's pretty complicated.
Re:Restic – Backups Done Right by smackeyacky on Saturday November 13, 2021 @05:51PM (#29213869)
It does seem a bit obtuse. Especially compared with

# tar cvf /dev/st0 .

Re:Restic – Backups Done Right by IceWreck on Saturday November 13, 2021 @04:30PM (#29213332)
Its a single shell command.

restic -r reponame /path-to-files-to-be-backuped

Everything else in the mentioned script is optional stuff for scheduling, removing old backups, etc.

Re:Restic – Backups Done Right by lobocinza on Saturday November 13, 2021 @07:53PM (#29214577)
It kind is, simple but effective. For comparison, take a look at my over-engineered backup script: https://github.com/danisztls/arbie/blob/main/arbie
Re:Restic – Backups Done Right by krick on Sunday November 14, 2021 @11:02AM (#29217970)
Well, 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.
Re:Restic – Backups Done Right by kkjjkgjjgg on Sunday November 14, 2021 @05:22AM (#29216414)
Wow :-)