changeset 10:4417be0e2f07

adapted to dsmc's problem with mount points saves index.meta from overwriting by archived version
author casties
date Fri, 21 Jan 2005 15:33:26 +0100
parents 9c61f624d802
children b19df18aa19a
files MPIWGStor.pm unarchiver.pl
diffstat 2 files changed, 100 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/MPIWGStor.pm	Tue Nov 30 13:39:51 2004 +0100
+++ b/MPIWGStor.pm	Fri Jan 21 15:33:26 2005 +0100
@@ -13,14 +13,14 @@
 	    $file_perm);
 use Exporter;
 
-$VERSION = 0.3; #  ROC 24.9.2003
+$VERSION = 0.4; #  ROC 20.1.2005
 
 @ISA = qw(Exporter);
 
 @EXPORT = qw($debug %junk_files %index_files $index_file_perm $archived_index_file_perm 
 	     $file_perm
 	     &parseargs &logger &stime  &s2stime &ymd_date &split_file_path &sstrip 
-	     &valid_file_name &valid_dir_name &read_xml &write_xml);
+	     &valid_file_name &valid_dir_name &park_file &unpark_file &read_xml &write_xml);
 
 # debug level
 $debug = 0;
@@ -211,6 +211,44 @@
 
 
 #
+# $newfilename = park_file($filename)
+#
+# parks a file under a new name (*.bak)
+#
+sub park_file {
+    my ($filename) = @_;
+    my $newfn = "";
+    if (-f $filename) {
+	$newfn = "$filename.bak";
+	if (! rename $filename, $newfn) {
+	    logger("ABORT", "unable to rename file $filename!");
+	    exit 1;
+	}
+    }
+    return $newfn;
+}
+    
+#
+# $filename = unpark_file($filename)
+#
+# unparks a file
+#
+sub unpark_file {
+    my ($filename) = @_;
+    my $newfn = "$filename.bak";
+    if (-f $newfn) {
+	if (! rename $newfn, $filename) {
+	    logger("ABORT", "unable to rename file $newfn!");
+	    exit 1;
+	}
+	return $filename;
+    }
+    return "";
+}
+    
+
+
+#
 # ($document, $rootnode) = read_xml($file)
 #
 # reads xml meta file $file
--- a/unarchiver.pl	Tue Nov 30 13:39:51 2004 +0100
+++ b/unarchiver.pl	Fri Jan 21 15:33:26 2005 +0100
@@ -18,7 +18,7 @@
 #
 
 # program version
-my $version = "0.2 (23.9.2004)";
+my $version = "0.3 (20.1.2004)";
 
 # read command line parameters
 my $args = parseargs;
@@ -79,10 +79,6 @@
     exit 1;
 }
 
-# construct document's parent dir
-my $docparent = $docdir;
-$docparent =~ s!/[^/]+$!!;
-
 #######################################################
 # internal variables
 #
@@ -96,6 +92,14 @@
 # subroutines
 #
 
+# construct document's parent dir
+sub get_parent {
+    my ($dirname) = @_;
+    my $dirparent = $dirname;
+    $dirparent =~ s!/[^/]+$!!;
+    return $dirparent;
+}
+
 
 #
 # $files = read_resource_meta($rootnode)
@@ -172,23 +176,36 @@
 
 
 #
-# $%files = run_retrieve
+# $num_files = run_retrieve($docdir, $docmount, \%files)
 #
