Compare commits

...

5 Commits

Author SHA1 Message Date
Kenny Phelps-McKeown 9b7f6540a1
Merge b50e55c17a into 940a84e21f 2025-06-16 22:39:22 -05:00
Jim Salter 940a84e21f
Merge pull request #1008 from aabccd021/master
Fix readme formatting
2025-06-12 09:53:57 -04:00
aabccd021 680194fa33 Fix readme formatting 2025-06-12 12:58:26 +07:00
kennypm b50e55c17a full flexibility for naming template 2025-02-22 13:16:34 -05:00
kennypm acbf5daa43 custom name prefix without breaking getsnaps()
custom datestamp format
no name reordering yet as getsnaps() expects leading prefix and trailing snap type
2025-02-22 12:05:59 -05:00
3 changed files with 20 additions and 8 deletions

View File

@ -330,6 +330,7 @@ As of 1.4.18, syncoid also automatically supports and enables resume of interrup
This argument tells syncoid to create a zfs bookmark for the newest snapshot after it got replicated successfully. The bookmark name will be equal to the snapshot name. Only works in combination with the --no-sync-snap option. This can be very useful for irregular replication where the last matching snapshot on the source was already deleted but the bookmark remains so a replication is still possible. This argument tells syncoid to create a zfs bookmark for the newest snapshot after it got replicated successfully. The bookmark name will be equal to the snapshot name. Only works in combination with the --no-sync-snap option. This can be very useful for irregular replication where the last matching snapshot on the source was already deleted but the bookmark remains so a replication is still possible.
+ --use-hold + --use-hold
This argument tells syncoid to add a hold to the newest snapshot on the source and target after replication succeeds and to remove the hold after the next successful replication. Setting a hold prevents the snapshots from being destroyed. The hold name includes the identifier if set. This allows for separate holds in case of replication to multiple targets. This argument tells syncoid to add a hold to the newest snapshot on the source and target after replication succeeds and to remove the hold after the next successful replication. Setting a hold prevents the snapshots from being destroyed. The hold name includes the identifier if set. This allows for separate holds in case of replication to multiple targets.
+ --preserve-recordsize + --preserve-recordsize

21
sanoid
View File

@ -17,6 +17,7 @@ use Getopt::Long qw(:config auto_version auto_help);
use Pod::Usage; # pod2usage use Pod::Usage; # pod2usage
use Time::Local; # to parse dates in reverse use Time::Local; # to parse dates in reverse
use Capture::Tiny ':all'; use Capture::Tiny ':all';
use POSIX 'strftime';
my %args = ( my %args = (
"configdir" => "/etc/sanoid", "configdir" => "/etc/sanoid",
@ -616,7 +617,11 @@ sub take_snapshots {
my @snapshots; my @snapshots;
foreach my $type (@types) { foreach my $type (@types) {
my $snapname = "autosnap_$datestamp{'sortable'}_$type"; my $sortable = strftime($config{$dataset}{'datestamp_format'}, localtime($datestamp{'unix_time'}));
my $snapname = $config{$dataset}{'snapname_format'};
$snapname =~ s/IDENTIFIER/$config{$dataset}{'identifier'}/g;
$snapname =~ s/DATE/$sortable/g;
$snapname =~ s/TYPE/$type/g;
push(@snapshots, $snapname); push(@snapshots, $snapname);
} }
@ -906,12 +911,13 @@ sub getsnaps {
} }
foreach my $snap (@rawsnaps) { foreach my $snap (@rawsnaps) {
my ($fs,$snapname,$snapdate) = ($snap =~ m/(.*)\@(.*ly)\t*creation\t*(\d*)/); my ($fs,$snapname,$snapdate) = ($snap =~ m/(.*)\@(.*?)\t*creation\t*(\d*)/);
# avoid pissing off use warnings # avoid pissing off use warnings
if (defined $snapname) { if (defined $snapname) {
my ($snaptype) = ($snapname =~ m/.*_(\w*ly)/); if ($snapname =~ /$config{$fs}{'identifier'}/) {
if ($snapname =~ /^autosnap/) { my @types = qw(yearly monthly weekly daily hourly frequently);
my ($snaptype) = grep { $snapname =~ /$_/ } @types;
$snaps{$fs}{$snapname}{'ctime'}=$snapdate; $snaps{$fs}{$snapname}{'ctime'}=$snapdate;
$snaps{$fs}{$snapname}{'type'}=$snaptype; $snaps{$fs}{$snapname}{'type'}=$snaptype;
} }
@ -1150,16 +1156,15 @@ sub init {
sub get_date { sub get_date {
my %datestamp; my %datestamp;
($datestamp{'sec'},$datestamp{'min'},$datestamp{'hour'},$datestamp{'mday'},$datestamp{'mon'},$datestamp{'year'},$datestamp{'wday'},$datestamp{'yday'},$datestamp{'isdst'}) = localtime(time); $datestamp{'unix_time'} = time();
($datestamp{'sec'},$datestamp{'min'},$datestamp{'hour'},$datestamp{'mday'},$datestamp{'mon'},$datestamp{'year'},$datestamp{'wday'},$datestamp{'yday'},$datestamp{'isdst'}) = localtime($datestamp{'unix_time'});
$datestamp{'year'} += 1900; $datestamp{'year'} += 1900;
$datestamp{'unix_time'} = (((((((($datestamp{'year'} - 1971) * 365) + $datestamp{'yday'}) * 24) + $datestamp{'hour'}) * 60) + $datestamp{'min'}) * 60) + $datestamp{'sec'};
$datestamp{'sec'} = sprintf ("%02u", $datestamp{'sec'}); $datestamp{'sec'} = sprintf ("%02u", $datestamp{'sec'});
$datestamp{'min'} = sprintf ("%02u", $datestamp{'min'}); $datestamp{'min'} = sprintf ("%02u", $datestamp{'min'});
$datestamp{'hour'} = sprintf ("%02u", $datestamp{'hour'}); $datestamp{'hour'} = sprintf ("%02u", $datestamp{'hour'});
$datestamp{'mday'} = sprintf ("%02u", $datestamp{'mday'}); $datestamp{'mday'} = sprintf ("%02u", $datestamp{'mday'});
$datestamp{'mon'} = sprintf ("%02u", ($datestamp{'mon'} + 1)); $datestamp{'mon'} = sprintf ("%02u", ($datestamp{'mon'} + 1));
$datestamp{'noseconds'} = "$datestamp{'year'}-$datestamp{'mon'}-$datestamp{'mday'}_$datestamp{'hour'}:$datestamp{'min'}";
$datestamp{'sortable'} = "$datestamp{'noseconds'}:$datestamp{'sec'}";
return %datestamp; return %datestamp;
} }

View File

@ -113,3 +113,9 @@ yearly_crit = 0
# for overriding these values one needs to specify them in a root pool section! ([tank]\n ...) # for overriding these values one needs to specify them in a root pool section! ([tank]\n ...)
capacity_warn = 80 capacity_warn = 80
capacity_crit = 95 capacity_crit = 95
# snapshot name formats can be overridden
identifier = autosnap
# strftime-style format string
datestamp_format = %Y-%m-%d_%H:%M:%S
snapname_format = IDENTIFIER_DATE_TYPE