X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=restore.pl;h=be94078f7fe869cc5080160e9549eab53c29c901;hb=da87780779a2f165503d019ee0b59d10e5d31ec8;hp=9ba3a067de89a853936f23fc1f8123e3fef3236d;hpb=7a8869315b6b7cfa35eaf38b4af6a6f41713024c;p=cumulus.git diff --git a/restore.pl b/restore.pl index 9ba3a06..be94078 100755 --- a/restore.pl +++ b/restore.pl @@ -25,6 +25,8 @@ my $OBJECT_DIR; # Where are the unpacked objects available? my $DEST_DIR = "."; # Where should restored files should be placed? my $RECURSION_LIMIT = 3; # Bound on recursive object references +my $VERBOSE = 0; # Set to 1 to enable debugging messages + ############################ CHECKSUM VERIFICATION ############################ # A very simple later for verifying checksums. Checksums may be used on object # references directly, and can also be used to verify entire reconstructed @@ -69,7 +71,7 @@ sub verifier_check { my $digester = $verifier->{DIGESTER}; my $newhash = $digester->hexdigest(); - if ($verifier->{HASH} ne $newhash) { + if ($VERBOSE && $verifier->{HASH} ne $newhash) { print STDERR "Verification failure: ", $newhash, " != ", $verifier->{HASH}, "\n"; } @@ -225,7 +227,7 @@ sub process_file { my $type = $info{type}; my $filename = uri_decode($info{name}); - print "process_file: $filename\n"; + print "$filename\n" if $VERBOSE; # Restore the specified file. How to do so depends upon the file type, so # dispatch based on that. @@ -264,13 +266,14 @@ sub process_file { # Restore mode, ownership, and any other metadata for the file. This is # split out from the code above since the code is the same regardless of # file type. - my $atime = $info{atime} || time(); my $mtime = $info{mtime} || time(); - utime $atime, $mtime, $dest - or warn "Unable to update atime/mtime for $dest"; + utime time(), $mtime, $dest + or warn "Unable to update mtime for $dest"; - my $uid = $info{user} || -1; - my $gid = $info{group} || -1; + my $uid = -1; + my $gid = -1; + $uid = $info{user} + 0 if defined $info{user}; + $gid = $info{group} + 0 if defined $info{group}; chown $uid, $gid, $dest or warn "Unable to change ownership for $dest"; @@ -319,7 +322,7 @@ sub process_metadata { # Recursively handle indirect metadata blocks. if ($line =~ m/^@(\S+)$/) { - print "Indirect: $1\n"; + print "Indirect: $1\n" if $VERBOSE; my $indirect = load_ref($1); process_metadata($indirect, $recursion_level + 1); next; @@ -363,14 +366,14 @@ if (defined($ARGV[1])) { } $OBJECT_DIR = dirname($descriptor); -print "Source directory: $OBJECT_DIR\n"; +print "Source directory: $OBJECT_DIR\n" if $VERBOSE; # Read the snapshot descriptor to find the root object. open DESCRIPTOR, "<", $descriptor or die "Cannot open backup descriptor file $descriptor: $!"; my $line = ; -if ($line !~ m/^root: (\S+)$/) { - die "Expected 'root:' specification in backup descriptor file"; +if ($line !~ m/^Root: (\S+)$/) { + die "Expected 'Root:' specification in backup descriptor file"; } my $root = $1; close DESCRIPTOR; @@ -382,6 +385,6 @@ close DESCRIPTOR; umask 077; # Start processing metadata stored in the root to recreate the files. -print "Root object: $root\n"; +print "Root object: $root\n" if $VERBOSE; my $contents = load_ref($root); process_metadata($contents);