Backup-EZ
view release on metacpan or search on metacpan
bin/ezbackup view on Meta::CPAN
version 0.46
=cut
###### PACKAGES ######
use strict;
use warnings;
use Getopt::Long;
use Data::Printer alias => 'pdump';
use Devel::Confess 'color';
use Backup::EZ;
use File::ShareDir;
use File::Spec;
###### PACKAGE CONFIG ######
Getopt::Long::Configure('no_ignore_case');
###### CONSTANTS ######
###### GLOBAL VARIABLES ######
use vars qw($Conf $DryRun $Exclude $InstallCfg $InstallCron $DumpConf);
###### MAIN PROGRAM ######
parse_cmd_line();
if ($InstallCfg) {
install_cfg();
}
elsif ($InstallCron) {
install_cron();
}
else {
main();
}
###### END 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 $?;
}
sub main {
my $ez = Backup::EZ->new(
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;
}
sub parse_cmd_line {
my $help;
my $rc = GetOptions(
"c=s" => \$Conf,
"e=s" => \$Exclude,
"dry-run" => \$DryRun,
"installcfg" => \$InstallCfg,
"installcron=s" => \$InstallCron,
"dumpconf" => \$DumpConf,
"help|?" => \$help
);
print_usage("usage:") if $help;
#check_required( '-h', $Host );
if ($InstallCron) {
if ( $InstallCron ne 'hourly'
and $InstallCron ne 'daily'
and $InstallCron ne 'weekly'
and $InstallCron ne 'monthly' )
{
die "invalid option for -installcron";
}
}
if ( !($rc) || ( @ARGV != 0 ) ) {
( run in 0.952 second using v1.01-cache-2.11-cpan-e93a5daba3e )