Thanks, Watts! That was the help I needed.
Here's what I've got now, which seems to work fine:
Code:
#!/usr/bin/perl -w
use strict;
&MAIN();
sub MAIN
{
my $target_dir = '/PATH/TO/DIRECTORY';
my $backup_dir = '/PATH/TO/STORE/ARCHIVE';
my $exclude_dir = '/PATH/TO/EXCLUDE';
my $days_to_keep = 21;
my $archive;
# Move to the backup directory
chdir($backup_dir) or die "ERROR: Could not change to backup directory\n";
if (! -d $target_dir)
{
die "ERROR: Target is not a directory.\n";
}
if (! -r $target_dir)
{
die "ERROR: Can't read target.\n";
}
# Make archive name
$archive = makeArchiveName($target_dir);
# Make the tarball
`tar cf $archive $target_dir --exclude $exclude_dir`;
# Bzip the tarball
`bzip2 $archive`;
# Delete old archives
opendir(DELE, $backup_dir) or die "Could not open directory\n";
@TODELETE = readdir(DELE);
foreach $archive_file (@TODELETE) {
if(-d $archive_file) {next};
if ((-C $archive_file) > $days_to_keep) {
unlink($archive_file);
}
}
closedir(DELE);
}
sub makeArchiveName
{
## stuff in here to generate the archive file name
}
Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund