Find the answer to your Linux question:
Results 1 to 2 of 2
I put together a cron script for a clients server that is meant to create a MySQL backup with a date in the filename, then send it to a remote ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    2

    Smile Having trouble writing SQL cron script


    I put together a cron script for a clients server that is meant to create a MySQL backup with a date in the filename, then send it to a remote server. My problem is this, Cron keeps giving me errors. I have concealed the actual user folder for security on this forum.

    mySQL_backup
    ----------------------
    * Creating new backup...
    /home/user/test.sh: line 13: joomnew-2009-07-16.bz2: Permission denied
    mysqldump: Got errno 32 on write
    ----------------------
    Done
    Sending
    joomnew-2009-07-16.bz2: No such file or directory

    I am new to shell scripting. Can anyone explain how to fix these errors? The script is below:

    #!/bin/bash

    # modify the following to suit your environment
    export DB_BACKUP="/"
    export DB_USER="fakeuser"
    export DB_PASSWD="fakepass"

    # title and version
    echo ""
    echo "mySQL_backup"
    echo "----------------------"
    echo "* Creating new backup..."
    mysqldump -u $DB_USER -p$DB_PASSWD dbname | bzip2 > dbname-`date +%Y-%m-%d`.bz2
    echo "----------------------"
    echo "Done"
    echo "Sending"
    scp dbname-`date +%Y-%m-%d`.bz2 remotehost:./dbname-`date +%Y-%m-%d`.bz2
    exit 0


    Any help would be appreciated! Thanks!

  2. #2
    Just Joined!
    Join Date
    Jul 2009
    Posts
    58
    Most likely you need to specific another path for the outfile:

    Code:
    mysqldump -u $DB_USER -p$DB_PASSWD dbname | bzip2 > /tmp/dbname-`date +%Y-%m-%d`.bz2
    It's whatever directory the cron is running in that the script is trying to create the dbname-.... file in. Which is failing.

Posting Permissions

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