Last active
December 15, 2015 07:21
-
-
Save calebreister/3d04aa3c81affd4d43ec to your computer and use it in GitHub Desktop.
New and updated version of backup.sh. The old script had many limitations and was often unreliable. This script, while requiring slightly more user input, is much more robust.
This file contains 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/sh | |
#Find a date in file name: | |
#ls | grep -E $datematch | |
increment() { | |
# Creates a backup version of a btrfs subvolume and sends it to to an | |
# external drive. Assumes there are drives mounted in ./hd and ./bu | |
# $1 subvolume to backup | |
# $2 date of parent | |
# $3 date of child | |
local old=$1-$2 | |
local new=$1-$3 | |
echo Backing up $1... | |
btrfs sub snap -r ./hd/$1 ./hd/$new | |
echo Sending $new to external drive... | |
sync | |
btrfs send -p ./hd/$old ./hd/$new | btrfs receive ./bu/ | |
echo ----------------------------------------------------------------------- | |
} | |
if [ "$(whoami)" != "root" ]; then | |
echo Please run this script as root. | |
exit | |
fi | |
cd /mnt | |
#Mount drives | |
mount /dev/sda3 ./hd | |
mount /dev/sdb1 ./bu | |
echo /dev/sda3: | |
ls ./hd | |
echo ----------------------------------------------------------------------- | |
echo /dev/sdb1: | |
ls ./bu | |
echo ----------------------------------------------------------------------- | |
#User Prompts | |
read -p 'Backup @ [y/n]? ' bu_root | |
read -p 'Backup @home [y/n]? ' bu_home | |
read -p 'Backup @Dropbox [y/n]? ' bu_dropbox | |
read -p 'Date of previous version: ' old_ver | |
today=$(date -I) | |
#Backup function calls | |
if ([ $bu_root = "y" ] || [ $bu_hd = "Y" ]); then | |
increment @ $old_ver $today | |
fi | |
if ([ $bu_home = "y" ] || [ $bu_home = "Y" ]); then | |
increment @home $old_ver $today | |
fi | |
if ([ $bu_dropbox = "y" ] || [ $bu_dropbox = "Y" ]); then | |
increment @Dropbox $old_ver $today | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment