]>
git.proxmox.com Git - pve-storage.git/blob - PVE/API2/Storage/FileRestore.pm
68f81ebe1e31acc125be6d99afe4f268aeabcb74
1 package PVE
::API2
::Storage
::FileRestore
;
7 use PVE
::JSONSchema
qw(get_standard_option);
10 use PVE
::Tools
qw(extract_param);
13 use base
qw(PVE::RESTHandler);
15 __PACKAGE__-
>register_method ({
21 description
=> "You need read access for the volume.",
24 description
=> "List files and directories for single file restore under the given path.",
26 additionalProperties
=> 0,
28 node
=> get_standard_option
('pve-node'),
29 storage
=> get_standard_option
('pve-storage-id'),
31 description
=> "Backup snapshot identifier.",
35 description
=> 'base64-path to the directory or file being listed, or "/".',
46 description
=> "base64 path of the current entry",
50 description
=> "Entry type.",
54 description
=> "Entry display text.",
58 description
=> "If this entry is a leaf in the directory graph.",
59 type
=> 'any', # JSON::PP::Boolean gets passed through
62 description
=> "Entry file size.",
67 description
=> "Entry last-modified time (unix timestamp).",
78 my $rpcenv = PVE
::RPCEnvironment
::get
();
79 my $user = $rpcenv->get_user();
81 my $path = extract_param
($param, 'filepath') || "/";
82 my $base64 = $path ne "/";
83 my $snap = extract_param
($param, 'snapshot');
84 my $storeid = extract_param
($param, 'storage');
85 my $cfg = PVE
::Storage
::config
();
86 my $scfg = PVE
::Storage
::storage_config
($cfg, $storeid);
88 my $volid = "$storeid:backup/$snap";
89 PVE
::Storage
::check_volume_access
($rpcenv, $user, $cfg, undef, $volid);
91 my $client = PVE
::PBSClient-
>new($scfg, $storeid);
92 my $ret = $client->file_restore_list($snap, $path, $base64);
97 __PACKAGE__-
>register_method ({
103 description
=> "You need read access for the volume.",
106 description
=> "Extract a file or directory (as zip archive) from a PBS backup.",
108 additionalProperties
=> 0,
110 node
=> get_standard_option
('pve-node'),
111 storage
=> get_standard_option
('pve-storage-id'),
113 description
=> "Backup snapshot identifier.",
117 description
=> 'base64-path to the directory or file to download.',
123 type
=> 'any', # download
129 my $rpcenv = PVE
::RPCEnvironment
::get
();
130 my $user = $rpcenv->get_user();
132 my $path = extract_param
($param, 'filepath');
133 my $snap = extract_param
($param, 'snapshot');
134 my $storeid = extract_param
($param, 'storage');
135 my $cfg = PVE
::Storage
::config
();
136 my $scfg = PVE
::Storage
::storage_config
($cfg, $storeid);
138 my $volid = "$storeid:backup/$snap";
139 PVE
::Storage
::check_volume_access
($rpcenv, $user, $cfg, undef, $volid);
141 my $client = PVE
::PBSClient-
>new($scfg, $storeid);
142 my $fifo = $client->file_restore_extract_prepare();
144 $rpcenv->fork_worker('pbs-download', undef, $user, sub {
145 my $name = decode_base64
($path);
146 print "Starting download of file: $name\n";
147 $client->file_restore_extract($fifo, $snap, $path, 1);
154 'content-type' => 'application/octet-stream',