Skip to content

Instantly share code, notes, and snippets.

@fabricionaweb
Last active November 22, 2023 13:45
Show Gist options
  • Save fabricionaweb/192dd038df070043ba43b4ece6486e20 to your computer and use it in GitHub Desktop.
Save fabricionaweb/192dd038df070043ba43b4ece6486e20 to your computer and use it in GitHub Desktop.
Backups with restic
# backblaze
export B2_ACCOUNT_ID=""
export B2_ACCOUNT_KEY=""
export RESTIC_BACKBLAZE="b2:bucket"
# cloudflare (s3 uses AWS variables)
export AWS_ACCESS_KEY_ID=""
export AWS_SECRET_ACCESS_KEY=""
export RESTIC_CLOUDFLARE="s3:https://id.r2.cloudflarestorage.com/bucket"
# others
export RESTIC_LOCAL="/mnt/user0/data/backups"
export RESTIC_USB="/mnt/disks/External/backups"
# common
export RESTIC_PASSWORD=""
export RESTIC_CACHE_DIR=/mnt/appdata/.extra/.restic
#!/bin/bash
# this file holds repositories like RESTIC_REMOTE RESTIC_LOCAL RESTIC_USB
source /mnt/appdata/.extra/.restic-env
# where lxc is installed at
LXC_BASE=/mnt/appdata/lxc/
# make the backups to all repositories
backup() {
local TAG=$1
local DIR=$2
shift 2
echo "[Local] $TAG"
restic -r "$RESTIC_LOCAL" backup "$DIR" --tag "$TAG" $@
#echo "[USB] $TAG"
#restic -r "$RESTIC_USB" backup "$DIR" --tag "$TAG" $@
echo "[Backblaze] $TAG"
restic -r "$RESTIC_BACKBLAZE" backup "$DIR" --tag "$TAG" $@
echo "[Cloudflare] $TAG"
restic -r "$RESTIC_CLOUDFLARE" backup "$DIR" --tag "$TAG" $@
}
# delete old backups
clean() {
local LAST=7
local WEEK=4
local MONTH=12
echo "[Clean]"
restic -r "$RESTIC_LOCAL" forget --prune --keep-last $LAST --keep-weekly $WEEK --keep-monthly $MONTH
#restic -r "$RESTIC_USB" forget --prune --keep-last $LAST --keep-weekly $WEEK --keep-monthly $MONTH
restic -r "$RESTIC_BACKBLAZE" forget --prune --keep-last $LAST --keep-weekly $WEEK --keep-monthly $MONTH
restic -r "$RESTIC_CLOUDFLARE" forget --prune --keep-last $LAST --keep-weekly $WEEK --keep-monthly $MONTH
}
# ALPINE_MEDIA=$LXC_BASE/alpine-media/rootfs
# /usr/bin/lxc-stop alpine-media
# backup alpine-media $ALPINE_MEDIA \
# --iexclude "/var/lib/**/{backup,backups,log,logs,cache,caches,update,updates}" \
# --iexclude "/var/lib/sabnzbd/history" \
# --exclude "/var/lib/**/MediaCover" \
# --exclude "/var/{cache,log}" --exclude "*.log" \
# --exclude "/tmp"
# /usr/bin/lxc-start alpine-media &
# ALPINE_TORRENT=$LXC_BASE/alpine-torrent/rootfs
# /usr/bin/lxc-stop alpine-torrent
# backup alpine-torrent $ALPINE_TORRENT \
# --iexclude "/var/lib/**/{backup,backups,log,logs,cache,caches,update,updates}" \
# --exclude "/var/{cache,log}" --exclude "*.log" \
# --exclude "/tmp"
# /usr/bin/lxc-start alpine-torrent &
ALPINE_MISC=$LXC_BASE/alpine-misc/rootfs
/usr/bin/lxc-stop alpine-misc
backup alpine-misc $ALPINE_MISC \
--iexclude "/var/lib/**/{backup,backups,log,logs,cache,caches,update,updates}" \
--exclude "/var/{cache,log}" --exclude "*.log" \
--exclude "/tmp"
/usr/bin/lxc-start alpine-misc &
# DEBIAN_PLEX=$LXC_BASE/debian-plex/rootfs/
# backup debian-plex $DEBIAN_PLEX \
# --iexclude "/var/lib/**/{backup,backups,log,logs,cache,caches,update,updates}" \
# --exclude "/var/{backups,cache,log}" --exclude "*.log" \
# --exclude "/tmp" \
# --exclude "/var/lib/apt" \
# --iexclude "/var/lib/plexmediaserver/**/*.db-*-*-*"
# backup unraid /boot \
# --exclude ".git"
# docker
APPDATA=/mnt/appdata/docker
backup docker $APPDATA \
--iexclude "/**/{backup,backups,log,logs,cache,caches,update,updates}" \
--iexclude "/sabnzbd/history" \
--iexclude "/**/MediaCover" \
--iexclude "/**/*.db-*-*-*" \
--exclude "*.log"
clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment