Daily Archiving

It’s a good idea. Do it. It doesn’t need to be a hassle. If you have a ‘nix system you can tweak this script to suit your tastes. Pretty much you’ll need to edit the excluded directories. I don’t backup thunderbird because it’s all on the imap, or the trash, well because there’s nothing there I care about, hence calling it the trash. And a few other things I don’t really hold near and dear. This one will keep the last 3 days on hand, as well as one archive per week for the last month, and keeps monthlies for a long time. Feel free to edit, and share, CC-BY-SA (you can put Bearfeet, for the by).

# created 9/2010 by Bearfeet
use strict;
system(“chmod 755 ~/Archives/”);
my $date = `date +%Y_%m_%d`;
my $home = `echo ~`;
chdir $home;
my $host = `hostname`;
my $ehome = $home;
$ehome =~ s/\//\\\//g;
my $archive = “$host\_backup_$date.tar.gz”;
my $command = “ls -A1 ~|grep -Ev \”Archives|remote_drives|Trash|Music|thumbnails\”|”;
$command = “$command xargs -r tar -czf $home/Archives/$archive”;
$command = “$command –exclude=\”*[Cc]ache*\””;
$command = “$command –exclude=\”*macromedia*\””;
$command = “$command –exclude=\”.wine\””;
$command = “$command –exclude=\”share/Trash\””;
$command = “$command –exclude=\”.VirtualBox\””;
$command = “$command –exclude=\”.thunderbird\””;
$command = “$command –exclude=\”Downloads\””;
$command = “$command 2>/dev/null”;
system($command);#create today’s archive
my $offset = `date +%d`;
if($offset == 1)
print “first condition\n”;
$offset = `date –date=”+10 years -3 days”`;
system(“touch –date=\”$offset\” $home/Archives/$archive”);
elsif($offset%7 == 1)
print “second condition\n”;
$offset = `date –date=”+1 month -3 days”`;
system(“touch –date=\”$offset\” $home/Archives/$archive”);
system(“find $home/Archives -mtime +3 -name \”$host\_backup_*_*_*.tar.gz\”|xargs -r /bin/rm”);#|xargs /bin/rm”);
system(“chmod 555 ~/Archives/”);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: