Thread: How to Crontab

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    141
    Rep Power
    12

    How to Crontab


    Hi,

    I want to use crontab to make daily backups of my mysql database.

    But, I donít want it to overwrite the old file.

    How do I auto number the files Iím creating ?

    Backup - mysqldump database_name -u user_name -ppassword > SQL_Back_XX

    Where xx will increment one after another.


    Thanks !

    Low.
  2. #2
  3. No Profile Picture
    GŲdelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    61
    This is really a Unix shell-scripting issue, not a database one, but one quick way to handle this would be to use dates:

    mysqldump database_name -u user_name -ppassword > SQL_Back_`date +%Y_%m_%d`

    Note: the single quotes in this are backquotes (the top left key over the Tab). This means that the command inside the quotes is executed, and the result is returned as a string. So, your backup files would look like

    SQL_Back_2003_08_05
    SQL_Back_2003_08_06
    SQL_Back_2003_08_07

    etc...

    You could also add minutes to this if you want several backups a day:

    mysqldump database_name -u user_name -ppassword > SQL_Back_`date +%Y_%m_%d_%M`

    There are many combinations you can do if you play with the date formatting options. Do a 'man date' for more info.
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    141
    Rep Power
    12
    Thanks, Helped a bunch.

    Originally posted by rycamor
    This is really a Unix shell-scripting issue, not a database one, but one quick way to handle this would be to use dates:

    mysqldump database_name -u user_name -ppassword > SQL_Back_`date +%Y_%m_%d`

    Note: the single quotes in this are backquotes (the top left key over the Tab). This means that the command inside the quotes is executed, and the result is returned as a string. So, your backup files would look like

    SQL_Back_2003_08_05
    SQL_Back_2003_08_06
    SQL_Back_2003_08_07

    etc...

    You could also add minutes to this if you want several backups a day:

    mysqldump database_name -u user_name -ppassword > SQL_Back_`date +%Y_%m_%d_%M`

    There are many combinations you can do if you play with the date formatting options. Do a 'man date' for more info.

IMN logo majestic logo threadwatch logo seochat tools logo