fix menu
This commit is contained in:
118
backup
118
backup
@@ -71,81 +71,75 @@ for x in $SNAPPER_CONFIGS; do
|
|||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
source /etc/snapper/configs/$x
|
source /etc/snapper/configs/$x
|
||||||
|
|
||||||
read -n 1 -p "Perform backup on '$x' configuration (y/n)? " do_backup
|
|
||||||
echo
|
|
||||||
|
|
||||||
if [[ $do_backup == "y" ]]; then
|
old_number=$(snapper -c "$x" list -t single | awk '/'"$selected_uuid"'/ {print $1}')
|
||||||
|
new_number=$(snapper -c "$x" create --print-number)
|
||||||
|
sync
|
||||||
|
|
||||||
|
new_snapshot=$SUBVOLUME/.snapshots/$new_number/snapshot
|
||||||
|
new_info=$SUBVOLUME/.snapshots/$new_number/info.xml
|
||||||
|
echo "At '$x' configuration"
|
||||||
|
|
||||||
old_number=$(snapper -c "$x" list -t single | awk '/'"$selected_uuid"'/ {print $1}')
|
if [[ -z "$old_number" ]]; then
|
||||||
new_number=$(snapper -c "$x" create --print-number)
|
|
||||||
sync
|
|
||||||
|
|
||||||
new_snapshot=$SUBVOLUME/.snapshots/$new_number/snapshot
|
|
||||||
new_info=$SUBVOLUME/.snapshots/$new_number/info.xml
|
|
||||||
|
|
||||||
if [[ -z "$old_number" ]]; then
|
echo "No backups have been performed for '$x' on this disk."
|
||||||
|
read -p "Enter name of directory to store backups: " mybackupdir
|
||||||
|
|
||||||
echo "No backups have been performed for '$x' on this disk."
|
BACKUPDIR="$(findmnt -n -v -t btrfs -o UUID,TARGET --list | awk '/'$selected_uuid'/ {print $2}')/$mybackupdir"
|
||||||
read -p "Enter name of directory to store backups: " mybackupdir
|
backup_location=$BACKUPDIR/$x/$new_number/
|
||||||
|
echo "Backup location: $backup_location"
|
||||||
|
read -n 1 -p "Continue (y/n)? " cont_backup
|
||||||
|
echo
|
||||||
|
if [[ "$cont_backup" != "y" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
mkdir -p "$backup_location"
|
||||||
|
echo "Performing initial backup for snapper configuration '$x'. This could take awhile..."
|
||||||
|
btrfs send "$new_snapshot" | btrfs receive "$backup_location"
|
||||||
|
|
||||||
BACKUPDIR="$(findmnt -n -v -t btrfs -o UUID,TARGET --list | awk '/'$selected_uuid'/ {print $2}')/$mybackupdir"
|
else
|
||||||
backup_location=$BACKUPDIR/$x/$new_number/
|
|
||||||
echo "Backup location: $backup_location"
|
|
||||||
read -n 1 -p "Continue (y/n)? " cont_backup
|
|
||||||
echo
|
|
||||||
if [[ "$cont_backup" != "y" ]]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
mkdir -p "$backup_location"
|
|
||||||
echo "Performing initial backup for snapper configuration '$x'. This could take awhile..."
|
|
||||||
btrfs send "$new_snapshot" | btrfs receive "$backup_location"
|
|
||||||
|
|
||||||
else
|
mybackupdir=$(snapper -c root list -t single | awk -F"|" '/'$selected_uuid'/ {print $5}' | awk -F "," '{print $1}' | awk -F"=" '{print $2}')
|
||||||
|
BACKUPDIR="$(findmnt -n -v -t btrfs -o UUID,TARGET --list | awk '/'$selected_uuid'/ {print $2}')/$mybackupdir"
|
||||||
mybackupdir=$(snapper -c root list -t single | awk -F"|" '/'$selected_uuid'/ {print $5}' | awk -F "," '{print $1}' | awk -F"=" '{print $2}')
|
|
||||||
BACKUPDIR="$(findmnt -n -v -t btrfs -o UUID,TARGET --list | awk '/'$selected_uuid'/ {print $2}')/$mybackupdir"
|
|
||||||
|
|
||||||
if [[ ! -d $BACKUPDIR ]]; then
|
|
||||||
echo "ERROR: $BACKUPDIR is not a directory."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
backup_location=$BACKUPDIR/$x/$new_number/
|
|
||||||
|
|
||||||
echo "Backup location: $backup_location"
|
|
||||||
if [[ -d "$backup_location" ]]; then
|
|
||||||
echo "ERROR: Backup location already exists."
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
mkdir -p "$backup_location"
|
|
||||||
|
|
||||||
read -n 1 -p "Continue (y/n)? " cont_backup
|
|
||||||
echo
|
|
||||||
if [[ "$cont_backup" != "y" ]]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
old_snapshot=$SUBVOLUME/.snapshots/$old_number/snapshot
|
|
||||||
|
|
||||||
# Sends the difference between the new snapshot and old snapshot to
|
|
||||||
# the backup location. Using the -c flag instead of -p tells it that
|
|
||||||
# there is an identical subvolume to the old snapshot at the
|
|
||||||
# receiving location where it can get its data. This helps speed up
|
|
||||||
# the transfer.
|
|
||||||
btrfs send "$new_snapshot" -c "$old_snapshot" | btrfs receive "$backup_location" &>/dev/null
|
|
||||||
|
|
||||||
cp "$new_info" "$backup_location"
|
|
||||||
snapper -c "$x" delete "$old_number"
|
|
||||||
|
|
||||||
|
if [[ ! -d $BACKUPDIR ]]; then
|
||||||
|
echo "ERROR: $BACKUPDIR is not a directory."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
userdata="backupdir=$mybackupdir, uuid=$selected_uuid"
|
backup_location=$BACKUPDIR/$x/$new_number/
|
||||||
|
|
||||||
# Tag new snapshot as the latest
|
echo "Backup location: $backup_location"
|
||||||
snapper -v -c "$x" modify -d "$description" -u "$userdata" "$new_number"
|
if [[ -d "$backup_location" ]]; then
|
||||||
|
echo "ERROR: Backup location already exists."
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
mkdir -p "$backup_location"
|
||||||
|
|
||||||
|
read -n 1 -p "Continue (y/n)? " cont_backup
|
||||||
|
echo
|
||||||
|
if [[ "$cont_backup" != "y" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
old_snapshot=$SUBVOLUME/.snapshots/$old_number/snapshot
|
||||||
|
|
||||||
|
# Sends the difference between the new snapshot and old snapshot to
|
||||||
|
# the backup location. Using the -c flag instead of -p tells it that
|
||||||
|
# there is an identical subvolume to the old snapshot at the
|
||||||
|
# receiving location where it can get its data. This helps speed up
|
||||||
|
# the transfer.
|
||||||
|
btrfs send "$new_snapshot" -c "$old_snapshot" | btrfs receive "$backup_location" &>/dev/null
|
||||||
|
|
||||||
|
cp "$new_info" "$backup_location"
|
||||||
|
snapper -c "$x" delete "$old_number"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
userdata="backupdir=$mybackupdir, uuid=$selected_uuid"
|
||||||
|
|
||||||
|
# Tag new snapshot as the latest
|
||||||
|
snapper -v -c "$x" modify -d "$description" -u "$userdata" "$new_number"
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user