-# runs the retriever program on $docdir and returns a list of archived files
+# Runs the retriever program on $docdir and returns the number of unarchived files.
+# All filenames are put in %files. 
+# $docmount is the mount point of the doc partition in cases when the new mount point
+# is different.
 #
 # Sample output:
 # (old!) Retrieving          17,234 /mpiwg/archive/data/test/auto_titit_123/pageimg/essen-wind1.jpg [Done]
 # Retrieving      42,406,326 /mpiwg/archive/data/library/B980G582/raw/00015.tif --> /mpiwg/archive/data/library/B980G582/raw/00015.tif [Done]
 sub run_retrieve {
-    my %files;
+    my ($archdir, $archmount, $files) = @_;
+    my $archparent;
+    if ($archmount eq $archdir) {
+	# no explicit mount point
+	$archparent = get_parent($archdir);
+    } else {
+	# destination dir is mount point
+	$archparent = $archmount;
+    }
+
     print LOG "START unarchive $version on ", scalar localtime, "\n";
     my $archcmd = $archprog;
     $archcmd .= " retrieve -subdir=yes -replace=all";
-    $archcmd .= " -description='$archname'";
-    $archcmd .= " '$docdir/'"; # archive name
-    $archcmd .= " '$docparent/'"; # destination dir name
+    $archcmd .= " -description='$archname'"; # archive name
+    $archcmd .= " '$archmount/'"; # archive mount point
+    $archcmd .= " '$archparent/'"; # destination dir name
 
     my $archcnt = 0;
+    my $numfiles = 0;
     print LOG "CMD: $archcmd\n";
     if (open ARCH, "$archcmd 2>&1 |") {
 	while (<ARCH>) {
@@ -207,19 +224,20 @@
 		$size =~ s/,//g;
 		logger("DEBUG", "  RETRIEVE: file '$file'");
 		$archcnt++;
-		if ($files{$file}) {
+		if ($$files{$file}) {
 		    logger("WARNING", "file $file seems to be archived multiple times.");
 		    $warncnt++;
 		} 
-		$files{$file} = [$size];
+		$$files{$file} = [$size];
 	    }
 	}
-	logger("INFO", "$archcnt archives of " . (scalar keys %files) . " files.");
+	$numfiles =  (scalar keys %$files);
+	logger("INFO", "$archcnt archives of $numfiles files (in $archmount).");
     } else {
 	logger("ABORT", "unable to start archive command '$archcmd'!!");
 	exit 1;
     }
-    return \%files;
+    return $numfiles;
 }
 
 
@@ -286,9 +304,9 @@
 
 # use checkarchive first
 if (system("$checkprog $docdir >/dev/null") == 0) {
-    logger("INFO", "archive '$docdir' check OK");
+    logger("INFO", "archive \"$docdir\" check OK");
 } else {
-    logger("ABORT", "archive '$docdir' check failed!!");
+    logger("ABORT", "archive \"$docdir\" check failed!!");
     exit 1;
 }
 
@@ -309,18 +327,37 @@
 
 logger("INFO", "$num_archived_files files to retrieve.");
 
+# save current index.meta
+park_file($metafile); 
+
 # retrieve
-my $retrieved_files = run_retrieve;
+my %retrieved_files = ();
+my $archcnt = 0;
 
-my $num_arch_files = (scalar keys %$retrieved_files);
-if ($num_arch_files == 0) {
+if ($docdir =~ /\/mpiwg\/archive\/data\/(.*)/) {
+    # TSM needs two different paths because of historical mount points :-(
+    # try the new one first
+    $archcnt = run_retrieve($docdir, "/mpiwg/archive", \%retrieved_files);
+    if ($archcnt == 0) {
+	# and then the old one
+	$archcnt = run_retrieve($docdir, "/mpiwg/archive/data", \%retrieved_files);
+    }
+} else {
+    # otherwise we assume that it works
+    $archcnt += run_retrieve($docdir, $docdir, \%retrieved_files);
+}
+
+# restore current index.meta
+unpark_file($metafile);
+
+if ($archcnt == 0) {
     logger("ABORT", "no files retrieved!!");
     exit 1;
 }
-logger("INFO", "$num_arch_files files retrieved");
+logger("INFO", "$archcnt files retrieved");
 
 # check list of archived files
-check_files($archived_files, $retrieved_files);
+check_files($archived_files, \%retrieved_files);
 
 # rewrite index.meta file
 write_xml($document, $metafile);
@@ -328,7 +365,7 @@
 logger("INFO", "$warncnt warnings");
 logger("INFO", "$errcnt errors");
 if ($errcnt == 0) {
-    logger("DONE", "" . (scalar keys %$retrieved_files) . " archived files retrieved");
+    logger("DONE", "$archcnt archived files retrieved");
 } else {
     logger("ABORT", "there were $errcnt errors!!");
     exit 1;