diff --git a/bin/snap-sync b/bin/snap-sync index 0fd596f..5cbfc2f 100755 --- a/bin/snap-sync +++ b/bin/snap-sync @@ -64,12 +64,6 @@ fi # It's important not to change this userdata in the snapshots, since that's how # we find the previous one. -TMPDIR=$(mktemp -d) -PIPE=$TMPDIR/snap-sync.out -mkfifo $PIPE -systemd-cat -t "snap-sync" < $PIPE & -exec 3>$PIPE - TARGETS="$(findmnt -n -v -t btrfs -o TARGET --list)" UUIDS="$(findmnt -n -v -t btrfs -o UUID --list)" @@ -120,13 +114,13 @@ fi selected_uuid="${UUIDS_ARRAY[$((disk))]}" selected_mnt="${TARGETS_ARRAY[$((disk))]}" -printf "\nYou selected the disk with UUID %s.\n" "$selected_uuid" | tee $PIPE -printf "The disk is mounted at %s.\n" "$selected_mnt" | tee $PIPE +printf "\nYou selected the disk with UUID %s.\n" "$selected_uuid" +printf "The disk is mounted at %s.\n" "$selected_mnt" if [[ -f /etc/conf.d/snapper ]]; then source /etc/conf.d/snapper else - printf "ERROR: /etc/conf.d/snapper does not exist!\n" | tee $PIPE + printf "ERROR: /etc/conf.d/snapper does not exist!\n" exit 1 fi @@ -161,7 +155,7 @@ for x in $selected_configs; do mybackupdir=$(snapper -c root list -t single | awk -F"|" '/'"$selected_uuid"'/ {print $5}' | awk -F "," '/backupdir/ {print $1}' | awk -F"=" '{print $2}') BACKUPDIR="$selected_mnt/$mybackupdir" if [[ ! -d $BACKUPDIR ]]; then - printf "ERROR: %s is not a directory on %s.\n" "$BACKUPDIR" "$selected_uuid" | tee $PIPE + printf "ERROR: %s is not a directory on %s.\n" "$BACKUPDIR" "$selected_uuid" exit 1 fi fi @@ -173,7 +167,7 @@ done for x in $selected_configs; do if [[ "$(sudo snapper -c root list -t single | awk '/snap-sync backup in progress/ {cnt++} END {print cnt}')" -gt 0 ]]; then - printf "Note: Previous failed snap-sync backup snapshots found for '$x'.\n" | tee $PIPE + printf "Note: Previous failed snap-sync backup snapshots found for '$x'.\n" fi SNAP_SYNC_EXCLUDE=no @@ -196,13 +190,13 @@ for x in $selected_configs; do BACKUPDIR="${BACKUPDIRS_ARRAY[$x]}" - printf "Creating new snapshot for $x...\n" | tee $PIPE + printf "Creating new snapshot for $x...\n" new_number=$(snapper -c "$x" create --print-number -d "snap-sync backup in progress") new_snapshot=$SUBVOLUME/.snapshots/$new_number/snapshot new_info=$SUBVOLUME/.snapshots/$new_number/info.xml sync backup_location=$BACKUPDIR/$x/$new_number/ - printf "Will backup %s to %s\n" "$new_snapshot" "$backup_location/snapshot" | tee $PIPE + printf "Will backup %s to %s\n" "$new_snapshot" "$backup_location/snapshot" cont_backup="" if [[ $noconfirm == "yes" ]]; then @@ -227,18 +221,18 @@ for x in $selected_configs; do if [[ -z "$old_num" ]]; then - printf "Sending first snapshot for %s...\n" "$x" | tee $PIPE + printf "Sending first snapshot for %s...\n" "$x" btrfs send "$new_snapshot" | btrfs receive "$backup_location" &>/dev/null else - printf "Sending incremental snapshot for %s...\n" "$x" | tee $PIPE + printf "Sending incremental snapshot for %s...\n" "$x" # 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_snap" | btrfs receive "$backup_location" &>/dev/null - printf "Deleting old snapshot for $x...\n" | tee $PIPE + printf "Deleting old snapshot for $x...\n" snapper -c "$x" delete "$old_num" fi @@ -247,12 +241,12 @@ for x in $selected_configs; do userdata="backupdir=$mybackupdir, uuid=$selected_uuid" # Tag new snapshot as the latest - printf "Tagging new snapshot as latest backup for $x...\n" | tee $PIPE + printf "Tagging new snapshot as latest backup for $x...\n" snapper -v -c "$x" modify -d "$description" -u "$userdata" "$new_number" - printf "Backup complete for configuration %s.\n" "$x" > $PIPE + printf "Backup complete for configuration %s.\n" "$x" done -printf "\nDone!\n" | tee $PIPE +printf "\nDone!\n" exec 3>&-