Results 1 to 3 of 3
  1. #1
    Join Date
    May 2005

    mySQL backup script & cronjob


    I've got no idea in the world about what I'm doing here, so seeking help from experts

    Our school runs a forum and is now too large to backup fully via phpmyadmin and I've been advised I need to create a "cronjob" and a "shell script" to create a mySQL backup of a database running off Plesk 7

    First time I had ever heard the word "cronjob" but was advised to seek help here

    So basically if anybody could help, what do I need to achieve a mysql database backup once a week on an early Sunday morning (in gzip format is preferred if possible) to output to a folder on our server called root/private

    Our database details are

    db - forum
    u - forumuser
    p - forumpass

    and it is in the path of

    in our Plesk panel there is a crontab tab - so assuming I would want for 3am Sundays (if I worked this out right)

    Minute 0
    Hour 3
    Day of the Month *
    Month *
    Day of the Week 0
    Command (command for the script I need?)

    So I think I have the "cronjob" part worked out (maybe?) - just need a "shell script" now to spit out the backup


  2. #2
    Join Date
    Feb 2004
    hai browne,

    here are differences in environment when you run a cron, and when you run a script while logged in. It's typically a stripped-down shell, with a minimal $PATH, etc etc.

    What I'd suggest doing is echoing everything that you're going to execute.
    So, when you have your exec, echo what is actually being exec'd and so on. It may be that it doesn't know where gzip is, etc. It's usually something minor that screws up the whole thing, that's hard to track down, but easy to fix.

    To spit out the database
    As an additional note, if you wanted all of the potential output from all streams (stdout and stderr rather than just stdout), use:

    */1 * * * * /usr/local/bin/php -f /kunden/homepages/33/d85254132/htdocs/SQLbackup.php > /path/to/log.txt 2>&1

    I agree with nalin that you should be using a shell script rather than PHP's exec function, since you're using the shell anyway with the exec function.

    Also, whenever you're calling a command, use the full path. If you're using mysqldump, then use /usr/local/mysql/bin/mysqldump, or whatever the path is. It can save a lot of trouble in the future.

    Bright Info Solutions

  3. #3
    Join Date
    May 2005
    Would this work as my script?

    outfile='/private/db-'`date +%m`'-'`date +%d`'-'`date +%y`'.tar.gz'
    mkdir /private/temp

    mysqldump -u forumuser -p forumpass --databases forum > /private/temp/forum.sql

    tar -czf $outfile /private/temp/*
    rm -rf /private/temp
    rm -f temptar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts