For those who use Restic for their backups, please share your set-ups

I’ve been using Bash scripts with cronjobs to schedule daily backups, and then sync the backup to BackblazeB2 after the local backup has completed.

However, it’s a bit messy and has a failure point where a locally corrupted repo could be uploaded to the remote repo. It also doesn’t send emails on failure or success.

amp,

two repos, one local one remote, alternating between them manually, using https://gitlab.com/stormking/resticguigx/ (I wrote that)

spez_,

This looks great. I wonder if it’s possible to expose this to the (local) internet so I can access it via e.g. restic.mydomain.com

amp,

nope, but you're not the first one to ask, so maybe I'll write that one day.

LastoftheDinosaurs,
@LastoftheDinosaurs@lemmy.world avatar

I don’t even use cron. Manual backups, rarely taken. I only really want my config files to be saved, and I’ve been using git for that mostly.

I took a full backup shortly after install using restic. I’ve restored it a couple of times. Works for me.

raphael,

After jumping between duplicati, duplicacy, borg backup, kopia I finally settled on Restic a couple of weeks ago.

Using it with resticprofile (https://github.com/creativeprojects/resticprofile) on Linux and Windows which does all the heavy lifting converting the setup from a simple configuration file to restic commands and adding a few options like calling webhooks on specific conditions etc. It is running rock stable so far.

https://creativeprojects.github.io/resticprofile/configuration/getting_started/index.html

spez_,

Here’s mine:

shared.sh

<pre style="background-color:#ffffff;">
<span style="font-style:italic;color:#969896;">#!/bin/bash
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># Sources to be backed up
</span><span style="color:#323232;">SOURCES</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;">(
</span><span style="color:#323232;">    </span><span style="color:#183691;">"/srv/dev-disk-by-uuid-a57d5696-00fk-4d1c-9885-095ad5cf71ba/Stuff/"
</span><span style="color:#323232;">)
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># Restic configurations
</span><span style="color:#323232;">RESTIC_CONFIG_LOCATION</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"/srv/dev-disk-by-uuid-a77de696-04f9-4d1c-9875-055advcf71ba/Stuff/Projects/Setup/Backups/restic-config"
</span><span style="color:#323232;">RESTIC_REPO</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"/srv/dev-disk-by-uuid-25EE65533BB23C37/restic/repo"
</span><span style="color:#323232;">RESTIC_PASSWORD_FILE</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"${</span><span style="color:#323232;">RESTIC_CONFIG_LOCATION</span><span style="color:#183691;">}/config/password.txt"
</span><span style="color:#323232;">RESTIC_EXCLUDE_FILE</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"${</span><span style="color:#323232;">RESTIC_CONFIG_LOCATION</span><span style="color:#183691;">}/config/excludes.txt"
</span><span style="color:#323232;">RESTIC_LOG_LOCATION</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"${</span><span style="color:#323232;">RESTIC_CONFIG_LOCATION</span><span style="color:#183691;">}/logs"
</span><span style="color:#323232;">RESTIC_LOCK_LOCATION</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"${</span><span style="color:#323232;">RESTIC_REPO</span><span style="color:#183691;">}/locks"
</span><span style="color:#323232;">RESTIC_MOUNT_LOCATION</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"/srv/dev-disk-by-uuid-28EE65538BB23J37/restic/mount"
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># RClone configurations
</span><span style="color:#323232;">RCLONE_CONFIG</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"${</span><span style="color:#323232;">RESTIC_CONFIG_LOCATION</span><span style="color:#183691;">}/config/rclone.conf"
</span><span style="color:#323232;">RCLONE_REPO</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"bucket:restic-backup"
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">function </span><span style="font-weight:bold;color:#795da3;">unlock-repo</span><span style="color:#323232;">() {
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#a71d5d;">if </span><span style="color:#62a35c;">[[ </span><span style="color:#323232;">$(ls -A ${RESTIC_LOCK_LOCATION}) </span><span style="color:#62a35c;">]] </span><span style="font-weight:bold;color:#a71d5d;">; then
</span><span style="color:#323232;">        restic -r ${RESTIC_REPO} unlock --password-file</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;">${RESTIC_PASSWORD_FILE}
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#a71d5d;">fi
</span><span style="color:#323232;">}
</span>

