My nightly dump =)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • StinkFinger

    #1

    My nightly dump =)

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

    a-071804-0900pm.sql
    b-071804-0900pm.sql
    c-071804-0900pm.sql

    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)

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

    foreach($dbname s as $dbname)
    {
    $filename = $savepath.$dbna me."-".$date.".s ql";
    $execCmd = "mysqldump -h$host -u$user -p$pass $dbname >> $filename";
    exec($execCmd);
    }
    ?>

    Any ideas ?
    Thanks.


  • Ian.H

    #2
    Re: My nightly dump =)

    On Mon, 19 Jul 2004 22:37:15 -0800, StinkFinger wrote:
    [color=blue]
    > All,
    > This is a tiny script that I am using to create nightly dumps of my MySQL
    > dbs. Each night it will generate these files:
    >
    > a-071804-0900pm.sql
    > b-071804-0900pm.sql
    > c-071804-0900pm.sql
    >
    > 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.[/color]


    [ 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]{2}).*$/', $filename, $matches)) {
    if (intval($matche s[1]) > 1 and intval($matches[1]) < date('m')) {
    unlink($filenam e);
    }
    }


    HT(kinda)H =)



    Regards,

    Ian

    --
    Ian.H
    digiServ Network
    London, UK


    Comment

    • Michael Austin

      #3
      Re: My nightly dump =)

      Ian.H wrote:
      [color=blue]
      > On Mon, 19 Jul 2004 22:37:15 -0800, StinkFinger wrote:
      >
      >[color=green]
      >>All,
      >>This is a tiny script that I am using to create nightly dumps of my MySQL
      >>dbs. Each night it will generate these files:
      >>
      >>a-071804-0900pm.sql
      >>b-071804-0900pm.sql
      >>c-071804-0900pm.sql
      >>
      >>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.[/color]
      >
      >
      >
      > [ 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]{2}).*$/', $filename, $matches)) {
      > if (intval($matche s[1]) > 1 and intval($matches[1]) < date('m')) {
      > unlink($filenam e);
      > }
      > }
      >
      >
      > HT(kinda)H =)
      >
      >
      >
      > Regards,
      >
      > Ian
      >[/color]

      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. Http://www.firstdbasource.com/donations.html
      :)

      Comment

      Working...