App-bk
view release on metacpan or search on metacpan
lib/App/bk.pm view on Meta::CPAN
package App::bk;
use warnings;
use strict;
use Getopt::Long qw(:config no_ignore_case bundling no_auto_abbrev);
use Pod::Usage;
use English 'no-match-vars';
use POSIX qw(strftime);
use File::Basename;
use File::Copy;
use File::Which qw(which);
use Carp;
=head1 NAME
App::bk - A module for functions used by the F<bk> program.
=head1 VERSION
Version 0.05
=cut
our $VERSION = '0.06';
my %opts = (
'help|h|?' => 0,
'man' => 0,
'version|V' => 0,
'debug:+' => 0,
'diff|d' => 0,
'edit|e' => 0,
);
my %options;
# 'tidier' way to store global variables
# probably shouldnt do it like this - will rework later
$options{debug} ||= 0;
$options{username} = getpwuid($EUID);
if ( $options{username} eq 'root' ) {
logmsg( 2, 'Running as root so dropping username from file backups' );
$options{username} = '';
}
=head1 SYNOPSIS
Please see the file F<bk> for more information about the F<bk> program.
=head1 SUBROUTINES/METHODS
=head2 backup_files
Main function to process ARGV and backup files as necessary
=cut
sub backup_files {
# make sure we don't clobber any callers variables
local @ARGV = @ARGV;
GetOptions( \%options, keys(%opts) ) || pod2usage( -verbose => 1 );
die("Version: $VERSION\n") if ( $options{version} );
pod2usage( -verbose => 1 ) if ( $options{'?'} || $options{help} );
pod2usage( -verbose => 2 ) if ( $options{HELP} || $options{man} );
$options{debug} ||= 0;
$options{debug} = 8 if ( $options{debug} > 8 );
if ( !@ARGV ) {
pod2usage(
-message => 'No filenames provided.',
-verbose => 0,
);
}
my $date = strftime( '%Y%m%d', localtime() );
my $time = strftime( '%H%M%S', localtime() );
foreach my $filename (@ARGV) {
my ( $basename, $dirname ) = fileparse($filename);
# do this via savedir as we might move this somewhere else dir in future
my $savedir = $dirname;
logmsg( 2, "dirname=$dirname" );
logmsg( 2, "basename=$basename" );
if ( !-f $filename ) {
warn "WARNING: File $filename not found", $/;
next;
}
if ( !$savedir ) {
warn "WARNING: $savedir does not exist", $/;
next;
}
( run in 3.441 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )