snap-sync.bash: rename bash version of snap-sync to snap-sync.bash

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2017-11-16 19:19:11 +01:00
parent aa19fcbef8
commit 19dc43125c

View File

@@ -34,9 +34,9 @@ name="snap-sync"
SNAPPER_CONFIG=/etc/conf.d/snapper SNAPPER_CONFIG=/etc/conf.d/snapper
TMPDIR=$(mktemp -d) TMPDIR=$(mktemp -d)
PIPE=$TMPDIR/$name.out PIPE=$TMPDIR/$progname.out
mkfifo $PIPE mkfifo $PIPE
systemd-cat -t "$name" < $PIPE & systemd-cat -t "$progname" < $PIPE &
exec 3>$PIPE exec 3>$PIPE
donotify=0 donotify=0
@@ -49,7 +49,7 @@ notify() {
for u in $(users | sed 's/ /\n/' | sort -u); do for u in $(users | sed 's/ /\n/' | sort -u); do
sudo -u $u DISPLAY=:0 \ sudo -u $u DISPLAY=:0 \
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus \ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus \
notify-send -a $name "$1" "$2" --icon="dialog-$3" notify-send -a $progname "$1" "$2" --icon="dialog-$3"
done done
} }
@@ -84,7 +84,7 @@ traperror() {
printf "exit status: %s\n" "$2" printf "exit status: %s\n" "$2"
printf "command: %s\n" "$3" printf "command: %s\n" "$3"
printf "bash line: %s\n" "$4" printf "bash line: %s\n" "$4"
printf "function name: %s\n" "$5" printf "function progname: %s\n" "$5"
exit 1 exit 1
} }
@@ -92,13 +92,13 @@ trapkill() {
die "Exited due to user intervention." die "Exited due to user intervention."
} }
trap 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCNAME[@]}"' ERR trap 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCPROGNAME[@]}"' ERR
trap trapkill SIGTERM SIGINT trap trapkill SIGTERM SIGINT
usage() { usage() {
cat <<EOF cat <<EOF
$name $version $progname $version
Usage: $name [options] Usage: $progname [options]
Options: Options:
-d, --description <desc> Change the snapper description. Default: "latest incremental backup" -d, --description <desc> Change the snapper description. Default: "latest incremental backup"
@@ -110,7 +110,7 @@ Options:
-u, --UUID <UUID> Specify the UUID of the mounted BTRFS subvolume to back up to. Otherwise will prompt. -u, --UUID <UUID> Specify the UUID of the mounted BTRFS subvolume to back up to. Otherwise will prompt.
If multiple mount points are found with the same UUID, will prompt user. If multiple mount points are found with the same UUID, will prompt user.
-s, --subvolid <subvlid> Specify the subvolume id of the mounted BTRFS subvolume to back up to. Defaults to 5. -s, --subvolid <subvlid> Specify the subvolume id of the mounted BTRFS subvolume to back up to. Defaults to 5.
--remote <address> Send the snapshot backup to a remote machine. The snapshot will be sent via ssh. You --remote <address> Send the snapshot backup to a remote machine. The snapshot will be sent via ssh. You
should specify the remote machine's hostname or ip address. The 'root' user must be should specify the remote machine's hostname or ip address. The 'root' user must be
permitted to login on the remote machine. permitted to login on the remote machine.
EOF EOF
@@ -151,7 +151,7 @@ while [[ $# -gt 0 ]]; do
shift 2 shift 2
;; ;;
*) *)
die "Unknown option: $key\nRun '$name -h' for valid options.\n" die "Unknown option: $key\nRun '$progname -h' for valid options.\n"
;; ;;
esac esac
done done
@@ -280,8 +280,8 @@ for x in $selected_configs; do
continue continue
fi fi
if [[ "$(snapper -c $x list -t single | awk '/'$name' backup in progress/ {cnt++} END {print cnt}')" -gt 0 ]]; then if [[ "$(snapper -c $x list -t single | awk '/'$progname' backup in progress/ {cnt++} END {print cnt}')" -gt 0 ]]; then
printf "\nNOTE: Previous failed %s backup snapshots found for '%s'.\n" "$name" "$x" | tee $PIPE printf "\nNOTE: Previous failed %s backup snapshots found for '%s'.\n" "$progname" "$x" | tee $PIPE
read -r -p "Delete failed backup snapshots [y/N]? " delete_failed read -r -p "Delete failed backup snapshots [y/N]? " delete_failed
while [[ -n "$delete_failed" && "$delete_failed" != [Yy]"es" && while [[ -n "$delete_failed" && "$delete_failed" != [Yy]"es" &&
"$delete_failed" != [Yy] && "$delete_failed" != [Nn]"o" && "$delete_failed" != [Yy] && "$delete_failed" != [Nn]"o" &&
@@ -294,7 +294,7 @@ for x in $selected_configs; do
fi fi
done done
if [[ "$delete_failed" == [Yy]"es" || "$delete_failed" == [Yy] ]]; then if [[ "$delete_failed" == [Yy]"es" || "$delete_failed" == [Yy] ]]; then
snapper -c $x delete $(snapper -c $x list | awk '/'$name' backup in progress/ {print $3}') snapper -c $x delete $(snapper -c $x list | awk '/'$progname' backup in progress/ {print $3}')
fi fi
fi fi
@@ -333,7 +333,7 @@ for x in $selected_configs; do
MYBACKUPDIR_ARRAY[$i]="$mybackupdir" MYBACKUPDIR_ARRAY[$i]="$mybackupdir"
printf "Creating new snapshot for %s...\n" "$x" | tee $PIPE printf "Creating new snapshot for %s...\n" "$x" | tee $PIPE
new_num=$(snapper -c "$x" create --print-number -d "$name backup in progress") new_num=$(snapper -c "$x" create --print-number -d "$progname backup in progress")
new_snap=$SUBVOLUME/.snapshots/$new_num/snapshot new_snap=$SUBVOLUME/.snapshots/$new_num/snapshot
new_info=$SUBVOLUME/.snapshots/$new_num/info.xml new_info=$SUBVOLUME/.snapshots/$new_num/info.xml
sync sync