[savepoint]
authorHeiko Schlittermann <hs@schlittermann.de>
Fri, 15 Jan 2010 23:17:23 +0100
changeset 6 df6ca24871d4
parent 3 1b975c58c5bf
child 7 03ca6d811a17
[savepoint]
SI/blkid.pm
SI/lvm.pm
SI/mbr.pm
SI/ptable.pm
si
--- a/SI/blkid.pm	Fri Jan 15 20:40:14 2010 +0100
+++ b/SI/blkid.pm	Fri Jan 15 23:17:23 2010 +0100
@@ -4,21 +4,9 @@
 use warnings;
 use File::Find;
 
-sub ff($$) {
-    my ($dir, $id) = @_;
-    my $found;
-    find(
-        sub {
-            return if $found;
-            $found = (stat)[6] == $id ? $File::Find::name : undef;
-            return;
-        },
-        $dir
-    );
-    return $found;
-}
+sub ff($$);
 
-sub info($\%) {
+sub save($\%) {
     my ($file, $part) = @_;
 
     foreach (`blkid -c /dev/null`) {
@@ -47,5 +35,19 @@
     }
 }
 
+sub ff($$) {
+    my ($dir, $id) = @_;
+    my $found;
+    find(
+        sub {
+            return if $found;
+            $found = (stat)[6] == $id ? $File::Find::name : undef;
+            return;
+        },
+        $dir
+    );
+    return $found;
+}
+
 1;
 # vim:sts=4 sw=4 aw ai si:
--- a/SI/lvm.pm	Fri Jan 15 20:40:14 2010 +0100
+++ b/SI/lvm.pm	Fri Jan 15 23:17:23 2010 +0100
@@ -4,7 +4,7 @@
 use warnings;
 use SI::tools;
 
-sub vg_info($\%) {
+sub vgcfgbackup($\%) {
     my ($file, $part) = @_;
     foreach (map { (split /:/)[0] }
         map { /^\s*(.*)/; } `vgs --noheadings --separator :`)
@@ -14,19 +14,5 @@
     }
 }
 
-sub lv_info($\%) {
-    my ($file, $part) = @_;
-
-    foreach my $p (keys %$part) {
-        `pvs -o +uuid --nameprefix --noheadings $p` =~ /\bLVM2_PV_UUID='(.*?)'/
-          or next;
-
-        $part->{$p}{type} = "pv";
-        $part->{$p}{uuid} = $1;
-
-    }
-
-}
-
 1;
 # vim:sts=4 sw=4 aw ai si:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SI/mbr.pm	Fri Jan 15 23:17:23 2010 +0100
@@ -0,0 +1,21 @@
+package SI::mbr;
+
+use strict;
+use warnings;
+use File::Basename;
+use if $ENV{DEBUG} ~~ q(mbr) => "Smart::Comments";
+
+sub save($\%) {
+	my ($file, $devices) = @_;
+	
+
+	foreach my $disk (keys %{$devices->{disks}}) {
+		open((my $o), $_ = sprintf(">$file", basename($disk))) or die "Can't open $_: $!\n";
+		local $/ = \512;
+
+		open(my $in, $disk) or die "Can't open $disk: $!\n";
+		print $o $_ = <$in>;
+	}
+}
+
+1;
--- a/SI/ptable.pm	Fri Jan 15 20:40:14 2010 +0100
+++ b/SI/ptable.pm	Fri Jan 15 23:17:23 2010 +0100
@@ -9,10 +9,10 @@
 
 use SI::tools;
 
-sub info($\%) {
+sub save($\%) {
     my ($file, $part) = @_;
 
-    # find major of devmapper
+    # find the major number of the devmapper
     my $devmapper = 0;
     {
         local $/ = undef;
@@ -21,20 +21,27 @@
         ($devmapper) = <$i> =~ /^\s*(\d+)\s+device.mapper\b/m;
     }
 
+    # find the non-removable devices, store their
+    # names as $part->{disks}{DEVICE}
+    # and save the current sfdisk dump of these devices
+    # in @{$dev{DEVICE}}
     my ($current, %dev);
     foreach (`sfdisk -d 2>/dev/null`) {
         chomp;
-        ### $_
-        if (/^# partition table .*?(\/\S+)/) {
-            $current = (stat $1)[6] >> 8 == $devmapper ? undef : $1
-              and push(@{ $dev{$current} }, $_);
-            next;
+        if (/^# partition table .*?(\/\S+\/(\S+))/) {
+	    # skip the removable devices
+	    my ($device, $name) = ($1, $2);
+	    $_ = (grep { /ATTR{removable}/ } `udevadm info --attribute-walk --name $name`)[0];
+	    $current = /==.0./ ? $device : undef;
+	    $part->{disks}{$current} = undef if $current;
+	    next;
         }
         next if not $current;
         push @{ $dev{$current} }, $_;
     }
-    ### partiton tables of useful blockdevices:
+
     ### %dev
+### exit
 
     # process the partition tables
     # and output the tables for relevant devices
--- a/si	Fri Jan 15 20:40:14 2010 +0100
+++ b/si	Fri Jan 15 23:17:23 2010 +0100
@@ -5,20 +5,24 @@
 use warnings;
 use if $ENV{DEBUG} => "Smart::Comments";
 
+use Sys::Hostname;
+
 use SI::ptable;
 use SI::blkid;
 use SI::lvm;
+use SI::mbr;
 
-my $OUT = "out";
+my $OUT = "../out-" . hostname;
 
 unlink(glob("$OUT/*"));
 -d $OUT or mkdir($OUT, 0700) or die "Can't mkdir $OUT: $!\n";
 
 my %devices;
 
-SI::ptable::info("$OUT/partitions.%s", %devices);
-SI::blkid::info("$OUT/blkid", %devices);
-SI::lvm::vg_info("$OUT/vg.%s", %devices);
+SI::ptable::save("$OUT/partitions.%s", %devices);
+SI::blkid::save("$OUT/blkid", %devices);
+SI::lvm::vgcfgbackup("$OUT/vg.%s", %devices);
+SI::mbr::save("$OUT/mbr.%s", %devices);
 
 ### %devices;