From cdcd5490b4ab8c0207541318c3d9d922dc04fdbe Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Wed, 29 Oct 2025 20:40:28 +0300 Subject: [PATCH] Use content of disk_id file for notification If there is disk_id file in the root direcctory of backup media, use its content in the messages displayed in dialog windows and send to messenger --- aftermount | 10 ++++++++-- backup | 25 ++++++++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/aftermount b/aftermount index fe22565..5877406 100755 --- a/aftermount +++ b/aftermount @@ -32,7 +32,11 @@ grep -q "^snapshot_root $mountpoint" /etc/rsnapshot.conf || exit 0 eval "$(df -H "$mountpoint"|awk 'NR>1 {printf "dev=%s\nsize=%s\nfree=%s\nmp=%s",$1,$2,$4,$6;}')" -message="Backup media inserted into $dev\nTotal space $size\nFree space=$free\n. Would you like to start backup?" +disk_id="" +[ -f "$mountpoint/disk_id" ] && disk_id=$(cat "${mountpoint}/disk_id") + +message="Backup media ${disk_id} inserted into $dev\nTotal space $size\nFree space=$free\n. Would you like to start backup?" + if command -v spacefm; then iface=spacefm @@ -40,10 +44,12 @@ else iface=zenity fi + ${iface}_dialog "Backup media inserted" "$message" || exit 0 + if sudo $BACKUP; then - ${iface}_monolog "Backup successful" "Backup finished successfully" info + ${iface}_monolog "Backup successful" "Backup to disk $disk_id finished successfully" info else ${iface}_monolog "Backup failed" "Backup finished with errors. See logs" error exit 1 diff --git a/backup b/backup index 84c1d89..fad452e 100755 --- a/backup +++ b/backup @@ -69,6 +69,13 @@ pop @levels; die "No backup media mounted on $snapshot_root\n" unless -d $snapshot_root; # Now we have following triples: # "level,number,nextlevel" +my ($device, $rootpath) = get_fs($snapshot_root); +my $disk_id=""; +if ( -f "$rootpath/disk_id" ) { + open my $f,"<","$rootpath/disk_id"; + $disk_id=<$f>; + chomp $disk_id; +} my $level; LEVEL: while (@levels) { @@ -92,12 +99,11 @@ while (@levels) { open my $stamp, ">>","$snapshot_root/${nextlevel}-stamp"; close $stamp; } + run_rsnapshot($level); -notify("Backup completed successfully\n"); +notify("Backup to disk $disk_id completed successfully\n"); # Размонтируем файловую систему, содержащую snapshot_root -my @lines = `df $snapshot_root`; -my @line = split(/\s+/,pop @lines); -my $device = shift @line; + $device =~ s/\d$//; # remove partition number open my $mount,"mount|" or die "Cannot execute mount:$!"; my @to_umount=(); @@ -123,7 +129,7 @@ sub run_rsnapshot { print STDERR "running rsnapshot $level\n"; my $status= system("rsnapshot",$level) >> 8; if ($status) { - notify("rsapshot $level finished with code $status\n"); + notify("rsapshot $level on disk $disk_id finished with code $status\n"); exit $status; } } @@ -138,3 +144,12 @@ sub notify { close $pipe; } } + +sub get_fs { + # returns pair device, mountpoint for fs containing giv en path + my $path = $_[0]; + my @line = split(/\s+/, (`df $path`)[1]); + return (shift @line, pop @line); +} + + -- 2.47.3