Use printf
This commit is contained in:
28
backup
28
backup
@@ -20,7 +20,7 @@ declare -r description="latest incremental backup"
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
echo "Script must be run as root."
|
printf "Script must be run as root.\n"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -43,13 +43,13 @@ for x in $UUIDS; do
|
|||||||
UUIDS_ARRAY[$i]=$x
|
UUIDS_ARRAY[$i]=$x
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
done
|
done
|
||||||
echo "Selected a mounted BTRFS device to backup to."
|
printf "Selected a mounted BTRFS device to backup to.\n"
|
||||||
disk=-1
|
disk=-1
|
||||||
while [[ $disk -lt 0 || $disk -gt $i ]]; do
|
while [[ $disk -lt 0 || $disk -gt $i ]]; do
|
||||||
for x in "${!TARGETS_ARRAY[@]}"; do
|
for x in "${!TARGETS_ARRAY[@]}"; do
|
||||||
echo -e "$((x+1))) ${UUIDS_ARRAY[$x]}\t(${TARGETS_ARRAY[$x]})"
|
printf "%s) %s (%s)\n" "$((x+1))" "${UUIDS_ARRAY[$x]}" "${TARGETS_ARRAY[$x]}"
|
||||||
done
|
done
|
||||||
echo "0) Exit"
|
printf "0) Exit\n"
|
||||||
read -r -p "Enter a number: " disk
|
read -r -p "Enter a number: " disk
|
||||||
done
|
done
|
||||||
if [[ $disk == 0 ]]; then
|
if [[ $disk == 0 ]]; then
|
||||||
@@ -57,12 +57,12 @@ if [[ $disk == 0 ]]; then
|
|||||||
fi
|
fi
|
||||||
selected_uuid="${UUIDS_ARRAY[$((disk-1))]}"
|
selected_uuid="${UUIDS_ARRAY[$((disk-1))]}"
|
||||||
selected_mnt="${TARGETS_ARRAY[$((disk-1))]}"
|
selected_mnt="${TARGETS_ARRAY[$((disk-1))]}"
|
||||||
echo "You selected the disk with UUID $selected_uuid."
|
printf "You selected the disk with UUID %s.\n" "$selected_uuid"
|
||||||
|
|
||||||
if [[ -f /etc/conf.d/snapper ]]; then
|
if [[ -f /etc/conf.d/snapper ]]; then
|
||||||
source /etc/conf.d/snapper
|
source /etc/conf.d/snapper
|
||||||
else
|
else
|
||||||
echo "ERROR: /etc/conf.d/snapper does not exist!"
|
printf "ERROR: /etc/conf.d/snapper does not exist!\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -70,22 +70,22 @@ for x in $SNAPPER_CONFIGS; do
|
|||||||
|
|
||||||
source /etc/snapper/configs/$x
|
source /etc/snapper/configs/$x
|
||||||
|
|
||||||
echo "At '$x' configuration"
|
printf "At '%s' configuration\n" "$x"
|
||||||
|
|
||||||
old_number=$(snapper -c "$x" list -t single | awk '/'"$selected_uuid"'/ {print $1}')
|
old_number=$(snapper -c "$x" list -t single | awk '/'"$selected_uuid"'/ {print $1}')
|
||||||
old_snapshot=$SUBVOLUME/.snapshots/$old_number/snapshot
|
old_snapshot=$SUBVOLUME/.snapshots/$old_number/snapshot
|
||||||
|
|
||||||
if [[ -z "$old_number" ]]; then
|
if [[ -z "$old_number" ]]; then
|
||||||
echo "No backups have been performed for '$x' on this disk."
|
printf "No backups have been performed for '%s' on this disk.\n" "$x"
|
||||||
read -r -p "Enter name of directory to store backups: " mybackupdir
|
read -r -p "Enter name of directory to store backups: " mybackupdir
|
||||||
echo "This will be the initial backup for snapper configuration '$x' to this disk. This could take awhile."
|
printf "This will be the initial backup for snapper configuration '%s' to this disk. This could take awhile.\n" "$x"
|
||||||
BACKUPDIR="$selected_mnt/$mybackupdir"
|
BACKUPDIR="$selected_mnt/$mybackupdir"
|
||||||
mkdir -p "$BACKUPDIR"
|
mkdir -p "$BACKUPDIR"
|
||||||
else
|
else
|
||||||
mybackupdir=$(snapper -c root list -t single | awk -F"|" '/'$selected_uuid'/ {print $5}' | awk -F "," '{print $1}' | awk -F"=" '{print $2}')
|
mybackupdir=$(snapper -c root list -t single | awk -F"|" '/'"$selected_uuid"'/ {print $5}' | awk -F "," '{print $1}' | awk -F"=" '{print $2}')
|
||||||
BACKUPDIR="$selected_mnt/$mybackupdir"
|
BACKUPDIR="$selected_mnt/$mybackupdir"
|
||||||
if [[ ! -d $BACKUPDIR ]]; then
|
if [[ ! -d $BACKUPDIR ]]; then
|
||||||
echo "ERROR: $BACKUPDIR is not a directory on $selected_uuid."
|
printf "ERROR: %s is not a directory on %s.\n" "$BACKUPDIR" "$selected_uuid"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -95,10 +95,10 @@ for x in $SNAPPER_CONFIGS; do
|
|||||||
new_info=$SUBVOLUME/.snapshots/$new_number/info.xml
|
new_info=$SUBVOLUME/.snapshots/$new_number/info.xml
|
||||||
sync
|
sync
|
||||||
backup_location=$BACKUPDIR/$x/$new_number/
|
backup_location=$BACKUPDIR/$x/$new_number/
|
||||||
echo "Backup location: $backup_location"
|
printf "Backup location: %s\n" "$backup_location"
|
||||||
|
|
||||||
read -r -n 1 -p "Continue (y/n)? " cont_backup
|
read -r -n 1 -p "Continue (y/n)? " cont_backup
|
||||||
echo
|
printf "\n"
|
||||||
if [[ "$cont_backup" != "y" ]]; then
|
if [[ "$cont_backup" != "y" ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
@@ -130,4 +130,4 @@ done
|
|||||||
|
|
||||||
date > "$HOME"/.lastbackup
|
date > "$HOME"/.lastbackup
|
||||||
|
|
||||||
echo "Done!"
|
printf "Done!\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user