Scripting restic (languages/tools/snippets)

I’m wondering what scripting languages and tools people are using to work with restic?

I know there are some wrappers to automate backups and improve configuration, but I’m thinking more in the line of snippets to find particular snapshots, particular paths and such, to achieve things that are not possible with the command line. This ends up being the recommended solution to a number of issues discussed here on the forum.

And what would be a good way for users to post such snippets? Perhaps a #snippet tag or something here on the forum would be lightweight enough? This has been discussed as an aside in other discussions, such as Read password from gnome keyring - #3 by matt but I haven’t seen a dedicated discussion of it, or any recommended best practices.

[Edit - Turns out the Recipes category is the way to go for this: Recipes - restic forum]

Thinking more about what languages one might find in such a snippet collection, it seems a suitable scripting language would be one that made the following simple and effective:

  • Parsing json
  • Executing commands and parameters (to control restic)
  • Handling dates
  • Handling general regular expressions

I can think of the following possibilities:

  • Straight sh/bash (not the nicest, but ubiquitous)
  • Python
  • Go itself
  • PowerShell (perhaps the go-to solution for Windows users)
  • R (probably not that popular, but a personal go-to for historical reasons).

But there are probably more …

TL;DR: Bash.

For my personal systems, I just wrap my restic commands in simple Bash scripts.

For my customers, I use a (non-simple) Bash script as well, and wrap it using Platypus - Create Mac apps from command line scripts to create a .app for macOS that can be assigned full disk access which needed on macOS.

On the one Windows system I back up using restic, I use GitHub - kmwoley/restic-windows-backup: Powershell scripts to run Restic backups on Windows which has been working very well so far, never hard to touch it for a year or two :slight_smile:

1 Like

If you’re going for more, I can suggest Python, but that’s a personal preference. Any well-known high level language can handle that, thanks to restic being a simple binary without weird dependencies.

I am responsible of a backup environment with 3500+ restic-enabled vms. Using a fairly complex python wrapper for it: sets environment variables, triggers restic with appropriate parameters (tags, folder names etc), handles possible errors, logging statistics and keeps graphite data relevant etc.

PowerShell meets all of these requirements. It’s the only scripting language I’d claim to be proficient in so I’m highly biased but I think it checks all the boxes.

My script kicks off backups of all my specified paths, writes logs, parses the logs for sending in alerts, alerting, checking, and a weekly check --read-data on 1% of my repo.

There’s not much I’ve haven’t been able to solve with it. On Windows of course. Also available on *nix but those guys have languages they prefer already with no real reason to switch AFAICT.

That’s what I’ve been using the “recipes” category for here in the forum. Hopefully I haven’t been using it incorrectly…

Awesome, looks like there are lots of nice things there!