Skip to content

Instantly share code, notes, and snippets.

@EdwardIII
Created March 17, 2011 16:24
Show Gist options
  • Save EdwardIII/874614 to your computer and use it in GitHub Desktop.
Save EdwardIII/874614 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use DateTime;
use File::Copy 'move';
my $dt = DateTime->now;
my $today = $dt->ymd('-');
my $filename_out = '/home/datastore/home_edward_' . $today . '.tar';
my $final_destination = '/mnt/server16/Shared/Edd/'; # include trailing slash
use Archive::Tar;
my $tar = Archive::Tar->new;
my @files = (glob('/home/edward/*'), glob('/home/edward/.*'));
@files = grep (!/\.cache|\.links|\.thunderbird/, @files);
$tar->add_files(@files) or die "Couldn't add files";
$tar->write($filename_out) or die "Couldn't write $filename_out";
move($filename_out, $final_destination) or die "Couldn't move backup to a safe place: $!";
# rotate
my @existing_backups = glob($final_destination . 'home_edward_*');
my @goners = map { (-f > 3) ? $_ : () } @existing_backups;
unlink(@goners) or warn "Couldn't rotate backups: $!";
#'regex' validation parameter for 'DateTime::from_epoch must be a string or qr// regex
# at /home/edward/perl5/lib/perl5/i686-linux-thread-multi/DateTime.pm line 486
# DateTime::from_epoch(undef, 'epoch', 1300379136) called at /home/edward/perl5/lib/perl5/i686-linux-thread-multi/DateTime.pm line 511
# DateTime::now('DateTime') called at ./scripts/backup.pl line 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment