From b735fd32081b00b0c94196cf77c9b465703d8da5 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Sat, 2 Jun 2007 17:14:13 -0700 Subject: [PATCH] Add version information to the backup descriptor files. This adds a "Format:" line at the start of a backup descriptor, with the intent that different formats can be recognized if there is a need to make changes in the future. This can also be used as a magic number to identify LBS snapshot files. Also, update the restore.pl script to handle the new format--make the parser more flexible so that fields can appear in any order, and unrecognized lines are ignored. --- restore.pl | 30 ++++++++++++++++++++++++++---- scandir.cc | 1 + 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/restore.pl b/restore.pl index 53b48dc..3a600b1 100755 --- a/restore.pl +++ b/restore.pl @@ -374,14 +374,36 @@ if (defined($ARGV[1])) { $OBJECT_DIR = dirname($descriptor); print "Source directory: $OBJECT_DIR\n" if $VERBOSE; -# Read the snapshot descriptor to find the root object. +# Read the snapshot descriptor to find the root object. Parse it to get a set +# of key/value pairs. open DESCRIPTOR, "<", $descriptor or die "Cannot open backup descriptor file $descriptor: $!"; -my $line = ; -if ($line !~ m/^Root: (\S+)$/) { +my %descriptor = (); +my ($line, $last_key); +while (defined($line = )) { + # Any lines of the form "key: value" should be inserted into the + # %descriptor dictionary. Any continuation line (a line starting with + # whitespace) will append text to the previous key's value. Ignore other + # lines. + chomp $line; + + if ($line =~ m/^(\w+):\s*(.*)$/) { + $descriptor{$1} = $2; + $last_key = $1; + } elsif ($line =~/^\s/ && defined $last_key) { + $descriptor{$last_key} .= $line; + } else { + undef $last_key; + print STDERR "Ignoring line in backup descriptor: $line\n"; + } +} + +# A valid backup descriptor should at the very least specify the root metadata +# object. +if (!exists $descriptor{Root}) { die "Expected 'Root:' specification in backup descriptor file"; } -my $root = $1; +my $root = $descriptor{Root}; close DESCRIPTOR; # Set the umask to something restrictive. As we unpack files, we'll originally diff --git a/scandir.cc b/scandir.cc index 64a0dbf..bf4a583 100644 --- a/scandir.cc +++ b/scandir.cc @@ -485,6 +485,7 @@ int main(int argc, char *argv[]) root->checksum(); segment_list.insert(root->get_ref().get_segment()); + descriptor << "Format: LBS Snapshot v0.1\n"; descriptor << "Root: " << root->get_ref().to_string() << "\n"; strftime(desc_buf, sizeof(desc_buf), "%Y-%m-%d %H:%M:%S %z", &time_buf); descriptor << "Date: " << desc_buf << "\n"; -- 2.20.1