-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Archive module add the possibility to rsync the the files after a dump. Also you can enfore clean up with a very simple retention rule.
- Loading branch information
Showing
6 changed files
with
118 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package PostgresTools::Archive; | ||
|
||
use strict; | ||
use warnings; | ||
use 5.012; | ||
|
||
use Moo; | ||
use File::Path; | ||
use File::Rsync; | ||
use PostgresTools::Date; | ||
|
||
has keep_days => ( is => 'rw' ); | ||
has dst => ( is => 'ro', required => 1 ); | ||
has base_dir => ( is => 'ro', required => 1 ); | ||
|
||
sub BUILD { | ||
my $self = shift; | ||
unless ( $self->{dst} ) { | ||
die "archive destination is undefined or empty string"; | ||
} | ||
} | ||
|
||
sub backup { | ||
my $self = shift; | ||
my $rsync = File::Rsync->new( { archive => 1 } ); | ||
|
||
$rsync->exec( { src => $self->{base_dir}, dest => $self->{dst} } ) or die $!; | ||
} | ||
|
||
sub clean { | ||
my $self = shift; | ||
my $formatter = DateTime::Format::Strptime->new( pattern => '%Y%m%d' ); | ||
my $date = PostgresTools::Date->new( | ||
formatter => $formatter, | ||
); | ||
my $delete_date = $date->offset2date( $self->{keep_days} ); | ||
my $to_clean = "$self->{base_dir}/$delete_date"; | ||
if ( -d $to_clean ) { | ||
rmtree $to_clean or warn $!; | ||
} | ||
my $rsync = File::Rsync->new( { archive => 1, delete => 1 } ); | ||
|
||
$rsync->exec( { src => $self->{base_dir}, dest => $self->{dst} } ) or die $!; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters