X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=server-src%2Famrmtape.pl;h=27f6d1eafe27dad07ef716fde799361a16fd8a6e;hb=b116e9366c7b2ea2c2eb53b0a13df4090e176235;hp=05a1fb635d5e0e43035d6590447e1f2e4843b4f3;hpb=fd48f3e498442f0cbff5f3606c7c403d0566150e;p=debian%2Famanda diff --git a/server-src/amrmtape.pl b/server-src/amrmtape.pl index 05a1fb6..27f6d1e 100644 --- a/server-src/amrmtape.pl +++ b/server-src/amrmtape.pl @@ -33,6 +33,7 @@ use Amanda::MainLoop; use Amanda::Tapelist; use Amanda::Util qw( :constants ); use File::Copy; +use File::Basename; use Getopt::Long; my $amadmin = "$sbindir/amadmin"; @@ -176,28 +177,31 @@ if ($cfgerr_level >= $CFGERR_ERRORS) { my $scrub_db = sub { my $tapelist_file = config_dir_relative(getconf($CNF_TAPELIST)); - my $tapelist = Amanda::Tapelist::read_tapelist($tapelist_file); + my $tapelist = Amanda::Tapelist->new($tapelist_file, !$dry_run); unless ($tapelist) { die "Could not read the tapelist"; } + my $t = $tapelist->lookup_tapelabel($label); if ($keep_label) { - my $t = $tapelist->lookup_tapelabel($label); $t->{'datestamp'} = 0 if $t; + } elsif (!defined $t) { + print "label '$label' not found in $tapelist_file\n"; + exit 0; } else { $tapelist->remove_tapelabel($label); } - my $tmp_tapelist_file = "$AMANDA_TMPDIR/tapelist-amrmtape-" . time(); - my $backup_tapelist_file = "$AMANDA_TMPDIR/tapelist-backup-amrmtape-" . time(); - unless (copy($tapelist_file, $backup_tapelist_file)) { - die "Failed to copy/backup $tapelist_file to $backup_tapelist_file"; + + #take a copy in case we roolback + my $backup_tapelist_file = dirname($tapelist_file) . "-backup-amrmtape-" . time(); + if (-x $tapelist_file) { + unless (copy($tapelist_file, $backup_tapelist_file)) { + die "Failed to copy/backup $tapelist_file to $backup_tapelist_file"; + } } - # writing to temp and then moving is generally safer than writing directly + unless ($dry_run) { - $tapelist->write($tmp_tapelist_file); - unless (move($tmp_tapelist_file, $tapelist_file)) { - die "Failed to replace old tapelist with new tapelist."; - } + $tapelist->write(); } my $tmp_curinfo_file = "$AMANDA_TMPDIR/curinfo-amrmtape-" . time();