Last active
March 13, 2022 03:04
-
-
Save leogao2/573f5c4f8a3ae4f9852649c59bcc8d10 to your computer and use it in GitHub Desktop.
A fully self contained script for making a backup on an Ubuntu system using LVM. On a typical system, only configuration you need to do is 1. change BKP_LOC to wherever you want to save your backup and 2. make a password file at ~/borg_password (and you might need to enter this password first time running the script, but it's automated thereafter)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# change these values before use! | |
# where you want the backup to go | |
BKP_LOC=/mnt/backup/primary | |
# the name of the source LV | |
SOURCE_LVM=vgubuntu/root | |
# where the repo password is stored | |
PASSWORD_FILE=~/borg_password | |
TMP_CKPT_SIZE=20G | |
SNAPSHOT_NAME=$(date '+%Y-%m-%d.%H-%M') | |
SOURCE_VG=$(echo $SOURCE_LVM | cut -d/ -f 1) | |
# make LVM snapshot | |
sudo lvcreate --size $TMP_CKPT_SIZE --snapshot --name root_bkp_snapshot /dev/$SOURCE_LVM | |
sudo mkdir -p /mnt/bkp_tmp | |
sudo mount /dev/$SOURCE_VG/root_bkp_snapshot /mnt/bkp_tmp | |
# backup with borg | |
borg -V || sudo apt install borgbackup -y | |
borg init --encryption=repokey $BKP_LOC | |
BORG_PASSPHRASE=$(cat $PASSWORD_FILE) sudo -E borg create --progress --stats $BKP_LOC::$SNAPSHOT_NAME /mnt/bkp_tmp | |
sudo umount /mnt/bkp_tmp | |
sudo lvremove $SOURCE_VG/root_bkp_snapshot -y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment