sub cleanup {
my ($f_day, $f_month, $f_year) = (0, 0, 0);
if (skip_file($_)) { return; }
# File to be deleted should have a filename that matches the pattern:
# www-
--.tar.gz
if ($_ =~ /^(www)-(\d+)-(\d+)-(\d+)(\.tar\.gz)$/) {
# Extract the day, month, and year values from the filename.
($f_day, $f_month, $f_year) = ($2, $3, $4);
# In order to delete a file, it must have been created in the same year and month
# in which this script is executed, and must be older than $days_old from the current
# day.
if ($f_year eq $c_year) {
if ($f_month eq $c_month) {
if ($f_day lt ($c_day - $days_old)) {
# print "Unlinking file: $find_dir\/$_ \n";
# unlink $_ or print "Couldn't delete $_: $!\n";
&unlink_file($_);
}
}
# If the script is run on, say, the first of a month, it will NOT
# delete ANY tarballs created in the previous month. This is
# a workaround to it. If the current date is the third of the
# month or greater, remove all tarballs created last month.
elsif ($f_month lt $c_month) {
if ($c_day => 3) {
# print "Unlinking file: $find_dir\/$_ \n";
# unlink $_ or print "Couldn't delete $_: $!\n";
&unlink_file($_);
}
} # line 87
}
}
}