- my ($restore) = @_;
-
- checkRunningClient();
-
- my $veid = shift(@ARGV);
- die "HN needs a VEID argument" if (!defined($veid));
- die "HN: no command to execute after VEID" if ($#ARGV < 0);
-
- # Find $host in the list of VEs
- my $ve = localVe($veid);
- die "VE $veid not found on this HN" if (!defined($ve));
- #printVeEntry($ve);
-
- if (! $restore) {
- cmdSystemOrEval("vzctl stop $veid >/dev/null 2>&1")
- if ($ve->{'running'});
- makeSnapshot($ve);
- cmdSystemOrEval("vzctl start $veid >/dev/null 2>&1")
- if ($ve->{'running'});
- die "Failed to make snapshot of filesystem for VE $veid"
- if (!defined($ve->{'snaproot'}));
-
- # Make and exec the backup command. Do it in a chroot to the snapshot
- # of the VE's root dir so that any relative path information in the
- # backup command is accurate. This does mean that each VE needs rsync,
- # etc.
- my $cmd = "chroot ".$ve->{'snapprivate'}." ".join(' ', @ARGV);
- #print "HN: cmd |$cmd|\n";
- $? = 0;
- cmdSystemOrEval($cmd);
- my $ret = $?; # FIXME
-
- # Remove snapshot, we're done
- delSnapshot($ve);
-
- # Pass the return code back
- #exit $ret; FIXME: currently, cmdSystemOrEval doesn't return a retcode.
- exit 0;
- } else {
- # Restores work off the VE's live root filesystem. A full restore
- # should be done to the HN host, redirecting the restore to the VE's
- # private directory on the HN when the VE is stopped.
- my $cmd = "chroot ".$ve->{'private'}." ".join(' ', @ARGV);
- #print "HN: cmd |$cmd|\n";
- # A restore can exec, because we have no cleanup to do.
- cmdExecOrEval($cmd);
- }
-}
-
-sub runServer($)
-{
- my ($restore) = @_;
-
- # Build the beginning remote command
- my $remoteCmd = "/usr/bin/".basename($0);
- #print "Remote command is $remoteCmd\n";
-
- my $host = shift(@ARGV);
- die "Hostname argument required" if (!defined($host));
- die "No command to execute after hostname" if ($#ARGV < 0);
-
- # Find $host in the list of VEs
- loadVeList();
- my $ve = getVeByHostname($host);
- die "VE $host not found" if (!defined($ve));
- #printVeEntry($ve);
-
- # The command line is bisected by the next occurrence of $host. Everything
- # before is the ssh command (sans what to run on the VE) and everything
- # after is the xfer command to run on the VE.
- my @sshCmd;
- my @xferCmd;
- my $foundHost = 0;
- foreach my $arg (@ARGV) {
- if ($arg eq $host) {
- $foundHost = 1;
- } else {
- if ($foundHost) {
- push(@xferCmd, $arg);
- } else {
- push(@sshCmd, $arg);
- }
- }
- }
- die "No ssh command found" if ($#sshCmd < 0);
- die "No xfer command found" if ($#xferCmd < 0);
- #print "ssh command: |".join(' ', @sshCmd)."|\n";
- #print "xfer command: |".join(' ', @xferCmd)."|\n";
-
- # Create command line to initiate the remote side of the backup. The
- # remote side runs on the VE's HN and is given the VE's VEID.
- my $cmd = join(' ', @sshCmd)." ".$ve->{'HN'}." $remoteCmd ".
- ($restore ? "restore " : "").$ve->{'VEID'}." ".join(' ', @xferCmd);
- #print "remote command: |$cmd|\n";
-
- ## Search and replace
- #foreach my $key (keys %{$velist[0]}) {
- # my $val = $ve->{$key};
- # $cmd =~ s/\@$key\@/$val/g if (defined($val));
- #}
-
+ my ($restore) = @_;
+
+ checkRunningClient();
+
+ my $veid = shift(@ARGV);
+ die "HN needs a VEID argument" if (!defined($veid));
+ die "HN: no command to execute after VEID" if ($#ARGV < 0);
+
+ # We (the HN where this code is running) must be hosting the requested VE.
+ my $ve = localVe($veid);
+ die "VE $veid not found on this HN" if (!defined($ve));
+ #printVeEntry($ve);
+
+ if (!$restore) {
+ cmdSystemOrEval("vzctl stop $veid >/dev/null 2>&1") if ($ve->{'running'});
+ makeSnapshot($ve);
+ cmdSystemOrEval("vzctl start $veid >/dev/null 2>&1") if ($ve->{'running'});
+ die "Failed to make snapshot of filesystem for VE $veid"
+ if (!defined($ve->{'snaproot'}));
+
+ # Save the VE configuration from its hosted HN into the filesystem. If
+ # /etc is backed up, so will the VE configuration.
+ saveConfigs($ve);
+
+ # Make and exec the backup command. Do it in a chroot to the snapshot
+ # of the VEs root dir so that any relative path information in the
+ # backup command is accurate. This does mean that each VE needs rsync,
+ # etc.
+ my $cmd = "chroot ".$ve->{'snapprivate'}." ".join(' ', @ARGV);
+ #print "HN: cmd |$cmd|\n";
+ $? = 0;
+ cmdSystemOrEval($cmd);
+ my $ret = $?; # FIXME - modify cmdSystemOrEval to get a return value.
+
+ # Remove snapshot, we're done
+ delSnapshot($ve);
+
+ # Pass the return code back
+ #exit $ret; FIXME: currently, cmdSystemOrEval doesn't return a retcode.
+ exit 0;
+ } else {
+ # Restores work off the VE's live root filesystem. A full restore
+ # should be done to the HN host, redirecting the restore to the VE's
+ # private directory on the HN when the VE is stopped.
+ my $cmd = "chroot ".$ve->{'private'}." ".join(' ', @ARGV);
+ #print "HN: cmd |$cmd|\n";
+ # A restore can exec, because we have no cleanup to do.