},
optional => 1,
},
+ protected => {
+ description => "Protection status. Currently only supported for backups.",
+ type => 'boolean',
+ optional => 1,
+ },
},
},
links => [ { rel => 'child', href => "{volid}" } ],
description => "Optional notes.",
optional => 1,
type => 'string',
- }
+ },
+ protected => {
+ description => "Protection status. Currently only supported for backups.",
+ type => 'boolean',
+ optional => 1,
+ },
},
},
code => sub {
format => $format,
};
- # keep going if fetching an optional attribute fails
- eval {
- my $notes = PVE::Storage::get_volume_attribute($cfg, $volid, 'notes');
- $entry->{notes} = $notes if defined($notes);
- };
- warn $@ if $@;
+ for my $attribute (qw(notes protected)) {
+ # keep going if fetching an optional attribute fails
+ eval {
+ my $value = PVE::Storage::get_volume_attribute($cfg, $volid, $attribute);
+ $entry->{$attribute} = $value if defined($value);
+ };
+ warn $@ if $@;
+ }
return $entry;
}});
type => 'string',
optional => 1,
},
+ protected => {
+ description => "Protection status. Currently only supported for backups.",
+ type => 'boolean',
+ optional => 1,
+ },
},
},
returns => { type => 'null' },
PVE::Storage::check_volume_access($rpcenv, $authuser, $cfg, undef, $volid);
- if (exists $param->{notes}) {
- PVE::Storage::update_volume_attribute($cfg, $volid, 'notes', $param->{notes});
+ for my $attr (qw(notes protected)) {
+ if (exists $param->{$attr}) {
+ PVE::Storage::update_volume_attribute($cfg, $volid, $attr, $param->{$attr});
+ }
}
return undef;
return $info;
}
+sub protection_file_path {
+ my ($path) = @_;
+
+ return "${path}.protected";
+}
+
sub archive_info {
my ($archive) = shift;
my $info;
sub archive_remove {
my ($archive_path) = @_;
+ die "cannot remove protected archive '$archive_path'\n"
+ if -e protection_file_path($archive_path);
+
my $dirname = dirname($archive_path);
my $archive_info = eval { archive_info($archive_path) } // {};
my $logfn = $archive_info->{logfilename};
use Cwd;
use File::Path;
+use IO::File;
use POSIX;
use PVE::Storage::Plugin;
return $class->get_volume_notes($scfg, $storeid, $volname);
}
+ my ($vtype) = $class->parse_volname($volname);
+ return if $vtype ne 'backup';
+
+ if ($attribute eq 'protected') {
+ my $path = $class->filesystem_path($scfg, $volname);
+ return -e PVE::Storage::protection_file_path($path) ? 1 : 0;
+ }
+
return;
}
return $class->update_volume_notes($scfg, $storeid, $volname, $value);
}
+ my ($vtype) = $class->parse_volname($volname);
+ die "only backups support attribute '$attribute'\n" if $vtype ne 'backup';
+
+ if ($attribute eq 'protected') {
+ my $path = $class->filesystem_path($scfg, $volname);
+ my $protection_path = PVE::Storage::protection_file_path($path);
+
+ return if !((-e $protection_path) xor $value); # protection status already correct
+
+ if ($value) {
+ my $fh = IO::File->new($protection_path, O_CREAT, 0644)
+ or die "unable to create protection file '$protection_path' - $!\n";
+ close($fh);
+ } else {
+ unlink $protection_path or $! == ENOENT
+ or die "could not delete protection file '$protection_path' - $!\n";
+ }
+
+ return;
+ }
+
die "attribute '$attribute' is not supported for storage type '$scfg->{type}'\n";
}
sub free_image {
my ($class, $storeid, $scfg, $volname, $isBase, $format) = @_;
+ die "cannot remove protected volume '$volname' on '$storeid'\n"
+ if $class->get_volume_attribute($scfg, $storeid, $volname, 'protected');
+
my $path = $class->filesystem_path($scfg, $volname);
if ($isBase) {
# Should die if there is an error fetching the attribute.
# Possible attributes:
# notes - user-provided comments/notes.
+# protected - not to be removed by free_image, and for backups, ignored when pruning.
sub get_volume_attribute {
my ($class, $scfg, $storeid, $volname, $attribute) = @_;
$info->{notes} = $notes if defined($notes);
}
+ $info->{protected} = 1 if -e PVE::Storage::protection_file_path($original);
} elsif ($tt eq 'snippets') {
$info = {
$prune_entry->{mark} = 'protected';
}
+ $prune_entry->{mark} = 'protected' if $backup->{protected};
+
push @{$prune_list}, $prune_entry;
}
'ctime' => $basetime - 24*60*60 - 60*60,
'vmid' => $vmid,
},
+ {
+ 'volid' => "$storeid:backup/vzdump-qemu-$vmid-2019_12_31-11_18_51.tar.zst",
+ 'ctime' => $basetime - 24*60*60 - 60*60 + 30,
+ 'vmid' => $vmid,
+ 'protected' => 1,
+ },
{
'volid' => "$storeid:backup/vzdump-qemu-$vmid-2019_12_31-11_19_21.tar.zst",
'ctime' => $basetime - 24*60*60 - 60*60 + 60,
'mark' => $marks->[1],
'vmid' => $vmid,
},
+ {
+ 'volid' => "$storeid:backup/vzdump-qemu-$vmid-2019_12_31-11_18_51.tar.zst",
+ 'type' => 'qemu',
+ 'ctime' => $basetime - 24*60*60 - 60*60 + 30,
+ 'mark' => 'protected',
+ 'vmid' => $vmid,
+ },
{
'volid' => "$storeid:backup/vzdump-qemu-$vmid-2019_12_31-11_19_21.tar.zst",
'type' => 'qemu',