From bb62ba2a071879e4a8baf07f58964a64301c6179 Mon Sep 17 00:00:00 2001 From: Jonas Meier Date: Sun, 17 May 2020 23:13:11 +0200 Subject: [PATCH] add param support with getopt --- rsync-timefilter.pl | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/rsync-timefilter.pl b/rsync-timefilter.pl index aa9b1fd..b9d55e9 100755 --- a/rsync-timefilter.pl +++ b/rsync-timefilter.pl @@ -8,9 +8,20 @@ use File::Rsync; use DateTime; use DateTime::Duration; use DateTime::Format::Strptime; +use Getopt::Long; + +my $rsync_src; +my $rsync_dst; +my $age; + +GetOptions ("source=s" => \$rsync_src, + "destination=s" => \$rsync_dst, + "age=i" => \$age) +or die("Error. Wrong arguments!\n"); + my $now = DateTime->now(); -my $cutoff_timestamp = $now - DateTime::Duration->new(days => 7); +my $cutoff_timestamp = $now - DateTime::Duration->new(days => $age); my $parser = DateTime::Format::Strptime->new( pattern => '%Y/%m/%d %H:%M:%S', time_zone => 'UTC', @@ -26,13 +37,13 @@ my @files = grep { name => $parts[4], timestamp => $parser->parse_datetime($parts[2] . ' ' . $parts[3]), } -} $rsync->list(src => 'planet.openstreetmap.org::planet/planet/'); +} $rsync->list(src => $rsync_src); #use DDP; p @files; $rsync->exec( - src => 'planet.openstreetmap.org::planet/planet/', - dst => '/tmp/rsynctest', + src => $rsync_src, + dst => $rsync_dst, include => [map { $_->{name} } @files], exclude => ['*'], );