mirror of https://github.com/jimsalterjrs/sanoid
nerfed most of the warnings with if defined checks
This commit is contained in:
parent
ee6c1d15e4
commit
36980d4788
92
sanoid
92
sanoid
|
|
@ -7,6 +7,7 @@
|
||||||
$::VERSION = '1.4.17';
|
$::VERSION = '1.4.17';
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
use warnings;
|
||||||
use Config::IniFiles; # read samba-style conf file
|
use Config::IniFiles; # read samba-style conf file
|
||||||
use Data::Dumper; # debugging - print contents of hash
|
use Data::Dumper; # debugging - print contents of hash
|
||||||
use File::Path; # for rmtree command in use_prune
|
use File::Path; # for rmtree command in use_prune
|
||||||
|
|
@ -195,45 +196,48 @@ sub prune_snapshots {
|
||||||
elsif ($type eq 'daily') { $period = 60*60*24; }
|
elsif ($type eq 'daily') { $period = 60*60*24; }
|
||||||
elsif ($type eq 'monthly') { $period = 60*60*24*31; }
|
elsif ($type eq 'monthly') { $period = 60*60*24*31; }
|
||||||
elsif ($type eq 'yearly') { $period = 60*60*24*365.25; }
|
elsif ($type eq 'yearly') { $period = 60*60*24*365.25; }
|
||||||
|
|
||||||
|
# avoid pissing off use warnings by not executing this block if no matching snaps exist
|
||||||
|
if (defined $snapsbytype{$path}{$type}{'sorted'}) {
|
||||||
|
my @sorted = split (/\|/,$snapsbytype{$path}{$type}{'sorted'});
|
||||||
|
|
||||||
my @sorted = split (/\|/,$snapsbytype{$path}{$type}{'sorted'});
|
# if we say "daily=30" we really mean "don't keep any dailies more than 30 days old", etc
|
||||||
|
my $maxage = ( time() - $config{$section}{$type} * $period );
|
||||||
|
# but if we say "daily=30" we ALSO mean "don't get rid of ANY dailies unless we have more than 30".
|
||||||
|
my $minsnapsthistype = $config{$section}{$type};
|
||||||
|
|
||||||
# if we say "daily=30" we really mean "don't keep any dailies more than 30 days old", etc
|
# how many total snaps of this type do we currently have?
|
||||||
my $maxage = ( time() - $config{$section}{$type} * $period );
|
my $numsnapsthistype = scalar (@sorted);
|
||||||
# but if we say "daily=30" we ALSO mean "don't get rid of ANY dailies unless we have more than 30".
|
|
||||||
my $minsnapsthistype = $config{$section}{$type};
|
|
||||||
|
|
||||||
# how many total snaps of this type do we currently have?
|
my @prunesnaps;
|
||||||
my $numsnapsthistype = scalar (@sorted);
|
foreach my $snap( @sorted ){
|
||||||
|
# print "snap $path\@$snap has age $snaps{$path}{$snap}{'ctime'}, maxage is $maxage.\n";
|
||||||
my @prunesnaps;
|
if ( ($snaps{$path}{$snap}{'ctime'} < $maxage) && ($numsnapsthistype > $minsnapsthistype) ) {
|
||||||
foreach my $snap( @sorted ){
|
my $fullpath = $path . '@' . $snap;
|
||||||
# print "snap $path\@$snap has age $snaps{$path}{$snap}{'ctime'}, maxage is $maxage.\n";
|
push(@prunesnaps,$fullpath);
|
||||||
if ( ($snaps{$path}{$snap}{'ctime'} < $maxage) && ($numsnapsthistype > $minsnapsthistype) ) {
|
# we just got rid of a snap, so we now have one fewer, duh
|
||||||
my $fullpath = $path . '@' . $snap;
|
$numsnapsthistype--;
|
||||||
push(@prunesnaps,$fullpath);
|
}
|
||||||
# we just got rid of a snap, so we now have one fewer, duh
|
}
|
||||||
$numsnapsthistype--;
|
|
||||||
}
|
if ((scalar @prunesnaps) > 0) {
|
||||||
}
|
# print "found some snaps to prune!\n"
|
||||||
|
if (checklock('sanoid_pruning')) {
|
||||||
if ((scalar @prunesnaps) > 0) {
|
writelock('sanoid_pruning');
|
||||||
# print "found some snaps to prune!\n"
|
foreach my $snap( @prunesnaps ){
|
||||||
if (checklock('sanoid_pruning')) {
|
if ($args{'verbose'}) { print "INFO: pruning $snap ... \n"; }
|
||||||
writelock('sanoid_pruning');
|
if (iszfsbusy($path)) {
|
||||||
foreach my $snap( @prunesnaps ){
|
print "INFO: deferring pruning of $snap - $path is currently in zfs send or receive.\n";
|
||||||
if ($args{'verbose'}) { print "INFO: pruning $snap ... \n"; }
|
} else {
|
||||||
if (iszfsbusy($path)) {
|
if (! $args{'readonly'}) { system($zfs, "destroy",$snap) == 0 or warn "could not remove $snap : $?"; }
|
||||||
print "INFO: deferring pruning of $snap - $path is currently in zfs send or receive.\n";
|
}
|
||||||
} else {
|
}
|
||||||
if (! $args{'readonly'}) { system($zfs, "destroy",$snap) == 0 or warn "could not remove $snap : $?"; }
|
removelock('sanoid_pruning');
|
||||||
}
|
$forcecacheupdate = 1;
|
||||||
|
%snaps = getsnaps(%config,$cacheTTL,$forcecacheupdate);
|
||||||
|
} else {
|
||||||
|
print "INFO: deferring snapshot pruning - valid pruning lock held by other sanoid process.\n";
|
||||||
}
|
}
|
||||||
removelock('sanoid_pruning');
|
|
||||||
$forcecacheupdate = 1;
|
|
||||||
%snaps = getsnaps(%config,$cacheTTL,$forcecacheupdate);
|
|
||||||
} else {
|
|
||||||
print "INFO: deferring snapshot pruning - valid pruning lock held by other sanoid process.\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -512,10 +516,14 @@ sub getsnaps {
|
||||||
|
|
||||||
foreach my $snap (@rawsnaps) {
|
foreach my $snap (@rawsnaps) {
|
||||||
my ($fs,$snapname,$snapdate) = ($snap =~ m/(.*)\@(.*ly)\s*creation\s*(\d*)/);
|
my ($fs,$snapname,$snapdate) = ($snap =~ m/(.*)\@(.*ly)\s*creation\s*(\d*)/);
|
||||||
my ($snaptype) = ($snapname =~ m/.*_(\w*ly)/);
|
|
||||||
if ($snapname =~ /^autosnap/) {
|
# avoid pissing off use warnings
|
||||||
$snaps{$fs}{$snapname}{'ctime'}=$snapdate;
|
if (defined $snapname) {
|
||||||
$snaps{$fs}{$snapname}{'type'}=$snaptype;
|
my ($snaptype) = ($snapname =~ m/.*_(\w*ly)/);
|
||||||
|
if ($snapname =~ /^autosnap/) {
|
||||||
|
$snaps{$fs}{$snapname}{'ctime'}=$snapdate;
|
||||||
|
$snaps{$fs}{$snapname}{'type'}=$snaptype;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -603,10 +611,10 @@ sub init {
|
||||||
# make sure that true values are true and false values are false for any toggled values
|
# make sure that true values are true and false values are false for any toggled values
|
||||||
foreach my $toggle(@toggles) {
|
foreach my $toggle(@toggles) {
|
||||||
foreach my $true (@istrue) {
|
foreach my $true (@istrue) {
|
||||||
if ($config{$section}{$toggle} eq $true) { $config{$section}{$toggle} = 1; }
|
if (defined $config{$section}{$toggle} && $config{$section}{$toggle} eq $true) { $config{$section}{$toggle} = 1; }
|
||||||
}
|
}
|
||||||
foreach my $false (@isfalse) {
|
foreach my $false (@isfalse) {
|
||||||
if ($config{$section}{$toggle} eq $false) { $config{$section}{$toggle} = 0; }
|
if (defined $config{$section}{$toggle} && $config{$section}{$toggle} eq $false) { $config{$section}{$toggle} = 0; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1031,7 +1039,7 @@ sub iszfsbusy {
|
||||||
sub getchilddatasets {
|
sub getchilddatasets {
|
||||||
# for later, if we make sanoid itself support sudo use
|
# for later, if we make sanoid itself support sudo use
|
||||||
my $fs = shift;
|
my $fs = shift;
|
||||||
my $mysudocmd;
|
my $mysudocmd = '';
|
||||||
|
|
||||||
my $getchildrencmd = "$mysudocmd $zfs list -o name -Hr $fs |";
|
my $getchildrencmd = "$mysudocmd $zfs list -o name -Hr $fs |";
|
||||||
if ($args{'debug'}) { print "DEBUG: getting list of child datasets on $fs using $getchildrencmd...\n"; }
|
if ($args{'debug'}) { print "DEBUG: getting list of child datasets on $fs using $getchildrencmd...\n"; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue