diff options
author | Andinus <andinus@nand.sh> | 2020-10-29 19:10:14 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-10-29 19:10:14 +0530 |
commit | e0e4b23d522ef908b91d444a1578b923097b52fd (patch) | |
tree | 4236954e69f377b24de116062227cb07e03a9700 | |
parent | aa687edb97564beaddf382ce37629eb4f404cc1d (diff) | |
download | leo-e0e4b23d522ef908b91d444a1578b923097b52fd.tar.gz |
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.
-rwxr-xr-x | leo.pl | 22 |
1 files changed, 14 insertions, 8 deletions
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"; } |