Backup-EZ
view release on metacpan
or search on metacpan
Changes
view on Meta::CPAN
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ==================================================
-----------------------------------------
version 0.46 at 2021-01-14 20:48:26 +0000
-----------------------------------------
Change: e6839c576ddfa36f128d51878ec8ced66be41627
Author: John Gravatt <john @gravatt .org>
Date : 2021-01-14 14:48:14 +0000
removed previous sudo addition in EZ.pm, because it breaks backups
-----------------------------------------
version 0.45 at 2020-10-29 19:39:30 +0000
-----------------------------------------
Change: 3fab9d8b94fa23427a9133eeed584d637db73939
Author: John Gravatt <john @gravatt .org>
Date : 2020-10-29 14:39:30 +0000
Merge pull request
|
MANIFEST
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | Changes
INSTALL
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
bin/ezbackup
dist.ini
lib/Backup/EZ.pm
lib/Backup/EZ/Dir.pm
share/ezbackup.conf
share/ezbackup_exclude.rsync
t/00-load.t
t/01-module-prereq.t
t/10-new.t
t/11-backup.t
t/12-reldir.t
t/13- with -user.t
t/14-whoami.t
t/15-expire-without-sudo.t
t/16-expire- with -sudo.t
t/17-missing-dir.t
t/18-exclude.t
t/19-chunked.t
t/author-pod-syntax.t
t/boilerplate.t
t/common.pl
t/ezbackup.conf
t/ezbackup2.conf
t/ezbackup_chunked.conf
t/ezbackup_exclude.conf
t/ezbackup_min.conf
t/ezbackup_missing_dir.conf
t/ezbackup_reldir.conf
t/ezbackup_user.conf
|
META.json
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 | {
"abstract" : "Simple backups based on rsync." ,
"author" : [
"John Gravatt <gravattj@cpan.org>"
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010" ,
"license" : [
"perl_5"
],
"meta-spec" : {
|
META.yml
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 | ---
abstract: 'Simple backups based on rsync.'
author:
- 'John Gravatt <gravattj@cpan.org>'
build_requires:
File::Path: '0'
File::RandomGenerator: '0'
File::Touch: '0'
Test::More: '0'
perl: '5.006'
configure_requires:
ExtUtils::MakeMaker: '0'
|
Makefile.PL
view on Meta::CPAN
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | $File::ShareDir::Install::INCLUDE_DOTFILES = 1;
$File::ShareDir::Install::INCLUDE_DOTDIRS = 1;
install_share dist => "share" ;
my %WriteMakefileArgs = (
"ABSTRACT" => "Simple backups based on rsync." ,
"AUTHOR" => "John Gravatt <gravattj\@cpan.org>" ,
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0,
"File::ShareDir::Install" => "0.06"
},
"DISTNAME" => "Backup-EZ" ,
"EXE_FILES" => [
"bin/ezbackup"
],
"LICENSE" => "perl" ,
"MIN_PERL_VERSION" => "5.006" ,
"NAME" => "Backup::EZ" ,
"PREREQ_PM" => {
"Carp" => 0,
"Config::General" => 0,
"Data::Dumper" => 0,
"Data::Printer" => 0,
"Data::UUID" => 0,
|
README
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 | This archive contains the distribution Backup-EZ,
version 0.46:
Simple backups based on rsync.
This software is copyright (c) 2014 by John Gravatt.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
This README file was generated by Dist::Zilla::Plugin::Readme v6.012.
|
bin/ezbackup
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
bin/ezbackup
view on Meta::CPAN
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | }
else {
main();
}
sub install_cron {
my $cron_dir = "/etc/cron.$InstallCron" ;
my $ez_path = `which ezbackup`;
chomp $ez_path ;
if ( !File::Spec->file_name_is_absolute( $ez_path ) ) {
$ez_path = File::Spec->rel2abs( $ez_path );
}
my $cron_file = "$cron_dir/ezbackup" ;
print "installing $cron_file\n" ;
open my $fh , ">$cron_file" or die "failed to open $cron_file: $!" ;
print $fh "#!/bin/sh\n\n" ;
print $fh "nice $ez_path\n" ;
close $fh ;
my_system( "chmod 755 $cron_file" );
}
sub install_cfg {
my $etc_dir = "/etc/ezbackup" ;
my $dist_dir = File::ShareDir::dist_dir( "Backup-EZ" );
my_system( "mkdir -p $etc_dir" );
my_system( "cp $dist_dir/ezbackup.conf $etc_dir" );
my_system( "cp $dist_dir/ezbackup_exclude.rsync $etc_dir" );
my_system( "chmod 644 $etc_dir/*" );
}
sub my_system {
my $cmd = shift ;
print "$cmd\n" ;
system ( $cmd );
die if $?;
}
|
bin/ezbackup
view on Meta::CPAN
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | conf => $Conf ,
exclude_file => $Exclude ,
dryrun => $DryRun
);
die if ! $ez ;
if ( $DumpConf ) {
$ez ->dump_conf;
}
else {
$ez ->backup;
}
}
sub check_required {
my $opt = shift ;
my $arg = shift ;
print_usage( "missing arg $opt" ) if ! $arg ;
}
|
bin/ezbackup
view on Meta::CPAN
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | if ( !( $rc ) || ( @ARGV != 0 ) ) {
print_usage( "parse_cmd_line failed" );
}
}
sub print_usage {
print STDERR "@_\n" ;
print "\n* Install default config files to /etc/ezbackup:\n\n"
. "\t$0 -installcfg\n" . "\n\n" ;
print "* Install cron.X\n\n"
. "\t$0 -installcron (hourly|daily|weekly|monthly)\n" . "\n\n" ;
print "* Run a backup:\n\n"
. "\t$0\n"
. "\t\t[-c <conf file>]\n"
. "\t\t[-e <rsync exclude file>]\n"
. "\t\t[-dry-run]\n"
. "\t\t[-?] (usage)\n" . "\n" ;
exit 1;
}
|
dist.ini
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | name = Backup-EZ
author = John Gravatt <gravattj @cpan .org>
license = Perl_5
copyright_holder = John Gravatt
copyright_year = 2014
abstract = Simple backups based on rsync.
main_module = lib/Backup/EZ.pm
version = 0.46
;[NextRelease]
;[CheckChangesHasContent]
;[GatherDir]
[Git::GatherDir]
|
lib/Backup/EZ.pm
view on Meta::CPAN
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | use constant EXCLUDE_FILE => '/etc/ezbackup/ezbackup_exclude.rsync' ; use constant CONF => '/etc/ezbackup/ezbackup.conf' ; use constant DEST_HOSTNAME => 'localhost' ; use constant DEFAULT_ARCHIVE_OPTS => '-az' ; use constant ARCHIVE_NO_RECURSE_OPTS => '-dlptgoDz' ;
|
lib/Backup/EZ.pm
view on Meta::CPAN
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | bless $self , $class ;
return $self ;
}
sub _debug {
my $self = shift ;
my $msg = shift ;
my $line = ( caller )[2];
openlog "ezbackup" , $self ->{syslog_option}, LOG_SYSLOG;
syslog LOG_DEBUG, "($line) $msg" ;
closelog;
}
sub _info {
my $self = shift ;
my $msg = shift ;
openlog "ezbackup" , $self ->{syslog_option}, LOG_SYSLOG;
syslog LOG_INFO, $msg ;
closelog;
}
sub _read_conf {
my $self = shift ;
my %a = @_ ;
my $conf = $a {conf} ? $a {conf} : CONF;
|
lib/Backup/EZ.pm
view on Meta::CPAN
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | -LowerCaseNames => 1,
-AutoTrue => 1,
);
my %conf = $config ->getall;
_debug( $self , Dumper \ %conf );
foreach my $key ( keys %conf ) {
if ( ! defined $conf {backup_host} ) {
$conf {backup_host} = DEST_HOSTNAME;
}
if ( ! defined $conf {copies} ) {
$conf {copies} = COPIES;
}
if ( ! defined $conf {append_machine_id} ) {
$conf {append_machine_id} = DEST_APPEND_MACH_ID;
}
|
lib/Backup/EZ.pm
view on Meta::CPAN
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
confess if $?;
return @out ;
}
sub _get_dest_username {
my $self = shift ;
if ( $self ->{conf}->{backup_user} ) {
return $self ->{conf}->{backup_user};
}
if ( $ENV {USER} ) {
return $ENV {USER};
}
my $whoami = `whoami`;
chomp $whoami ;
return $whoami ;
}
sub _get_dest_hostname {
my $self = shift ;
return $self ->{conf}->{backup_host};
}
sub _get_dest_tmp_dir {
my $self = shift ;
return sprintf ( "%s/%s" , $self ->get_dest_dir, ".tmp" );
}
sub _get_dest_backup_dir {
my $self = shift ;
return sprintf ( "%s/%s" , $self ->get_dest_dir, $self ->{datestamp} );
}
sub _is_unit_test {
my $self = shift ;
if ( $0 =~ /\.t$/ ) {
|
lib/Backup/EZ.pm
view on Meta::CPAN
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | sub _full_backup_chunked {
my $self = shift ;
my $dir = shift ;
$self ->_rsync2(
dir => $dir ->dirname,
archive_opts => ARCHIVE_NO_RECURSE_OPTS,
extra_opts => $dir ->excludes(),
);
my @entries = read_dir( $dir ->dirname, prefix => 1 );
|
lib/Backup/EZ.pm
view on Meta::CPAN
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | if ( -d $entry ) {
$self ->_rsync2(
dir => $entry ,
archive_opts => DEFAULT_ARCHIVE_OPTS,
extra_opts => $dir ->excludes(),
);
}
}
}
sub _full_backup {
my $self = shift ;
my $dir = shift ;
if ( $dir ->chunked ) {
$self ->_full_backup_chunked( $dir );
}
else {
$self ->_rsync2(
dir => $dir ->dirname,
archive_opts => DEFAULT_ARCHIVE_OPTS,
extra_opts => $dir ->excludes(),
);
}
}
sub _inc_backup_chunked {
my $self = shift ;
my $dir = shift ;
my $last_backup_dir = shift ;
my $link_dest = shift ;
$self ->_rsync2(
dir => $dir ->dirname,
archive_opts => ARCHIVE_NO_RECURSE_OPTS,
extra_opts => $dir ->excludes(),
link_dest => $link_dest ,
);
my @entries = read_dir( $dir ->dirname, prefix => 0 );
|
lib/Backup/EZ.pm
view on Meta::CPAN
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | $self ->_rsync2(
dir => $abs_entry ,
archive_opts => DEFAULT_ARCHIVE_OPTS,
extra_opts => $dir ->excludes(),
link_dest => sprintf ( '%s/%s' , $link_dest , $entry ),
);
}
}
}
sub _inc_backup {
my $self = shift ;
my $dir = shift ;
my $last_backup_dir = shift ;
my $link_dest = sprintf (
"%s/%s/%s" ,
$self ->get_dest_dir,
$last_backup_dir ,
$dir ->dirname,
);
if ( $dir ->chunked ) {
$self ->_inc_backup_chunked( $dir , $last_backup_dir , $link_dest );
}
else {
$self ->_rsync2(
dir => $dir ->dirname,
archive_opts => DEFAULT_ARCHIVE_OPTS,
extra_opts => $dir ->excludes(),
link_dest => $link_dest ,
);
}
}
|
lib/Backup/EZ.pm
view on Meta::CPAN
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 | Does what it says.
sub backup {
my $self = shift ;
$self ->_mk_dest_dir( $self ->get_dest_dir );
my @backups = $self ->get_list_of_backups;
$self ->_set_datestamp;
$self ->_mk_dest_dir( $self ->_get_dest_tmp_dir, $self ->{dryrun} );
foreach my $dir ( $self ->_get_dirs ) {
my $dirname = $dir ->dirname();
if ( -d $dirname ) {
$self ->_info( "backing up $dirname" );
if ( ! @backups ) {
$self ->_full_backup( $dir );
}
else {
$self ->_inc_backup( $dir , $backups [ $#backups ] );
}
}
else {
$self ->_info( "skipping $dirname because it does not exist" );
}
}
$self ->_ssh(
sprintf ( "mv %s %s" ,
$self ->_get_dest_tmp_dir, $self ->_get_dest_backup_dir ),
$self ->{dryrun}
);
$self ->expire();
return 1;
}
sub expire {
my $self = shift ;
my @list = $self ->get_list_of_backups;
while ( scalar ( @list ) > $self ->{conf}->{copies} ) {
my $subdir = shift @list ;
my $del_dir = sprintf ( "%s/%s" , $self ->get_dest_dir, $subdir );
my $cmd = sprintf ( "%s rm -rf $del_dir" ,
$self ->{conf}->{use_sudo} ? 'sudo' : '' );
$self ->_ssh( $cmd );
}
}
sub get_backup_host {
my $self = shift ;
return $self ->{conf}->{backup_host};
}
sub get_dest_dir {
my $self = shift ;
|
lib/Backup/EZ.pm
view on Meta::CPAN
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | my $uuid = slurp( "/etc/machine-id" );
chomp $uuid ;
$hostname = "$hostname-$uuid" ;
}
return sprintf ( "%s/%s" , $self ->{conf}->{dest_dir}, $hostname );
}
sub get_list_of_backups {
my $self = shift ;
my @backups ;
my @list = $self ->_ssh( sprintf ( "ls %s" , $self ->get_dest_dir ) );
foreach my $e ( @list ) {
chomp $e ;
if ( $e =~ /^\d\d\d\d-\d\d-\d\d_\d\d:\d\d:\d\d$/ ) {
push ( @backups , $e );
}
}
return @backups ;
}
1;
|
lib/Backup/EZ/Dir.pm
view on Meta::CPAN
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
share/ezbackup.conf
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | copies 30
backup_host TODO
dest_dir TODO
exclude_file ezbackup_exclude.rsync
use_sudo 0
|
t/10-new.t
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #!/usr/bin/env perl
my $ez = Backup::EZ->new( conf => 'share/ezbackup.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync'
);
ok( $ez );
done_testing();
|
t/11-backup.t
view on Meta::CPAN
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | nuke();
pave();
my $ez = Backup::EZ->new(
conf => 't/ezbackup.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 1
);
die if ! $ez ;
remove_tree( $ez ->get_dest_dir);
ok( $ez ->backup );
ok( ! $ez ->get_list_of_backups() );
$ez = Backup::EZ->new(
conf => 't/ezbackup.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 0
);
die if ! $ez ;
ok( $ez ->backup );
my @list = $ez ->get_list_of_backups();
ok( @list == 1 );
ok( sleep 1 && $ez ->backup );
@list = $ez ->get_list_of_backups();
ok( @list == 2 ) or print Dumper \ @list ;
my $host = $ez ->get_backup_host;
ok( $host );
$ez = Backup::EZ->new(
conf => 't/ezbackup_min.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 0
);
die if ! $ez ;
ok( sleep 1 && $ez ->backup );
@list = $ez ->get_list_of_backups();
ok( @list == 3 ) or print STDERR Dumper \ @list ;
my $dir = sprintf "%s/junk" , $ez ->get_dest_dir;
touch( $dir );
@list = $ez ->get_list_of_backups();
ok( @list == 3 );
done_testing();
nuke();
|
t/12-reldir.t
view on Meta::CPAN
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | require "t/common.pl" ;
nuke();
pave();
my $ez ;
eval {
$ez = Backup::EZ->new(
conf => 't/ezbackup_reldir.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 0
);
};
ok( $ez );
eval { $ez ->backup };
ok($@);
nuke();
done_testing();
|
t/13-with-user.t
view on Meta::CPAN
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | require "t/common.pl" ;
nuke();
pave();
my $ez ;
eval {
$ez = Backup::EZ->new(
conf => 't/ezbackup_user.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 0,
);
};
ok( $ez );
ok( $ez ->backup );
nuke();
done_testing();
|
t/14-whoami.t
view on Meta::CPAN
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | require "t/common.pl" ;
$ENV {USER} = undef ;
nuke();
pave();
my $ez ;
eval {
$ez = Backup::EZ->new(
conf => 't/ezbackup.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 0,
);
};
ok( $ez );
ok( $ez ->backup );
nuke();
done_testing();
|
t/15-expire-without-sudo.t
view on Meta::CPAN
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | require "t/common.pl" ;
my $ez = Backup::EZ->new(
conf => 't/ezbackup.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 1
);
die if ! $ez ;
nuke();
pave();
$ez = Backup::EZ->new(
conf => 't/ezbackup.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 0
);
die if ! $ez ;
for ( my $i = 0 ; $i < 3 ; $i ++ ) {
ok( $ez ->backup );
sleep 1;
}
my @list = $ez ->get_list_of_backups();
ok( @list == 3 );
touch( sprintf ( "%s/junk" , $ez ->get_dest_dir() ));
ok( $ez ->backup );
@list = $ez ->get_list_of_backups();
ok( @list == 3 );
nuke();
done_testing();
|
t/16-expire-with-sudo.t
view on Meta::CPAN
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | require "t/common.pl" ;
my $ez = Backup::EZ->new(
conf => 't/ezbackup2.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 1
);
die if ! $ez ;
nuke();
pave();
$ez = Backup::EZ->new(
conf => 't/ezbackup2.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 0
);
die if ! $ez ;
for ( my $i = 0 ; $i < 3 ; $i ++ ) {
ok( $ez ->backup );
sleep 1;
}
my @list = $ez ->get_list_of_backups();
ok( @list == 3, "expected 3 dirs, got " . scalar ( @list ) );
touch( sprintf ( "%s/junk" , $ez ->get_dest_dir() ));
ok( $ez ->backup );
@list = $ez ->get_list_of_backups();
ok( @list == 3 );
nuke();
done_testing();
|
t/17-missing-dir.t
view on Meta::CPAN
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | nuke();
pave();
my $ez = Backup::EZ->new(
conf => 't/ezbackup_missing_dir.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 1
);
die if ! $ez ;
remove_tree( $ez ->get_dest_dir);
ok( $ez ->backup );
ok( ! $ez ->get_list_of_backups() );
$ez = Backup::EZ->new(
conf => 't/ezbackup_missing_dir.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 0
);
die if ! $ez ;
ok( $ez ->backup );
my @list = $ez ->get_list_of_backups();
ok( @list == 1 );
ok( sleep 1 && $ez ->backup );
@list = $ez ->get_list_of_backups();
ok( @list == 2 ) or print Dumper \ @list ;
my $host = $ez ->get_backup_host;
ok( $host );
nuke();
done_testing();
|
t/18-exclude.t
view on Meta::CPAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | require "t/common.pl" ;
use constant SRC_DIR => '/tmp/backup_ez_testdata' ; use constant SRC_FOO_DIR => sprintf ( '%s/%s' , SRC_DIR(), FOO_SUBDIR() ); nuke();
pave();
my $ez = Backup::EZ->new(
conf => 't/ezbackup_exclude.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 0
);
die if ! $ez ;
remove_tree( $ez ->get_dest_dir);
validate_conf( $ez );
finish_paving( $ez );
ok( $ez ->backup );
my @list = $ez ->get_list_of_backups();
ok( @list == 1 );
my $foo_subdir = get_dest_foo_dir( $ez );
ok( !-d $foo_subdir , "checking that $foo_subdir does not exist" );
my $src_count = get_dir_entry_count(SRC_DIR);
my $foo_count = get_dir_entry_count(SRC_FOO_DIR);
my $expect_count = $src_count - $foo_count ;
my $dest_count = get_dir_entry_count(get_dest_backup_dir( $ez ));
ok( $dest_count == $expect_count , "checking file counts" );
done_testing();
nuke();
sub get_dir_entry_count{
my $dir = shift ;
|
t/18-exclude.t
view on Meta::CPAN
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | my @out = `find $src_foo `;
if ( @out < 2 ) {
die "not enough files in $src_foo" ;
}
}
sub get_dest_foo_dir {
my $ez = shift ;
my ( $backup_dir ) = $ez ->get_list_of_backups();
my $foo_dir = sprintf ( '%s/%s%s' ,
$ez ->get_dest_dir, $backup_dir , get_root_backup_dir( $ez ));
return $foo_dir ;
}
sub get_dest_backup_dir {
my $ez = shift ;
return sprintf ( '%s/%s' , get_root_backup_dir( $ez ), SRC_DIR());
}
sub get_root_backup_dir {
my $ez = shift ;
my ( $backup_dir ) = $ez ->get_list_of_backups();
return sprintf ( '%s/%s' , $ez ->get_dest_dir, $backup_dir );
}
sub validate_conf {
my $ez = shift ;
my @dirs = $ez ->get_conf_dirs;
if ( scalar @dirs == 1 ) {
return 1;
}
|
t/19-chunked.t
view on Meta::CPAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | require "t/common.pl" ;
use constant SRC_DIR => '/tmp/backup_ez_testdata' ; use constant SRC_FOO_DIR => sprintf ( '%s/%s' , SRC_DIR(), FOO_SUBDIR() ); nuke();
pave();
my $ez = Backup::EZ->new(
conf => 't/ezbackup_chunked.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 0
);
die if ! $ez ;
remove_tree( $ez ->get_dest_dir);
validate_conf( $ez );
finish_paving( $ez );
ok( $ez ->backup );
my @list = $ez ->get_list_of_backups();
ok( @list == 1 );
my $foo_subdir = get_dest_foo_dir( $ez , $list [0] );
ok( -d $foo_subdir , "checking that $foo_subdir does exist" );
my $src_count = get_dir_entry_count(SRC_DIR);
my $dest_count = get_dir_entry_count( get_dest_backup_dir( $ez , $list [0]) );
ok( $src_count == $dest_count , "checking file counts" );
sleep 1;
ok( $ez ->backup());
@list = $ez ->get_list_of_backups();
ok( @list == 2 );
$foo_subdir = get_dest_foo_dir( $ez , $list [1] );
ok( -d $foo_subdir , "checking that $foo_subdir does exist" );
$src_count = get_dir_entry_count(SRC_DIR);
$dest_count = get_dir_entry_count( get_dest_backup_dir( $ez , $list [1]) );
ok( $src_count == $dest_count , "checking file counts" );
done_testing();
nuke();
sub get_dir_entry_count {
my $dir = shift ;
|
t/19-chunked.t
view on Meta::CPAN
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | $frg ->generate;
my @out = `find $src_foo `;
if ( @out < 2 ) {
die "not enough files in $src_foo" ;
}
}
sub get_dest_foo_dir {
my $ez = shift ;
my $backup = shift ;
my $foo_dir = sprintf (
'%s/%s%s' ,
$ez ->get_dest_dir,
$backup ,
SRC_FOO_DIR(),
);
return $foo_dir ;
}
sub get_dest_backup_dir {
my $ez = shift ;
my $backup = shift ;
my $dir = sprintf ( '%s/%s' , get_root_backup_dir( $ez , $backup ), SRC_DIR() );
return $dir ;
}
sub get_root_backup_dir {
my $ez = shift ;
my $backup = shift ;
return sprintf ( '%s/%s' , $ez ->get_dest_dir, $backup );
}
sub validate_conf {
my $ez = shift ;
my @dirs = $ez ->get_conf_dirs;
if ( scalar @dirs == 2 ) {
return 1;
}
|
t/common.pl
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | use constant DATA_DIR => '/tmp/backup_ez_testdata' ; sub nuke {
my $data_dir = shift @ARGV ;
if (! $data_dir ) {
$data_dir = DATA_DIR;
}
my $ez = Backup::EZ->new(
conf => 't/ezbackup.conf' ,
exclude_file => 'share/ezbackup_exclude.rsync' ,
dryrun => 1
);
die if ! $ez ;
remove_tree( $ez ->{conf}->{dest_dir} );
remove_tree( $data_dir );
}
|
t/ezbackup.conf
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | copies 3
backup_host localhost
dest_dir /tmp/backups
append_machine_id off
dir /tmp/backup_ez_testdata/dir1
dir /tmp/backup_ez_testdata/dir2
|
t/ezbackup2.conf
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | copies 3
backup_host localhost
dest_dir /tmp/backups
use_sudo 1
append_machine_id off
dir /tmp/backup_ez_testdata/dir1
dir /tmp/backup_ez_testdata/dir2
|
t/ezbackup_chunked.conf
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | copies 3
backup_host localhost
dest_dir /tmp/backups
append_machine_id off
dir /tmp/backup_ez_testdata, exclude=foo/
dir /tmp/backup_ez_testdata/dir1/foo, chunked
|
t/ezbackup_exclude.conf
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | copies 3
backup_host localhost
dest_dir /tmp/backups
append_machine_id off
dir /tmp/backup_ez_testdata, exclude=foo/
|
t/ezbackup_min.conf
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | dest_dir /tmp/backups
dir /tmp/backup_ez_testdata/dir1
dir /tmp/backup_ez_testdata/dir2
|
t/ezbackup_missing_dir.conf
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | copies 3
backup_host localhost
dest_dir /tmp/backups
append_machine_id off
dir /tmp/backup_ez_testdata/dir1
dir /tmp/backup_ez_testdata/dir2
dir /tmp/backup_ez_testdata/bogus
|
t/ezbackup_reldir.conf
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | dest_dir /tmp/backups
append_machine_id on
|
t/ezbackup_user.conf
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | backup_user root
dest_dir /tmp/backups
dir /tmp/backup_ez_testdata/dir1
dir /tmp/backup_ez_testdata/dir2
|