backup.sh

<pre style="background-color:#ffffff;">
<span style="font-style:italic;color:#969896;">#!/usr/bin/env bash
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># Get the directory this script is from, and then source the
</span><span style="font-style:italic;color:#969896;"># shared.sh shell script for the environment variables and
</span><span style="font-style:italic;color:#969896;"># functions
</span><span style="color:#323232;">BASEDIR</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">$(</span><span style="color:#323232;">dirname </span><span style="color:#183691;">"$</span><span style="color:#323232;">0</span><span style="color:#183691;">")
</span><span style="color:#62a35c;">source </span><span style="color:#183691;">"${</span><span style="color:#323232;">BASEDIR</span><span style="color:#183691;">}/shared.sh"
</span><span style="color:#323232;">
</span><span style="color:#323232;">RESTIC_LOG_FILE</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"${</span><span style="color:#323232;">RESTIC_LOG_LOCATION</span><span style="color:#183691;">}/log-backup.txt"
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># Backs up the sources to the local Restic repository
</span><span style="font-weight:bold;color:#a71d5d;">function </span><span style="font-weight:bold;color:#795da3;">backup</span><span style="color:#323232;">() {
</span><span style="color:#323232;">    </span><span style="font-style:italic;color:#969896;"># Get the latest saved parent snapshot ID
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#a71d5d;">local </span><span style="color:#323232;">short_id</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">$(</span><span style="color:#323232;">restic -r </span><span style="color:#183691;">${</span><span style="color:#323232;">RESTIC_REPO</span><span style="color:#183691;">}</span><span style="color:#323232;"> --password-file</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">${</span><span style="color:#323232;">RESTIC_PASSWORD_FILE</span><span style="color:#183691;">}</span><span style="color:#323232;"> --json</span><span style="color:#183691;"> snapshots </span><span style="font-weight:bold;color:#a71d5d;">| </span><span style="color:#323232;">jq -r </span><span style="color:#183691;">'max_by(.time) | .short_id')
</span><span style="color:#323232;">    </span><span style="font-style:italic;color:#969896;"># Back up and log the results
</span><span style="color:#323232;">    (
</span><span style="color:#323232;">        </span><span style="color:#62a35c;">echo
</span><span style="color:#323232;">        </span><span style="color:#62a35c;">echo
</span><span style="color:#323232;">        date
</span><span style="color:#323232;">        </span><span style="color:#62a35c;">echo
</span><span style="color:#323232;">        </span><span style="color:#62a35c;">echo
</span><span style="color:#323232;">        restic -r ${RESTIC_REPO} backup ${SOURCES[@]} --exclude-file</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;">${RESTIC_EXCLUDE_FILE} --password-file</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;">${RESTIC_PASSWORD_FILE} --parent ${short_id} --compression max
</span><span style="color:#323232;">    ) </span><span style="font-weight:bold;color:#a71d5d;">>></span><span style="color:#323232;">${RESTIC_LOG_FILE}
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">function </span><span style="font-weight:bold;color:#795da3;">main</span><span style="color:#323232;">() {
</span><span style="color:#323232;">    unlock-repo
</span><span style="color:#323232;">    backup
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="color:#323232;">main $@
</span>

validate.sh

<pre style="background-color:#ffffff;">
<span style="font-style:italic;color:#969896;">#!/usr/bin/env bash
</span><span style="color:#323232;">
</span><span style="color:#323232;">BASEDIR</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">$(</span><span style="color:#323232;">dirname </span><span style="color:#183691;">"$</span><span style="color:#323232;">0</span><span style="color:#183691;">")
</span><span style="color:#62a35c;">source </span><span style="color:#183691;">"${</span><span style="color:#323232;">BASEDIR</span><span style="color:#183691;">}/shared.sh"
</span><span style="color:#323232;">
</span><span style="color:#323232;">RESTIC_LOG_FILE</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"${</span><span style="color:#323232;">RESTIC_LOG_LOCATION</span><span style="color:#183691;">}/log-validate.txt"
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># Validates the local Restic repository.
</span><span style="font-weight:bold;color:#a71d5d;">function </span><span style="font-weight:bold;color:#795da3;">validate-locally</span><span style="color:#323232;">() {
</span><span style="color:#323232;">    (
</span><span style="color:#323232;">        </span><span style="color:#62a35c;">echo
</span><span style="color:#323232;">        </span><span style="color:#62a35c;">echo
</span><span style="color:#323232;">        date
</span><span style="color:#323232;">        </span><span style="color:#62a35c;">echo
</span><span style="color:#323232;">        </span><span style="color:#62a35c;">echo
</span><span style="color:#323232;">        restic -r ${RESTIC_REPO} check --read-data --password-file</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;">${RESTIC_PASSWORD_FILE}
</span><span style="color:#323232;">    ) </span><span style="font-weight:bold;color:#a71d5d;">>></span><span style="color:#323232;">${RESTIC_LOG_FILE}
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">function </span><span style="font-weight:bold;color:#795da3;">main</span><span style="color:#323232;">() {
</span><span style="color:#323232;">    unlock-repo
</span><span style="color:#323232;">    validate-locally
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="color:#323232;">main $@
</span>

sync.sh

<pre style="background-color:#ffffff;">
<span style="font-style:italic;color:#969896;">#!/usr/bin/env bash
</span><span style="color:#323232;">
</span><span style="color:#323232;">BASEDIR</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">$(</span><span style="color:#323232;">dirname </span><span style="color:#183691;">"$</span><span style="color:#323232;">0</span><span style="color:#183691;">")
</span><span style="color:#62a35c;">source </span><span style="color:#183691;">"${</span><span style="color:#323232;">BASEDIR</span><span style="color:#183691;">}/shared.sh"
</span><span style="color:#323232;">
</span><span style="color:#323232;">RESTIC_LOG_FILE</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"${</span><span style="color:#323232;">RESTIC_LOG_LOCATION</span><span style="color:#183691;">}/log-sync.txt"
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># Syncs the local Restic repository to the cloud provider, under the 'Restic' folder.
</span><span style="font-weight:bold;color:#a71d5d;">function </span><span style="font-weight:bold;color:#795da3;">cloud-sync</span><span style="color:#323232;">() {
</span><span style="color:#323232;">    (
</span><span style="color:#323232;">        </span><span style="color:#62a35c;">echo
</span><span style="color:#323232;">        </span><span style="color:#62a35c;">echo
</span><span style="color:#323232;">        date
</span><span style="color:#323232;">        </span><span style="color:#62a35c;">echo
</span><span style="color:#323232;">        </span><span style="color:#62a35c;">echo
</span><span style="color:#323232;">    ) </span><span style="font-weight:bold;color:#a71d5d;">>></span><span style="color:#323232;">${RESTIC_LOG_FILE}
</span><span style="color:#323232;">    rclone -v sync ${RESTIC_REPO} ${RCLONE_REPO} --config</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;">${RCLONE_CONFIG} --log-file</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;">${RESTIC_LOG_FILE} --b2-hard-delete
</span><span style="color:#323232;">    rclone cleanup ${RCLONE_REPO} --config</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;">${RCLONE_CONFIG} --log-file</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;">${RESTIC_LOG_FILE}
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">function </span><span style="font-weight:bold;color:#795da3;">main</span><span style="color:#323232;">() {
</span><span style="color:#323232;">    cloud-sync
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="color:#323232;">main $@
</span>
drspod,

Thanks for posting this. I’ve been meaning to write something similar for a while but never got around to it. I wish Restic would ship an official client application for managing this stuff!

spez_,

You’re welcome. Although I’m not good with Bash scripting, and it’s quite messy and could prove fatal if something goes wrong and it syncs to the secondary backup

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • wartaberita
  • uselessserver093
  • Food
  • aaaaaaacccccccce
  • [email protected]
  • test
  • CafeMeta
  • testmag
  • MUD
  • RhythmGameZone
  • RSS
  • dabs
  • TheResearchGuardian
  • Ask_kbincafe
  • KbinCafe
  • Testmaggi
  • Socialism
  • feritale
  • oklahoma
  • SuperSentai
  • KamenRider
  • All magazines