Skip to content

Instantly share code, notes, and snippets.

@AndrewPaglusch
Created February 7, 2021 01:12
Show Gist options
  • Select an option

  • Save AndrewPaglusch/c0ab5185c52cd193ba0656bb3c2103a2 to your computer and use it in GitHub Desktop.

Select an option

Save AndrewPaglusch/c0ab5185c52cd193ba0656bb3c2103a2 to your computer and use it in GitHub Desktop.
Restic Backup to B2 for Elkarbackup
#!/bin/sh
##################################################################################
# MIT License #
# #
# Copyright (c) 2021 Andrew Paglusch #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy #
# of this software and associated documentation files (the "Software"), to deal #
# in the Software without restriction, including without limitation the rights #
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #
# copies of the Software, and to permit persons to whom the Software is #
# furnished to do so, subject to the following conditions: #
# #
# The above copyright notice and this permission notice shall be included in all #
# copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
# SOFTWARE. #
##################################################################################
## This script will backup the Elkarbackups directory to Backblaze B2 via Restic
export B2_ACCOUNT_ID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
export B2_ACCOUNT_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
export RESTIC_REPOSITORY="b2:bucket-name-here"
export RESTIC_PASSWORD_FILE="/opt/restic/restic-password"
echo "Unlocking Restic repo before backup..."
sudo -E /opt/restic/restic unlock 2>&1
echo "Starting Restic backup..."
sudo -E /opt/restic/restic -o b2.connections=20 backup /opt/docker/elkarbackup/backups --exclude=*/*/Daily.{1..10} --exclude=*/*/.sync 2>&1
#Forget and delete/purge backups older than 90 days
echo "Cleaning backups older than 90 days..."
sudo -E /opt/restic/restic -o b2.connections=20 forget --keep-last 90 --prune
echo "Completed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment