My nightly dump =)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
This is a tiny script that I am using to create nightly dumps of my MySQL
dbs. Each night it will generate these files:


I am trying to modify the script so that it will 1) check the current month,
and 2) delete the backups that are not from the current month (i.e. in the
case above, all the a-06*.sql, b-06*.sql and c-06*.sql 's will be deleted.

This way I only have 1 month of dumps.

Here is the script (I have it setup as a scheduled task)

 $host = "localhost";
 $user = "root";
 $pass = "password";
 $dbnames = array ("a","b","c");
 $savepath = "c:\inetpub\sqlbackup\";
 $date = date("mdy-hia");

 foreach($dbnames as $dbname)
  $filename = $savepath.$dbname."-".$date.".sql";
  $execCmd = "mysqldump -h$host -u$user -p$pass $dbname >> $filename";

Any ideas ?

Re: My nightly dump =)

On Mon, 19 Jul 2004 22:37:15 -0800, StinkFinger wrote:

Quoted text here. Click to load it

[ snip scheduling script code ]

You'll need to look at opendir() and readdir() to loop through the files,
then I'd use a regex:

[ untested ]

   if (preg_match('/^.*?\-([0-9]).*$/', $filename, $matches)) {
     if (intval($matches[1]) > 1 and intval($matches[1]) < date('m')) {

HT(kinda)H =)



digiServ Network
London, UK /

Re: My nightly dump =)

Ian.H wrote:

Quoted text here. Click to load it

it is easy in OpenVMS

exec('delete path:file.ext;* /before="today-30-"');
(keeps 30 days worth online.)

This gives me 30 days worth of backups.  The script should take today-30 days
otherwise on the first day of the month you will delete all of the backups from
the previous month - including yesterdays backup.

Michael Austin.
Consultant - Available.
Donations welcomed.

Site Timeline