Skip to content

Instantly share code, notes, and snippets.

@0xDBFB7
Created February 12, 2022 19:11
Show Gist options
  • Save 0xDBFB7/15ed47ceaa267f855f3690ab71e6fe0f to your computer and use it in GitHub Desktop.
Save 0xDBFB7/15ed47ceaa267f855f3690ab71e6fe0f to your computer and use it in GitHub Desktop.
Script to perform restic backup on an LVM volume without it filling up
# <add spaces to keep out of bash hist> export RESTIC_PASSWORD=""
# run this command with sudo -E ./restic.sh
########
lvcreate -L 20G -s -n backup-snapshot /dev/new_root/lv0 || exit 1
mount /dev/new_root/backup-snapshot /home/arthurdent/NAS/backup-snapshot || exit 1
export B2_ACCOUNT_ID="XXXXXXXXXX"
export B2_ACCOUNT_KEY="XXXXXXXXXXX"
#source ~/scripts/restic.sh
# restic_bin = "~/Programs/restic_0.12.1_linux_amd64/restic"
#sudo -E restic -r b2:DeepThought-Ryzen-restic backup /home/arthurdent/NAS/backup-snapshot
restic_cmd="/home/arthurdent/Programs/restic_0.12.1_linux_amd64/restic -r b2:DeepThought-Ryzen-restic backup /home/arthurdent/NAS/backup-snapshot --cache-dir /home/arthurdent/NAS/primary_a/.restic_cache/ &"
eval "$restic_cmd"
restic_pid=$!
while true
do
snap_percent="$(lvs -o snap_percent --no-headings)"
# echo $snap_percent
snap_percent="$( printf "%.0f" $snap_percent )"
sleep 5
# if ! kill -0 "$restic_pid"; then
# echo "complete"
# exit 1
# fi
lvm_full=$(( $snap_percent >= 50 ))
if ! [ $lvm_full -eq 0 ]; then
echo "LVM full, reloading"
killall -INT restic
umount /home/arthurdent/NAS/backup-snapshot
yes | lvremove /dev/new_root/backup-snapshot
lvcreate -L 20G -s -n backup-snapshot /dev/new_root/lv0 || exit 1
mount /dev/new_root/backup-snapshot /home/arthurdent/NAS/backup-snapshot || exit 1
eval $restic_cmd
restic_pid=$!
fi
done
umount /home/arthurdent/NAS/backup-snapshot
yes | lvremove /dev/new_root/backup-snapshot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment