Skip to content

Commit

Permalink
Change | tee $PIPE to > $PIPE
Browse files Browse the repository at this point in the history
Remove duplication of logs.

Fixes #101.
  • Loading branch information
wesbarnett committed Feb 7, 2021
1 parent 276e177 commit 2f3470c
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions bin/snap-sync
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ fi
selected_subvolid="${SUBVOLIDS_ARRAY[$((disk))]}"
selected_uuid="${UUIDS_ARRAY[$((disk))]}"
selected_mnt="${TARGETS_ARRAY[$((disk))]}"
printf "\nYou selected the disk with uuid=%s, subvolid=%s.\n" "$selected_uuid" "$selected_subvolid" | tee $PIPE
printf "\nYou selected the disk with uuid=%s, subvolid=%s.\n" "$selected_uuid" "$selected_subvolid" > $PIPE
if [[ -z $ssh ]]; then
printf "The disk is mounted at '%s'.\n" "$selected_mnt" | tee $PIPE
printf "The disk is mounted at '%s'.\n" "$selected_mnt" > $PIPE
else
printf "The disk is mounted at '%s:%s'.\n" "$remote" "$selected_mnt" | tee $PIPE
printf "The disk is mounted at '%s:%s'.\n" "$remote" "$selected_mnt" > $PIPE
fi

source $SNAPPER_CONFIG
Expand Down Expand Up @@ -318,9 +318,9 @@ for x in $selected_configs; do
fi

if [[ "$(snapper -c $x list -t single | awk '/'$name' 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" "$name" "$x" > $PIPE
if [[ $noconfirm == "yes" ]]; then
printf "'noconfirm' option passed. Failed backups will not be deleted.\n" | tee $PIPE
printf "'noconfirm' option passed. Failed backups will not be deleted.\n" > $PIPE
else
read -e -r -p "Delete failed backup snapshot(s)? (These local snapshots from failed backups are not used.) [y/N]? " delete_failed
while [[ -n "$delete_failed" && "$delete_failed" != [Yy]"es" &&
Expand Down Expand Up @@ -373,21 +373,21 @@ for x in $selected_configs; do
BACKUPDIRS_ARRAY[$i]="$BACKUPDIR"
MYBACKUPDIR_ARRAY[$i]="$mybackupdir"

printf "Creating new local snapshot for '%s' configuration...\n" "$x" | tee $PIPE
printf "Creating new local snapshot for '%s' configuration...\n" "$x" > $PIPE
new_num=$(snapper -c "$x" create --print-number -d "$name backup in progress")
new_snap=$SUBVOLUME/.snapshots/$new_num/snapshot
new_info=$SUBVOLUME/.snapshots/$new_num/info.xml
sync
backup_location=$BACKUPDIR/$x/$new_num/
if [[ -z $ssh ]]; then
printf "Will backup %s to %s\n" "$new_snap" "$backup_location/snapshot" | tee $PIPE
printf "Will backup %s to %s\n" "$new_snap" "$backup_location/snapshot" > $PIPE
else
printf "Will backup %s to %s\n" "$new_snap" "$remote":"$backup_location/snapshot" | tee $PIPE
printf "Will backup %s to %s\n" "$new_snap" "$remote":"$backup_location/snapshot" > $PIPE
fi

if ($ssh test -d "$backup_location/snapshot") ; then
printf "WARNING: Backup directory '%s' already exists. This configuration will be skipped!\n" "$backup_location/snapshot" | tee $PIPE
printf "Move or delete destination directory and try backup again.\n" | tee $PIPE
printf "WARNING: Backup directory '%s' already exists. This configuration will be skipped!\n" "$backup_location/snapshot" > $PIPE
printf "Move or delete destination directory and try backup again.\n" > $PIPE
fi

NEW_NUM_ARRAY[$i]="$new_num"
Expand Down Expand Up @@ -423,7 +423,7 @@ for x in $selected_configs; do
done

# Actual backing up
printf "\nPerforming backups...\n" | tee $PIPE
printf "\nPerforming backups...\n" > $PIPE
i=-1
for x in $selected_configs; do

Expand Down Expand Up @@ -457,22 +457,22 @@ for x in $selected_configs; do
backup_location="${BACKUPLOC_ARRAY[$i]}"

if ($ssh test -d "$backup_location/snapshot") ; then
printf "ERROR: Backup directory '%s' already exists. Skipping backup of this configuration!\n" "$backup_location/snapshot" | tee $PIPE
printf "ERROR: Backup directory '%s' already exists. Skipping backup of this configuration!\n" "$backup_location/snapshot" > $PIPE
continue
fi

$ssh mkdir -p $backup_location

if [[ -z "$old_num" ]]; then
printf "Sending first snapshot for '%s' configuration...\n" "$x" | tee $PIPE
printf "Sending first snapshot for '%s' configuration...\n" "$x" > $PIPE
if [[ $doprogress -eq 0 ]]; then
btrfs send "$new_snap" | pv | $ssh btrfs receive "$backup_location" &>/dev/null
else
btrfs send "$new_snap" | $ssh btrfs receive "$backup_location" &>/dev/null
fi
else

printf "Sending incremental snapshot for '%s' configuration...\n" "$x" | tee $PIPE
printf "Sending incremental snapshot for '%s' configuration...\n" "$x" > $PIPE
# 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
Expand All @@ -485,10 +485,10 @@ for x in $selected_configs; do
fi

if [[ $keep == "yes" ]]; then
printf "Modifying data for old local snapshot for '%s' configuration...\n" "$x" | tee $PIPE
printf "Modifying data for old local snapshot for '%s' configuration...\n" "$x" > $PIPE
snapper -v -c "$x" modify -d "old snap-sync snapshot (you may remove)" -u "backupdir=,subvolid=,uuid=" -c "number" "$old_num"
else
printf "Deleting old snapshot for %s...\n" "$x" | tee $PIPE
printf "Deleting old snapshot for %s...\n" "$x" > $PIPE
snapper -c "$x" delete "$old_num"
fi

Expand All @@ -510,14 +510,14 @@ for x in $selected_configs; do
userdata="backupdir=$mybackupdir, subvolid=$selected_subvolid, uuid=$selected_uuid"

# Tag new snapshot as the latest
printf "Tagging local snapshot as latest backup for '%s' configuration...\n" "$x" | tee $PIPE
printf "Tagging local snapshot as latest backup for '%s' configuration...\n" "$x" > $PIPE
snapper -v -c "$x" modify -d "$description" -u "$userdata" "$new_num"

printf "Backup complete for '%s' configuration.\n" "$x" > $PIPE

done

printf "\nDone!\n" | tee $PIPE
printf "\nDone!\n" > $PIPE
exec 3>&-

if [[ "$uuid_cmdline" != "none" ]]; then
Expand Down

0 comments on commit 2f3470c

Please sign in to comment.