Skip to content

Commit 77a6a23

Browse files
authored
Merge pull request #2 from qubidt/fix/duplogs
2 parents a42f661 + fe4370f commit 77a6a23

1 file changed

Lines changed: 19 additions & 26 deletions

File tree

bin/snap-sync

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ printf "snap-sync comes with ABSOLUTELY NO WARRANTY. This is free software, and
3636
# find_snapper_config script
3737
SNAPPER_CONFIG=/etc/conf.d/snapper
3838

39-
TMPDIR=$(mktemp -d)
40-
PIPE=$TMPDIR/$name.out
41-
mkfifo "$PIPE"
42-
systemd-cat -t "$name" < "$PIPE" &
43-
exec 3>"$PIPE"
44-
4539
donotify=0
4640
if ! which notify-send &> /dev/null; then
4741
donotify=1
@@ -282,11 +276,11 @@ fi
282276
selected_subvolid="${SUBVOLIDS_ARRAY[$((disk))]}"
283277
selected_uuid="${UUIDS_ARRAY[$((disk))]}"
284278
selected_mnt="${TARGETS_ARRAY[$((disk))]}"
285-
printf "\nYou selected the disk with uuid=%s, subvolid=%s.\n" "$selected_uuid" "$selected_subvolid" | tee "$PIPE"
279+
printf "\nYou selected the disk with uuid=%s, subvolid=%s.\n" "$selected_uuid" "$selected_subvolid"
286280
if [[ -z $ssh ]]; then
287-
printf "The disk is mounted at '%s'.\n" "$selected_mnt" | tee "$PIPE"
281+
printf "The disk is mounted at '%s'.\n" "$selected_mnt"
288282
else
289-
printf "The disk is mounted at '%s:%s'.\n" "$remote" "$selected_mnt" | tee "$PIPE"
283+
printf "The disk is mounted at '%s:%s'.\n" "$remote" "$selected_mnt"
290284
fi
291285

292286
# shellcheck source=/etc/conf.d/snapper
@@ -317,9 +311,9 @@ for x in $selected_configs; do
317311
fi
318312

319313
if [[ "$(snapper -c "$x" list -t single | awk '/'$name' backup in progress/ {cnt++} END {print cnt}')" -gt 0 ]]; then
320-
printf "\nNOTE: Previous failed %s backup snapshots found for '%s'.\n" "$name" "$x" | tee "$PIPE"
314+
printf "\nNOTE: Previous failed %s backup snapshots found for '%s'.\n" "$name" "$x"
321315
if [[ $noconfirm == "yes" ]]; then
322-
printf "'noconfirm' option passed. Failed backups will not be deleted.\n" | tee "$PIPE"
316+
printf "'noconfirm' option passed. Failed backups will not be deleted.\n"
323317
else
324318
read -e -r -p "Delete failed backup snapshot(s)? (These local snapshots from failed backups are not used.) [y/N]? " delete_failed
325319
while [[ -n "$delete_failed" && "$delete_failed" != [Yy]"es" &&
@@ -373,21 +367,21 @@ for x in $selected_configs; do
373367
BACKUPDIRS_ARRAY[$i]="$BACKUPDIR"
374368
MYBACKUPDIR_ARRAY[$i]="$mybackupdir"
375369

376-
printf "Creating new local snapshot for '%s' configuration...\n" "$x" | tee "$PIPE"
370+
printf "Creating new local snapshot for '%s' configuration...\n" "$x"
377371
new_num=$(snapper -c "$x" create --print-number -d "$name backup in progress")
378372
new_snap=$SUBVOLUME/.snapshots/$new_num/snapshot
379373
new_info=$SUBVOLUME/.snapshots/$new_num/info.xml
380374
sync
381375
backup_location=$BACKUPDIR/$x/$new_num/
382376
if [[ -z $ssh ]]; then
383-
printf "Will backup %s to %s\n" "$new_snap" "$backup_location/snapshot" | tee "$PIPE"
377+
printf "Will backup %s to %s\n" "$new_snap" "$backup_location/snapshot"
384378
else
385-
printf "Will backup %s to %s\n" "$new_snap" "$remote:$backup_location/snapshot" | tee "$PIPE"
379+
printf "Will backup %s to %s\n" "$new_snap" "$remote":"$backup_location/snapshot"
386380
fi
387381

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

393387
NEW_NUM_ARRAY[$i]="$new_num"
@@ -423,7 +417,7 @@ for x in $selected_configs; do
423417
done
424418

425419
# Actual backing up
426-
printf "\nPerforming backups...\n" | tee "$PIPE"
420+
printf "\nPerforming backups...\n"
427421
i=-1
428422
for x in $selected_configs; do
429423

@@ -458,22 +452,22 @@ for x in $selected_configs; do
458452
backup_location="${BACKUPLOC_ARRAY[$i]}"
459453

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

465459
$ssh mkdir -p "$backup_location"
466460

467461
if [[ -z "$old_num" ]]; then
468-
printf "Sending first snapshot for '%s' configuration...\n" "$x" | tee "$PIPE"
462+
printf "Sending first snapshot for '%s' configuration...\n" "$x"
469463
if [[ $doprogress -eq 0 ]]; then
470464
btrfs send "$new_snap" | pv | $ssh btrfs receive "$backup_location" &>/dev/null
471465
else
472466
btrfs send "$new_snap" | $ssh btrfs receive "$backup_location" &>/dev/null
473467
fi
474468
else
475469

476-
printf "Sending incremental snapshot for '%s' configuration...\n" "$x" | tee "$PIPE"
470+
printf "Sending incremental snapshot for '%s' configuration...\n" "$x"
477471
# Sends the difference between the new snapshot and old snapshot to the
478472
# backup location. Using the -c flag instead of -p tells it that there
479473
# is an identical subvolume to the old snapshot at the receiving
@@ -486,10 +480,10 @@ for x in $selected_configs; do
486480
fi
487481

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

@@ -511,15 +505,14 @@ for x in $selected_configs; do
511505
userdata="backupdir=$mybackupdir, subvolid=$selected_subvolid, uuid=$selected_uuid"
512506

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

517-
printf "Backup complete for '%s' configuration.\n" "$x" > "$PIPE"
511+
printf "Backup complete for '%s' configuration.\n" "$x"
518512

519513
done
520514

521-
printf "\nDone!\n" | tee "$PIPE"
522-
exec 3>&-
515+
printf "\nDone!\n"
523516

524517
if [[ "$uuid_cmdline" != "none" ]]; then
525518
notify_info "Finished" "Backups to $uuid_cmdline complete!"

0 commit comments

Comments
 (0)