]> wagner.pp.ru Git - oss/restore.git/commitdiff
Use content of disk_id file for notification
authorVictor Wagner <vitus@wagner.pp.ru>
Wed, 29 Oct 2025 17:40:28 +0000 (20:40 +0300)
committerVictor Wagner <vitus@wagner.pp.ru>
Wed, 29 Oct 2025 17:40:28 +0000 (20:40 +0300)
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
backup

index fe22565887a7a05b193f00edf024da7397297164..58774069f08db7f87d8f6607975e062feca8e76a 100755 (executable)
@@ -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 84c1d894f5327544c8d01341e2aac19604565d93..fad452ecbc3f6b1753bf9be895b71577cbbf49f6 100755 (executable)
--- 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);
+}
+
+