Hi there everyone!

I've run amok and one of my hosts is unhappy that I'm storing as many backups as I am on a shared hosting account.

My problem is that I'm backing up to a remote server and don't have an automated method of removing backups older than a week.

Can someone help me with creating a script that will run via cron to delete all .zip files found in the current directory older than a week?

I would very much appreciate any guidance you can provide as I'm completely lost when it comes to manipulating physical files via php.

thanks,
json

    If you have access to run cron jobs, why use PHP at all? Just add:

    find /path/to/your_directory -mtime +7 -exec rm -f {} \;

    to the cron job (where "+7" means "7 days ago") and you're done.

      bradgrafelman;10977282 wrote:

      If you have access to run cron jobs, why use PHP at all? Just add:

      find /home/content/73/7682073/html -mtime +7 -exec rm -f {} \;

      to the cron job (where "+7" means "7 days ago") and you're done.

      Thanks very much for your help Brad,

      I need to delete only zips though, due to the fact that the cron will strip my html files as well. Is there a way to restrict it to tar.gz files?

        Add an "-iname *.tar.gz" (need to escape the asterisk character in a *nix shell) onto the find command to find specific file names (the 'i' means case insensitive, whereas '-name' would do a case-sensitive match).

          bradgrafelman;10977282 wrote:
          find /path/to/your_directory -iname \*.tar.gz -mtime +7 -exec rm -f {} \;

          Would be the correct implementation of this?

            Seems right to me, although you could do a test run by changing this:

            -exec rm -f {} \;

            to something like this:

            -exec echo Delete: {} \;

            and view the output to make sure that the files listed are indeed the files you wish to remove.

              Write a Reply...