Skip to content

Instantly share code, notes, and snippets.

@Prototyped
Created March 14, 2022 13:39
Show Gist options
  • Select an option

  • Save Prototyped/9585da21912b028a61b7a42ef4879bd6 to your computer and use it in GitHub Desktop.

Select an option

Save Prototyped/9585da21912b028a61b7a42ef4879bd6 to your computer and use it in GitHub Desktop.
Borg backup
#!/bin/bash
set -euo pipefail
PATH=${PATH}:/sbin:/usr/sbin
[ -x /etc/init.d/lvm2-lvmetad ] && /etc/init.d/lvm2-lvmetad restart
[ -x /etc/init.d/lvm2-lvmpolld ] && /etc/init.d/lvm2-lvmpolld restart
[ -x /etc/init.d/lvm2 ] && /etc/init.d/lvm2 restart
. /etc/borg/passphrase
export BORG_PASSPHRASE
[ -d /mnt/backup/data ] || mount /mnt/backup
[ -d /mnt/aux2/home ] && umount -f /mnt/aux2
[ -e /dev/Data/backup-snapshot ] && lvremove -f /dev/Data/backup-snapshot
sync
sync
sync
if [ "${1-ssdroot}" = ssdroot ]; then
lvcreate -L256GiB -s -n backup-snapshot /dev/Data/Root
mount -o ro,nouuid,norecovery /dev/Data/backup-snapshot /mnt/aux2
systemctl stop sav-protect
time borg create -x --numeric-ids -C lz4 -e '/mnt/aux2/tmp' -e '/mnt/aux2/var/tmp' -e '/mnt/aux2/var/cache' -e '/mnt/aux2/SWAPFILE' -s -p "/mnt/backup/ssdroot::$(date -u '+%Y-%m-%dT%H:%M:%SZ')" /mnt/aux2/.
umount /mnt/aux2
lvremove -f Data/backup-snapshot
systemctl start sav-protect
time borg prune -d 7 -w 9 -m 12 -y 2 /mnt/backup/ssdroot
fi
if [ "${1-data}" = data ]; then
lvcreate -L256GiB -s -n backup-snapshot /dev/Data/data
mount -o ro /dev/Data/backup-snapshot /mnt/aux2
systemctl stop sav-protect
time borg create -x --numeric-ids -C lz4 -s -p "/mnt/backup/data::$(date -u '+%Y-%m-%dT%H:%M:%SZ')" /mnt/aux2/.
umount /mnt/aux2
lvremove -f Data/backup-snapshot
systemctl start sav-protect
time borg prune -d 7 -w 9 -m 12 -y 2 /mnt/backup/data
fi
umount /mnt/backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment