use strict;
use warnings;
+
use Fcntl qw(F_GETFD F_SETFD FD_CLOEXEC);
use HTTP::Request;
use IO::File;
use LWP::UserAgent;
use POSIX qw(strftime ENOENT);
-use PVE::Tools qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach);
-use PVE::Storage::Plugin;
use PVE::JSONSchema qw(get_standard_option);
+use PVE::Network;
+use PVE::Storage::Plugin;
+use PVE::Tools qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach $IPV6RE);
use base qw(PVE::Storage::Plugin);
sub properties {
return {
datastore => {
- description => "Proxmox backup server datastore name.",
+ description => "Proxmox Backup Server datastore name.",
type => 'string',
},
# openssl s_client -connect <host>:8007 2>&1 |openssl x509 -fingerprint -sha256
description => "Encryption key. Use 'autogen' to generate one automatically without passphrase.",
type => 'string',
},
+ port => {
+ description => "For non default port.",
+ type => 'integer',
+ minimum => 1,
+ maximum => 65535,
+ default => 8007,
+ }
};
}
return {
server => { fixed => 1 },
datastore => { fixed => 1 },
+ port => { optional => 1 },
nodes => { optional => 1},
disable => { optional => 1},
content => { optional => 1},
my $pwfile = pbs_encryption_key_file_name($scfg, $storeid);
- unlink $pwfile;
+ if (!unlink $pwfile) {
+ return if $! == ENOENT;
+ die "failed to delete encryption key! $!\n";
+ }
+ delete $scfg->{'encryption-key'};
}
sub pbs_get_encryption_key {
return "${storeid}:${volname}";
}
+my sub get_server_with_port {
+ my ($scfg) = @_;
+
+ my $server = $scfg->{server};
+ $server = "[$server]" if $server =~ /^$IPV6RE$/;
+
+ if (my $port = $scfg->{port}) {
+ $server .= ":$port" if $port != 8007;
+ }
+ return $server;
+}
+
my $USE_CRYPT_PARAMS = {
backup => 1,
restore => 1,
die "executable not found '$client_exe'! Proxmox backup client not installed?\n"
if ! -x $client_exe;
- my $server = $scfg->{server};
+ my $server = get_server_with_port($scfg);
my $datastore = $scfg->{datastore};
my $username = $scfg->{username} // 'root@pam';
my $autogen_encryption_key = sub {
my ($scfg, $storeid) = @_;
my $encfile = pbs_encryption_key_file_name($scfg, $storeid);
- run_command(['proxmox-backup-client', 'key', 'create', '--kdf', 'none', $encfile]);
+ my $cmd = ['proxmox-backup-client', 'key', 'create', '--kdf', 'none', $encfile];
+ run_command($cmd, errmsg => 'failed to create encryption key');
+ return PVE::Tools::file_get_contents($encfile);
};
sub on_add_hook {
} else {
pbs_set_encryption_key($scfg, $storeid, $encryption_key);
}
+ $scfg->{'encryption-key'} = 1;
} else {
pbs_delete_encryption_key($scfg, $storeid);
}
} else {
pbs_set_encryption_key($scfg, $storeid, $encryption_key);
}
+ $scfg->{'encryption-key'} = 1;
} else {
pbs_delete_encryption_key($scfg, $storeid);
}
my ($vtype, $name, $vmid) = $class->parse_volname($volname);
- my $server = $scfg->{server};
+ my $server = get_server_with_port($scfg);
my $datastore = $scfg->{datastore};
my $username = $scfg->{username} // 'root@pam';
ctime => $epoch,
};
+ $info->{verification} = $item->{verification} if defined($item->{verification});
+ $info->{comment} = $item->{comment} if defined($item->{comment});
+
push @$res, $info;
}
sub activate_storage {
my ($class, $storeid, $scfg, $cache) = @_;
- run_client_cmd($scfg, $storeid, "status");
+ # a 'status' client command is to expensive here
+ # TODO: use a dummy ping API call to ensure the PBS API daemon is available for real
+ my $server = $scfg->{server};
+ my $port = $scfg->{port} // 8007;
+ PVE::Network::tcp_ping($server, $port, 2);
return 1;
}