]>
git.proxmox.com Git - pve-storage.git/blob - PVE/API2/Storage/FileRestore.pm
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.",
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);
95 # 'leaf' is a proper JSON boolean, map to perl-y bool
96 # TODO: make PBSClient decode all bools always as 1/0?
97 foreach my $item (@$ret) {
98 $item->{leaf
} = $item->{leaf
} ?
1 : 0;
104 __PACKAGE__-
>register_method ({
110 description
=> "You need read access for the volume.",
113 description
=> "Extract a file or directory (as zip archive) from a PBS backup.",
115 additionalProperties
=> 0,
117 node
=> get_standard_option
('pve-node'),
118 storage
=> get_standard_option
('pve-storage-id'),
120 description
=> "Backup snapshot identifier.",
124 description
=> 'base64-path to the directory or file to download.',
130 type
=> 'any', # download
136 my $rpcenv = PVE
::RPCEnvironment
::get
();
137 my $user = $rpcenv->get_user();
139 my $path = extract_param
($param, 'filepath');
140 my $snap = extract_param
($param, 'snapshot');
141 my $storeid = extract_param
($param, 'storage');
142 my $cfg = PVE
::Storage
::config
();
143 my $scfg = PVE
::Storage
::storage_config
($cfg, $storeid);
145 my $volid = "$storeid:backup/$snap";
146 PVE
::Storage
::check_volume_access
($rpcenv, $user, $cfg, undef, $volid);
148 my $client = PVE
::PBSClient-
>new($scfg, $storeid);
149 my $fifo = $client->file_restore_extract_prepare();
151 $rpcenv->fork_worker('pbs-download', undef, $user, sub {
152 my $name = decode_base64
($path);
153 print "Starting download of file: $name\n";
154 $client->file_restore_extract($fifo, $snap, $path, 1);
161 'content-type' => 'application/octet-stream',