App-TrimHistories
view release on metacpan or search on metacpan
See the included script trim-histories.
FUNCTIONS
trim_histories
Usage:
trim_histories(%args) -> [status, msg, payload, meta]
Keep only a certain number of sets of file histories, delete the rest.
This script can be used to delete old backup or log files. The files
must be named with timestamps, e.g. "mydb-2017-06-14.sql.gz". By
default, it keeps only 7 daily, 4 weekly, and 6 monthly histories. The
rest will be deleted.
This function is not exported.
This function supports dry-run operation.
Arguments ('*' denotes required arguments):
* discard_old_histories => *bool*
* discard_young_histories => *bool*
* files* => *array[filename]*
Each file name must be unique and contain date, e.g.
`backup-2017-06-14.tar.gz`.
* sets => *array[str]* (default: ["daily",7,"weekly",4,"monthly",6])
History sets to keep.
Expressed as a list of (period, num-to-keep) pairs. Period can be
number of seconds or either "hourly", "daily", "weekly", "monthly",
"yearly". The default is:
['daily', 7, 'weekly', 4, 'monthly', 6]
lib/App/TrimHistories.pm view on Meta::CPAN
use Log::ger;
our %SPEC;
$SPEC{trim_histories} = {
v => 1.1,
summary => 'Keep only a certain number of sets of file histories, '.
'delete the rest',
description => <<'_',
This script can be used to delete old backup or log files. The files must be
named with timestamps, e.g. `mydb-2017-06-14.sql.gz`. By default, it keeps only
7 daily, 4 weekly, and 6 monthly histories. The rest will be deleted.
_
args => {
files => {
'x.name.is_plural' => 1,
'x.name.singular' => 'file',
schema => ['array*', of=>'filename*'],
summary => 'Each file name must be unique and contain date, '.
'e.g. `backup-2017-06-14.tar.gz`',
req => 1,
pos => 0,
greedy => 1,
},
sets => {
summary => 'History sets to keep',
schema => ['array*', of=>'str*', min_len=>2, 'x.perl.coerce_rules' => ['From_str::comma_sep']],
default => [daily => 7, weekly => 4, monthly => 6],
description => <<'_',
lib/App/TrimHistories.pm view on Meta::CPAN
=head2 trim_histories
Usage:
trim_histories(%args) -> [status, msg, payload, meta]
Keep only a certain number of sets of file histories, delete the rest.
This script can be used to delete old backup or log files. The files must be
named with timestamps, e.g. C<mydb-2017-06-14.sql.gz>. By default, it keeps only
7 daily, 4 weekly, and 6 monthly histories. The rest will be deleted.
This function is not exported.
This function supports dry-run operation.
Arguments ('*' denotes required arguments):
=over 4
=item * B<discard_old_histories> => I<bool>
=item * B<discard_young_histories> => I<bool>
=item * B<files>* => I<array[filename]>
Each file name must be unique and contain date, e.g. `backup-2017-06-14.tar.gz`.
=item * B<sets> => I<array[str]> (default: ["daily",7,"weekly",4,"monthly",6])
History sets to keep.
Expressed as a list of (period, num-to-keep) pairs. Period can be number of
seconds or either C<hourly>, C<daily>, C<weekly>, C<monthly>, C<yearly>. The default
is:
['daily', 7, 'weekly', 4, 'monthly', 6]
script/trim-histories view on Meta::CPAN
Like previous, but older and younger files are deleted:
% trim-histories --discard-old --discard-young *
Only keep 5 daily, 2 weekly histories:
% trim-histories --sets daily,5,weekly,2 *
=head1 DESCRIPTION
This script can be used to delete old backup or log files. The files must be
named with timestamps, e.g. C<mydb-2017-06-14.sql.gz>. By default, it keeps only
7 daily, 4 weekly, and 6 monthly histories. The rest will be deleted.
=head1 OPTIONS
C<*> marks required options.
=head2 Main options
=over
=item B<--discard-old-histories>
=item B<--discard-young-histories>
=item B<--file>=I<s@>*
Each file name must be unique and contain date, e.g. `backup-2017-06-14.tar.gz`.
Can be specified multiple times.
=item B<--files-json>=I<s>
Each file name must be unique and contain date, e.g. `backup-2017-06-14.tar.gz` (JSON-encoded).
See C<--file>.
=item B<--sets-json>=I<s>
History sets to keep (JSON-encoded).
See C<--sets>.
=item B<--sets>=I<s@>
( run in 1.612 second using v1.01-cache-2.11-cpan-49f99fa48dc )