Skip to content

Commit

Permalink
wip: lock on restore too
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Nov 21, 2024
1 parent faee41c commit 6e1a6bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
39 changes: 19 additions & 20 deletions script/rvd_back
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ sub backup($rvd_back) {
unless scalar(@ARGV);

my @reqs;
my %dupe;
for my $name (@ARGV) {
my $dom;
if ( $name =~ /^\d+$/ ) {
Expand All @@ -997,9 +998,12 @@ sub backup($rvd_back) {
$dom = $rvd_back->search_domain($name);
}
if (!$dom) {
warn "Error: Unkonwn domain $name\n";
warn "Error: Unknown domain $name\n";
next;
}
if ($dupe{$dom->name}++) {
warn "Warning: Backup of ".$dom->name." duplicated, requested only one.\n";
}
if ($dom->is_active) {
warn "Error: $name is active, not backing up.\n";
next;
Expand All @@ -1012,17 +1016,24 @@ sub backup($rvd_back) {
push @reqs,($req);
}

_wait_request(@reqs);
exit 0;
}

sub _wait_request(@reqs) {
my $t0 = time;
for (;;) {
last if !@reqs;
my $pending = 0;
my @reqs2;
for my $req (@reqs) {
if ($req->status eq 'done') {
print "Completed backup:\n ";
print "Finished ".$req->command;
if ($req->error) {
print $req->error."\n";
warn $req->error."\n";
}
print $req->output."\n" if$req->output;
print "\n\t".$req->output if $req->output;
print "\n";
} else {
push @reqs2,($req);
}
Expand All @@ -1031,11 +1042,11 @@ sub backup($rvd_back) {
@reqs = @reqs2;
sleep 1;
if (time - $t0 > 10 ) {
print "Waiting for ".scalar(@reqs)." backups to finish\n";
print "Waiting for ".scalar(@reqs)." requests to finish\n";
$t0 = time;
}
}
exit 0;

}

sub _confirm_restore($name) {
Expand Down Expand Up @@ -1074,20 +1085,8 @@ sub restore($rvd_back) {
}
}

for (;;) {
last if !@reqs;
my @reqs2;
for my $req ( @reqs ) {
if ( $req->status eq 'done' ) {
warn $req->error if $req->error;
print $req->args('file')." restored.\n";
print(($req->output or '')."\n");
next;
}
push @reqs2,($req);
}
@reqs = @reqs2;
}
_wait_request(@reqs);
exit(0);
}

sub _list_domains($rvd_back
Expand Down
6 changes: 5 additions & 1 deletion t/vm/backup.t
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ sub backup($vm,$remove_user=undef) {
}

my ($backup) = $domain->list_backups();
$domain->restore_backup($backup,0);
$domain->restore_backup($backup);

my @md5_restored = _vols_md5($domain);
is_deeply(\@md5_restored, \@md5) or exit;
Expand Down Expand Up @@ -420,6 +420,10 @@ sub test_req_backup($vm) {
like($req->output,qr /\//);

remove_domain($domain);

my $file = $req->output;
chomp $file;
return $file;
}

sub test_req_restore($vm, $file) {
Expand Down

0 comments on commit 6e1a6bd

Please sign in to comment.