From e0e4b23d522ef908b91d444a1578b923097b52fd Mon Sep 17 00:00:00 2001 From: Andinus Date: Thu, 29 Oct 2020 19:10:14 +0530 Subject: Change backup format, group by profile instead of date Backups are now grouped by profile instead of date. This means less noise when running daily backup of a specific profile, earlier it would've polluted the backups directory, now it'll add the backups to the profile specific folder. Also, this includes more information & users can run leo multiple times a day. Earlier running more than once a day would've over-written the previous backup, from now on it'll create a new file because we include time in the filename. Time will be in GMT. --- leo.pl | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'leo.pl') diff --git a/leo.pl b/leo.pl index 50614d1..c03f673 100755 --- a/leo.pl +++ b/leo.pl @@ -63,9 +63,9 @@ foreach my $section (sort keys $config->%*) { } } -my $ymd = ymd(); # YYYY-MM-DD. +my $date = date(); my $backup_dir = $options{backup_dir} || "/tmp/backups"; -$backup_dir .= "/$ymd"; +# $backup_dir .= "/$date"; path($backup_dir)->mkpath; # Create backup directory. @@ -81,6 +81,7 @@ foreach my $prof ( @ARGV ) { if ( $profile{ $prof } ) { say "++++++++********++++++++"; + path("$backup_dir/${prof}")->mkpath; # Create backup directory. backup($prof); # It will fail because signify will look for "${prof}.tar" but @@ -99,7 +100,7 @@ foreach my $prof ( @ARGV ) { sub backup { my $prof = shift @_; - my $tar_file = "$backup_dir/${prof}.tar"; + my $tar_file = "$backup_dir/${prof}/${date}.tar"; # Make @backup_paths relative to '/'. my @backup_paths; @@ -140,7 +141,7 @@ sub backup { # Encrypt, Sign backups. sub encrypt_sign { my $prof = shift @_; - my $file = "$backup_dir/${prof}.tar"; + my $file = "$backup_dir/${prof}/${date}.tar"; my @options = (); push @options, "--default-key", $gpg_fingerprint; @@ -173,7 +174,7 @@ sub encrypt_sign { sub signify { my $prof = shift @_; - my $file = "$backup_dir/${prof}.tar"; + my $file = "$backup_dir/${prof}/${date}.tar"; die "\nSignify: seckey doesn't exist\n" unless $options{signify_seckey} and -e $options{signify_seckey}; @@ -229,9 +230,9 @@ Profile:}; sub tar_create { run3 ["/bin/tar", "cf", @_]; } sub tar_list { run3 ["/bin/tar", "tvf", @_]; } -sub ymd { +sub date { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = - localtime(time); + gmtime(time); $year += 1900; # $year contains the number of years since 1900. @@ -240,6 +241,11 @@ sub ymd { my @months = qw( 01 02 03 04 05 06 07 08 09 10 11 12 ); my $month = $months[$mon]; + # Pad by 2 zeros. $mday = sprintf "%02d", $mday; - return "$year-$month-$mday"; + $hour = sprintf "%02d", $hour; + $min = sprintf "%02d", $min; + $min = sprintf "%02d", $sec; + + return "$year-$month-${mday}T${hour}:${min}:${sec}Z"; } -- cgit 1.4.1-2-gfad0