sub set_password {
my ($self, $password) = @_;
- my $pwfile = $self->password_file_name();
+ my $pwfile = password_file_name($self);
mkdir $self->{secret_dir};
PVE::Tools::file_set_contents($pwfile, "$password\n", 0600);
sub delete_password {
my ($self) = @_;
- my $pwfile = $self->password_file_name();
+ my $pwfile = password_file_name($self);
- unlink $pwfile;
+ unlink $pwfile or die "deleting password file failed - $!\n";
};
sub get_password {
my ($self) = @_;
- my $pwfile = $self->password_file_name();
+ my $pwfile = password_file_name($self);
return PVE::Tools::file_read_firstline($pwfile);
}
# This must live in the top scope to not get closed before the `run_command`
my $keyfd;
if ($use_crypto) {
- if (defined($keyfd = $self->open_encryption_key())) {
+ if (defined($keyfd = open_encryption_key($self))) {
my $flags = fcntl($keyfd, F_GETFD, 0)
// die "failed to get file descriptor flags: $!\n";
fcntl($keyfd, F_SETFD, $flags & ~FD_CLOEXEC)
my sub run_raw_client_cmd {
my ($self, $client_cmd, $param, %opts) = @_;
- return $self->do_raw_client_cmd($client_cmd, $param, %opts);
+ return do_raw_client_cmd($self, $client_cmd, $param, %opts);
}
my sub run_client_cmd {
$param = [@$param, '--output-format=json'] if !$no_output;
- $self->do_raw_client_cmd(
+ do_raw_client_cmd(
+ $self,
$client_cmd,
$param,
outfunc => $outfunc,
return file_get_contents($encfile);
};
+# lists all snapshots, optionally limited to a specific group
sub get_snapshots {
- my ($self, $opts) = @_;
+ my ($self, $group) = @_;
my $param = [];
- push @$param, $opts->{group} if defined($opts->{group});
+ push @$param, $group if defined($group);
- return $self->run_client_cmd("snapshots", $param);
+ return run_client_cmd($self, "snapshots", $param);
};
-sub backup_tree {
- my ($self, $opts) = @_;
+# create a new PXAR backup of a FS directory tree - doesn't cross FS boundary
+# by default.
+sub backup_fs_tree {
+ my ($self, $root, $id, $pxarname, $cmd_opts) = @_;
- my $type = delete $opts->{type};
- die "backup-type not provided\n" if !defined($type);
- my $id = delete $opts->{id};
die "backup-id not provided\n" if !defined($id);
- my $root = delete $opts->{root};
- die "root dir not provided\n" if !defined($root);
- my $pxarname = delete $opts->{pxarname};
+ die "backup root dir not provided\n" if !defined($root);
die "archive name not provided\n" if !defined($pxarname);
- my $time = delete $opts->{time};
my $param = [
"$pxarname.pxar:$root",
- '--backup-type', $type,
+ '--backup-type', 'host',
'--backup-id', $id,
];
- push @$param, '--backup-time', $time if defined($time);
- return $self->run_raw_client_cmd('backup', $param, %$opts);
+ $cmd_opts //= {};
+
+ return run_raw_client_cmd($self, 'backup', $param, %$cmd_opts);
};
sub restore_pxar {
- my ($self, $opts) = @_;
+ my ($self, $snapshot, $pxarname, $target, $cmd_opts) = @_;
- my $snapshot = delete $opts->{snapshot};
die "snapshot not provided\n" if !defined($snapshot);
- my $pxarname = delete $opts->{pxarname};
die "archive name not provided\n" if !defined($pxarname);
- my $target = delete $opts->{target};
die "restore-target not provided\n" if !defined($target);
my $param = [
"$target",
"--allow-existing-dirs", 0,
];
+ $cmd_opts //= {};
- return $self->run_raw_client_cmd('restore', $param, %$opts);
+ return run_raw_client_cmd($self, 'restore', $param, %$cmd_opts);
};
sub forget_snapshot {
die "snapshot not provided\n" if !defined($snapshot);
- return $self->run_raw_client_cmd('forget', ["$snapshot"]);
+ return run_raw_client_cmd($self, 'forget', ["$snapshot"]);
};
sub prune_group {
}
push @$param, "$group";
- return $self->run_client_cmd('prune', $param);
+ return run_client_cmd($self, 'prune', $param);
};
sub status {
my $active = 0;
eval {
- my $res = $self->run_client_cmd("status");
+ my $res = run_client_cmd($self, "status");
$active = 1;
$total = $res->{total};