From 786e90e993884fe0208444d25c4613468549ecaf Mon Sep 17 00:00:00 2001 From: Seddy Date: Sun, 26 Nov 2023 16:09:19 +0100 Subject: [PATCH] New timestamp_format "human" with separators to increase human readability --- ChangeLog | 3 +++ btrbk | 7 +++++-- doc/btrbk.conf.5.asciidoc | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5fb1f7c1..e3b4b782 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +unreleased +* New timestamp_format "human" with separators to increase human readability + btrbk-0.32.6 * Fix backup of unrelated (by parent_uuid) snapshots (close #339). diff --git a/btrbk b/btrbk index 33251630..cf4ac264 100755 --- a/btrbk +++ b/btrbk @@ -64,7 +64,7 @@ my $ipv4_addr_match = qr/(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3} my $ipv6_addr_match = qr/[a-fA-F0-9]*:[a-fA-F0-9]*:[a-fA-F0-9:]+/; # simplified (contains at least two colons), matches "::1", "2001:db8::7" my $host_name_match = qr/(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])/; my $uuid_match = qr/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/; -my $btrbk_timestamp_match = qr/(?[0-9]{4})(?[0-9]{2})(?
[0-9]{2})(T(?[0-9]{2})(?[0-9]{2})((?[0-9]{2})(?(Z|[+-][0-9]{4})))?)?(_(?[0-9]+))?/; # matches "YYYYMMDD[Thhmm[ss+0000]][_NN]" +my $btrbk_timestamp_match = qr/(?[0-9]{4})-?(?[0-9]{2})-?(?
[0-9]{2})_?(T?(?[0-9]{2})-?(?[0-9]{2})((?[0-9]{2})(?(Z|[+-][0-9]{4})))?)?(_(?[0-9]+))??/; # matches "YYYYMMDD[Thhmm[ss+0000]][_NN]" my $raw_postfix_match = qr/\.btrfs(\.($compress_format_alt))?(\.(gpg|encrypted))?/; # matches ".btrfs[.gz|.bz2|.xz|...][.gpg|.encrypted]" my $safe_file_match = qr/[0-9a-zA-Z_@\+\-\.\/]+/; # note: ubuntu uses '@' in the subvolume layout: @@ -82,7 +82,7 @@ my %config_options = ( # NOTE: the parser always maps "no" to undef # NOTE: keys "volume", "subvolume" and "target" are hardcoded # NOTE: files "." and "no" map to - timestamp_format => { default => "long", accept => [qw( short long long-iso )], context => [qw( global volume subvolume )] }, + timestamp_format => { default => "long", accept => [qw( short long long-iso human )], context => [qw( global volume subvolume )] }, snapshot_dir => { default => undef, accept_file => { relative => 1, absolute => 1 }, context => [qw( global volume subvolume )] }, snapshot_name => { c_default => 1, accept_file => { name_only => 1 }, context => [qw( subvolume )], deny_glob_context => 1 }, # NOTE: defaults to the subvolume name (hardcoded) snapshot_create => { default => "always", accept => [qw( no always ondemand onchange )], context => [qw( global volume subvolume )] }, @@ -4834,6 +4834,9 @@ sub timestamp($$;$) elsif($format eq "debug-iso") { $ts = sprintf('%04u-%02u-%02uT%02u:%02u:%02u', $tm[5] + 1900, $tm[4] + 1, $tm[3], $tm[2], $tm[1], $tm[0]); } + elsif($format eq "human") { + return sprintf('%04u-%02u-%02u_%02u-%02u', $tm[5] + 1900, $tm[4] + 1, $tm[3], $tm[2], $tm[1]); + } else { die; } if($tm_is_utc) { diff --git a/doc/btrbk.conf.5.asciidoc b/doc/btrbk.conf.5.asciidoc index 04f8e4d3..09e90b33 100644 --- a/doc/btrbk.conf.5.asciidoc +++ b/doc/btrbk.conf.5.asciidoc @@ -94,7 +94,7 @@ otherwise. === Basic Options -*timestamp_format* short|long|long-iso:: +*timestamp_format* short|long|long-iso|human:: Timestamp format used as postfix for new snapshot subvolume names. Defaults to ``long''. + @@ -105,6 +105,7 @@ endif::backend-docbook,backend-manpage[] *short*;; +YYYYMMDD[_N]+ (e.g. "20150825", "20150825_1") *long*;; +YYYYMMDDhhmm[_N]+ (e.g. "20150825T1531") *long-iso*;; +YYYYMMDDhhmmss±hhmm[_N]+ (e.g. "20150825T153123+0200") +*human*;; +YYYY<->MM<->DD<_>hh<->mm[_N]+ (e.g. "2015-08-25_15-31") -- + Note that a postfix "_N" is appended to the timestamp if a snapshot or