Welcome to Dagon Design. In addition to free scripts, WordPress plugins, and articles, we offer a variety of services including custom theme design, plugin creation, and PHP scripting. Contact me for more information.

Version 2.1   Updated Thursday, May 3rd, 2007 at 8:08am

Automatic MySql Backup Script

This script finds all of the MySQL databases on your server, individually backs them up (for easy recovery of specific data), compresses them, and stores the file in a specified directory and/or emails it to you. It has been updated since the initial public release and includes several new features.

I would like to thank Oliver Mueller for his many contributions to this release, including additional features, fixes, and testing. Thanks Oliver!

Download v2.1

  If you have found this page useful, please consider donating. Thanks!

Other versions

Page Contents

Change log

  • v2.1 (May 3, 2007)

    New option added to allow comma separated list of databases to exclude

  • v2.0 (September 27, 2005)

    Completely rewritten in PHP
    Config is now in separate file
    New logging and error system
    Log files are time-stamped
    Log files can be sent with backup email
    Error log can be emailed to alternate address
    Windows support (more info below)
    Can set max execution time for script
    Option to flush and optimize databases
    Can be executed from browser, cron job, etc..

  • v1.2 (March 30, 2005 – First public release)

    Written in Perl for Unix-based systems
    Automatically finds all of your MySQL databases
    Databases are backed up individually
    The backup files are compressed into a single file
    Backups can be stored on the server and/or emailed

Requirements

There are very few requirements for this script to function. You must of course have PHP. You will also need to supply the script with a username and password for MySQL so that it can extract the databases. It is best to use the root MySQL account so it will be able to perform a complete backup.

This script was originally written for Unix-based systems, but this new version will work on Windows platforms, provided that you make the required configuration changes, and have an acceptable zip and tar replacement (that can properly handle the command line parameters).

Installation

To install the script, just download the two files above, renaming them from .txt to .php. You can put them anywhere on your server, as long as they are together. Since the script is now in PHP you can even run it directly from your browser, although if you do, a password-protected directory is recommended.

Configuration

Before running this script, open up the configuration file – backup_dbs_config.php – and make the required changes. Most of the options do not have to be changed, but some are required for the script to function properly (such as the MySQL connection info).

The logging / error system

Two log files are created every time the script runs. The standard log and error log. What happens to them depends on your configuration.

When you are performing an email backup, the standard log will be placed inside the body of the message. The backup file will of course be attached to this message. You can also choose if the backup file and standard log are left on the server after emailing.

Error messages are still shown in the standard log, but the separate error log allows you to receive notification (to a separate email address) in case of error. This can be useful if you want errors sent to your primary account, while backups are sent to an alternate (that you do not check every day). That way you can always be aware of problems.

Manually running the script

Depending on your configuration and user permissions, you may have to run this script as root.

From the command line, you can type: php /path_to_script/backup_dbs.php

You can also run it directly from your web browser: http://www.domain.com/path/backup_dbs.php

Setting up a cron job

Once again, depending on your configuration and user permissions, you may have to be logged in as root to create a cron job.

type crontab -e and add a new line. Here is an example:

30 0 * * * php /root/scripts/backup_dbs.php

That will configure cron to run the script every day at 12:30 am. To learn more about cron jobs, you can visit this cron guide.

After adding the new line, save the file and exit. Cron may have to be restarted before it will recognize the new job. To do this, simply type:

/etc/init.d/crond restart

On certain servers, emails are sent out containing the output of cron jobs. If you would like to prevent this, you can add the following code to the end of your new cron job line:

> /dev/null 2>&1

If you add this code, do not forget to restart cron again before testing. That line only prevents email notifications after cron jobs execute. This will not effect the script’s log file options.

Final notes

This script has been tested extensively, but I take no responsibility for any damages caused by misuse, improper configuration, or differences in server configurations. If you have any questions or comments, feel free to post them below!

  1. 213
    Felipe

    Hi everybody,

    I have been able to successfully run the script from a web browser. But when running as a cron job in Plesk I get the errors below. Any idea on how to fix this?

    Many thanks.

    ==============================
    Executing MySQL Backup Script v1.4
    Processing Databases..
    sh: /mysqldump: No such file or directory
    DUMP FAILED

    DUMP FAILED

    sh: /nice: No such file or directory
    COMPRESSION FAILED

    COMPRESSION FAILED

    Archiving files..
    sh: /cd: No such file or directory
    FAILED
    ==============================

  2. 212
    Jason

    Argggghhhhhhhhhh!!!!!!!!!!!!!!!!!!1

    I have the script runing ok from cron BUT-
    Tar file created on first attempt was 25M. (strange as my DB is only small).
    Tar file created on second attempt just kept growing larger until it consumed all space on the server like it was the blob. Yup all 160Gb of it!!!!

    It is almost as if the Db backup just continues to repeat in endless loop? Strange tho that it wouldn’t have continued on the first attempt.

    I have flicked through all posts below however no one seems to have had this prob in the past. Is it a PHP version issue?

    Any help appreciated, I really want this to work out between us.

    p.s. I am using PHP 5.3 on Fedora 11

  3. Hi I am using xampp which has mysql where to place these both php file (backup_db_config, backup_db) files to take back up ….

    Appreciate your help
    Nagaraj

  4. Beautiful, Worked the first time with 0 troubles. Thanks!

  5. dont work code …

    Warning: mkdir(/db_backups): Permission denied in /home/.sites/16/site186/web/backup_dbs.php on line 155

    Notice: Undefined index: f_log in /home/.sites/16/site186/web/backup_dbs.php on line 85
    Backup directory could not be created in /db_backups

    Notice: Undefined index: f_err in /home/.sites/16/site186/web/backup_dbs.php on line 85
    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups

    help me pls ?

  6. Brad,
    Waht versions of PHP and Mysql are you using. I want to install the script on Windows and since yours is working, I would like to install a similar configuration. I am running Windows Server 2008 and IIS.

    Thanks

  7. 207
    Brad

    For those with the infamous zip error that don’t want to buy WinZip, here’s what I did:

    1) Installed 7-zip and added it to my path statement (c:\program files\7-zip)
    2) Modified the line “exec( “zip -mj $BACKUP_TEMP/$db.sql.zip $BACKUP_TEMP/$db.sql 2>&1″ , $output, $res );” to “exec( “7z.exe a $BACKUP_TEMP/$db.sql.zip $BACKUP_TEMP/$db.sql 2>&1″ , $output, $res );”
    3) Modified the line “exec(“zip -j -0 $BACKUP_DEST/$BACKUP_NAME * 2>&1″, $output, $res);” to “exec(“7z a $BACKUP_DEST/$BACKUP_NAME * 2>&1″, $output, $res);”

    It now uses 7-zip for compression and all is well. Now, I don’t know what level of compression it’s using here and for my needs I don’t really care. You may want to look into 7-zip command line options if you want to tweak the compression and save more space, but I’m just backing up a small wiki so I’m not that concerned.

  8. Anyone getting the mkdir() error: Just create those directories manually and set the directory permissions for write access.

    I was getting the mkdir() error, but the script works once I created the directories manually.

  9. 205
    William

    I get the same errors that Aaron posted.

    I’m running PHP 5.3.0.

  10. 204
    Aaron

    Hi,

    I tried your script but for some reason I keep getting errors! To start with I receive:

    Warning: mkdir() [function.mkdir]: Permission denied in New Folder/backup_dbs.php on line 156

    Notice: Undefined index: f_log in New Folder/backup_dbs.php on line 86
    Backup directory could not be created in /db_backups

    Notice: Undefined index: f_err in New Folder/backup_dbs.php on line 86
    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups

    When initially trying to run the script.

  11. Please note you need two dashes on the below parameters such as –skip-opt, this blog removed the first.

  12. I’ve been using this script for years, I love it. I get emailed a backup every 2 hours and added an FTP function so I have backups all over the place.

    Whoever asked for PHP5 support, I’m on PHP5 and it works fine. If you want OPP, well, that’s kinda silly and would be a waste of dev time.

    My server would freeze on the frontend for about 30 seconds. I worked out this is because mysqldump, by default, locks the tables. Since I had very large tables this meant anyone on my website had to wait for pages to load, and this was causing pretty massive server load.

    Go down to //dump db

    Change the first exec() to:

    exec( “$MYSQL_PATH/mysqldump $db_auth –skip-opt –quick –disable-keys –set-charset –create-options $db 2>&1 >$BACKUP_TEMP/$db.sql”, $output, $res);

    No more lag :) It’s the –skip-opt that does it.

  13. Check out this alternative, if your provider does not allow the use of the exec() function, which is essential for Dagon’s awesome script.
    http://gelb3.de/blog/?p=79

  14. Would be really great if you could add support for PHP5

    Thank you in advance!

  15. When email arrives, it contains the code from backup_dbs_config.php. Excatly word for word. So now backup file is created. This is the command line in corn jobs: php /home/xxxxxxxx/xxxxxxxxxx/db_backups/backup_dbs.php . So would like to know where I went wrong.

  16. thanks,

    i’ll try this scripts :)

  17. Vielen Dank für diesen Vorschlag. Ich schicke Dir einen Gruß aus Deutschland.

    Thanks for the suggestion. I send you regards from Germany.

  18. How to organize the automatic start of the script (I have a dedicated server and have the right root). Can I make this script backups several MySql databases?

  19. 195
    drucker

    This is an invaluable resource. Many thanks.

    Im a php novice and it took me hours (more than I care to count) to get the script working. I see some folks are also struggling. One key is found in comment #74 on/about page 5. Neglecting part B of Sean’s comment is a show-stopper and neglecting part A is almost as troubling (for example at/about lines 255,301,362,379,381). Also comment 97 is good and because Im hosted by godaddy, comment 136 was invaluable. Also I struggled with the mkdir error and found it best to make these directories manually; also comment out rmdir at end of the script — what’s the harm in letting it be? Im on unix, php5, mysql5 and happily report that this script is a gem, backing up my data daily.

    For my own benefit I must wonder why comment 74 is so little discussed when it seems so vital. Maybe its just me. Can someone shed a light?

  20. Hmm… I keep running into an error… I’m not sure what’s causing it. Any help?
    Well here is the error (the HTML didn’t parse 0_o).

    
    <br />
    <b>Warning</b>:  mkdir() [<a href='function.mkdir'>function.mkdir</a>]: Permission denied in <b>/home/disney5/public_html/forums/includes/cron/backup_dbs.php</b> on line <b>156</b><br />
    <br />
    <b>Notice</b>:  Undefined index:  f_log in <b>/home/disney5/public_html/forums/includes/cron/backup_dbs.php</b> on line <b>86</b><br />
    Backup directory could not be created in /db_backups
    <br />
    <b>Notice</b>:  Undefined index:  f_err in <b>/home/disney5/public_html/forums/includes/cron/backup_dbs.php</b> on line <b>86</b><br />
    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups
    

  21. 193
    elp

    while i try it with appserv ( XP pro sp2 ). then i got these message

    Warning: mkdir() [function.mkdir]: No such file or directory in C:\AppServ\www\cron\backup_dbs.php on line 160

    Notice: Undefined index: f_log in C:\AppServ\www\cron\backup_dbs.php on line 86
    Backup temp directory could not be created in /tmp/backup_temp

    Notice: Undefined index: f_err in C:\AppServ\www\cron\backup_dbs.php on line 86
    Backup temp directory could not be created in /tmp/backup_temp
    Backup temp directory could not be created in /tmp/backup_temp

    anyone could help me?

  22. 192
    jsherk

    Akshay… the date() part of it should NOT be in single quotes… it should look like this:
    $BACKUP_NAME = ‘mysql_backup_’ . date(‘Y-m-d’);
    Notice there are NO quotes on the outside of the date(), only around ‘mysql_backup_’ and around ‘Y-m-d’.

  23. 191
    naveen

    Executing MySQL Backup Script v1.4
    Processing Databases..
    Dumped DB: weberservices_co_in_ws
    Compressed DB: weberservices_co_in_ws
    Archiving files..
    FAILED
    tar: db_backups/mysql_backup_2009-07-28.tar: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now
    FAILED
    tar: db_backups/mysql_backup_2009-07-28.tar: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now

    *** ERRORS DETECTED! ***
    Check your email account naveennathtripathi@gmail.com for more information!

    There were errors!
    Emailing error log to naveennathtripathi@gmail.com ..

  24. 190
    Akshay

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in D:\wamp\www\backup\backup_dbs_config.php on line 43

    43. $BACKUP_NAME = ‘mysql_backup_’ . ‘date(“Y-m-d”)’;

    could antone help out me in resilving this?
    I am using WapServer.

    Akshay

  25. 189
    Joy

    Hi,
    My testlink is associated with Mamp since I am using Mac machine. I can’t find the backup files that this script would produce upon running it. I tried to find the backups in the db and temp folders from my Mamp but no backups that had been created.

    I really need help to fix this. If possible a step by step procedure to ensure the script will run correctly.. thanks!

  26. 188
    Krishna

    There is Cron Job which runs every day. All the logs will come to be through mail. Suddenly I am getting mails without any data in it. When I check for logs on server, they are of 0KB. What could be wrong? And how can I resolve this issue?

  27. This script was created about four years ago, and the last small change I did was two years ago. It still runs on my servers to this day, but i have not even looked at it in a long time. In other words, it is not really a top priority as far as updates are concerned, but hey, it is free to download! ;)

  28. Everytime I try to run the script I get this
    Warning: Unexpected character in input: ‘\’ (ASCII=92) state=1 in /home/gwauctio/public_html/backup program/backup_dbs.php on line 2

    Parse error: syntax error, unexpected T_STRING in /home/gwauctio/public_html/backup program/backup_dbs.php on line 2

  29. 185
    Raktri4u

    can any one make me sure that this script do locks the tables of the mentioned databases or not???
    thanks in advance
    Rak

  30. Thanks for the script works on one server but not on Centos, I get this

    more rackmonkey_mysql_backup_2009-04-10_1655.log
    2009-04-10 16:55:35: Executing MySQL Backup Script v1.4
    2009-04-10 16:55:35: Processing Databases..

    I dont see any db getting back up , i do see /tmp/backup_temp get created but no email or a back up file. Also I notice it does not leave a copy of the db on the server

  31. 183
    Daniel

    Great script but could not work on WAMP setup on Windows. I changed the parameters pointing to the mysql path etc and whenever i run the script, i get this error:-

    
    DUMP FAILED
    '..' is not recognized as an internal or external command,
    operable program or batch file.
    DUMP FAILED
    
    

  32. Hi,

    The mail is not working. I have Xampp hosted on a linux machine.

    Thanks

    Deepak Bhatia

  33. Works great, thanks for the invaluable resource.

  34. This is a nice script, although it should have better error handling.

    Unfortunately, you cannot run it on a Bravenet hosted web site because their internal security rules for virtual hosting accounts prevent the use of exec().

    That is not the fault of the script writer, it is an issue with Bravenet.

  35. Have any of you seen this before:

    Fatal error: Cannot redeclare writelog() (previously declared in C:\xampp\htdocs\backup\backup_dbs.php:80) in C:\xampp\htdocs\backup\backup_dbs_config.php on line 98

    thanks!

  36. 178
    chinthaka

    Hi i wanna backup ‘mysql’ data base to remote computer at the same network.So how can i do that?
    What shuld be the –>> $BACKUP_TEMP and $BACKUP_DEST path..?

    
    
    $MYSQL_PATH = 'C:\wamp\bin\mysql\mysql5.0.51b\bin';
    
    // Mysql connection settings (must have root access to get all DBs)
    $MYSQL_HOST = '192.168.xx.xx'; // Ip address of Mysql data base
    $MYSQL_USER = 'root';
    $MYSQL_PASSWD = 'root';
    
    // Backup destination (will be created if not already existing)
    $BACKUP_DEST ='what shuld be this path if i want to backup mysql database to remote computer';
    
    // Temporary location (will be created if not already existing)
    $BACKUP_TEMP = 'what shuld be this path if i want to backup mysql database to remote computer';
    
    

    Thank you..!!

  37. 177
    chinthaka

    Great JOB man….Really great……Thank you so much….

  38. First of all, this is an excellent script. Thank you for providing it to us free of cost.

    This script had been working without any errors for a year, but suddenly, it started giving this error.

    Executing MySQL Backup Script v1.4
    Processing Databases..
    Dumped DB: xxxxxx
    Compressed DB: xxxxxx
    Archiving files.. 
    Backup complete!
    Emailing backup to XXXXX@XXXX.XXX .. 
    <br />
    <b>Fatal error</b>:  Allowed memory size of 67108864 bytes exhausted (tried to allocate 23149108 bytes) in <b>/home/animorph/public_html/backup_dbs.php</b> on line <b>312</b><br />

    The database has a size of 55 MB, if it’s of any use.

  39. 175
    Rob

    Hi, this script is fantastic! Works like a charm.. Thank you so much..

    I’m just wondering if it locks the db while it’s backing up? I wanted to set up a cron for 1:30pm to catch any changes made in the morning but don’t know if it will cause any problems to updates that are being made?

    Thanks again!

    Rob.

  40. Just a reply to a few of the previous comments.

    To BloggerSavvy .. dont run the script with the configured ‘root’ username.. change this to the username/password that you have given rights to your databases to be backed up (a mysql user).

    To fashionsjamaica .. those directories need to be world writable (ie. 777) ie. the db_backups directory and the tmp / backups directory (cant remember the other ones name off the top of my head). I precreated my dirs and made them 777.

    And to the script author.. thanks HEAPS for this script. I implemented this after the one I was running previously kept failing and running into memory errors (even though I was overriding php’s memory limit).
    This one works like a charm and even better than my previous one did. I use this to email all my databases to my gmail account.. using a gmail account to receive your databases is a great form of backups.

    Gmail can accept up to 20 meg attachments.. we have a forum with 10,000 posts (35meg database..) that compresses down to 4megs.. so we’ve still got a while before I need to work out a better backup solution. (and even then I’ll probably still use this script and then automate the ftp to elsewhere).

    I like to run multiple versions of this script each configured with different mysql database users that only have privileges to specific databases so I get them individually emailed to me and not all databases in one hit (because I’m doing the email thing).

    Thanks again.

    Paul

  41. I am getting this error: http://fashionsjamaica.mc-dollar.net/db_backups/backup_dbs.php

    Warning: mkdir() [function.mkdir]: Permission denied in /home2/fashions/public_html/db_backups/backup_dbs.php on line 156

    Notice: Undefined index: f_log in /home2/fashions/public_html/db_backups/backup_dbs.php on line 86
    Backup directory could not be created in /db_backups

    Notice: Undefined index: f_err in /home2/fashions/public_html/db_backups/backup_dbs.php on line 86
    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups

  42. 172
    Daniel

    is there a solution for SMTP mailing (with user/pw needed) instead of standard phpmail?
    my hoster only allows smtp with authentification…

    thanks in advance for your help!

  43. This script does not work using ‘root’ (on php5 server). Additionally, most web servers do not allow access permissions of ‘root’ to gain access to all databases on the server.

    Does anyone have a fix for this? (I don’t think I messed anything up in configurations etc. When manually running the script (via ssh), ‘root’ is simply denied access.

    Thank you!

  44. 170
    Divyang

    Very nice job….
    Thanks a lot….

  45. 169
    jonathan

    i would like to know if Scooter is right and the script doesn’t work with php5

  46. Ran this using php 4… works perfectly

    My hosting company uses php5… tried the switch and it does not work….

    Question :

    Is there a way to make this compatible for the latest version of php, if so how can this be accomplished..?

    Thank you for your time.

  47. arjen, and others. I’m too using Windows and had the infamous ‘Zip’ error.

    I can only speak from my experience of Winzip 12, but it appears winzip no-longer support command-line functions as standard, you have to download the ‘WinZip Command Line Support Add-on’ that only supports the ‘Standard’ & ‘Pro’ versions (so you have to pay). Once you’ve installed WinZip 12 & the Command Line Add-on you will still get the error….you have to copy the file ‘WZZIP.EXE’ to both the directory the script resides in AND the temp file that your backups are created in.
    You then have to change a couple of lines of code in the script to tell it to stop using the command ‘ZIP’ and start using ‘WZZIP’ (the code is set to always use ‘ZIP’ for windows systems regardless of what you put in the $COMPRESSOR variable:

    
    Line 221 changes to:
    exec( "wzzip $BACKUP_TEMP/$db.sql.zip $BACKUP_TEMP/$db.sql 2>&1" , $output, $res );
    
    Line 256 changes to:
    exec("wzzip $BACKUP_DEST/$BACKUP_NAME * 2>&1", $output, $res);
    

    That will get the code working with winzip the first time you run it, however, at the end of the script it tidies up the temp directory, so you’ll need to tell that bit of the script to NOT delete the ‘WZZIP.EXE’ you just put there (probably a better way of doing this but this worked so meh):
    
    Line 377 changes to:
    if (!is_dir($file) AND $file != 'WZZIP.EXE') {
    

    I hope this helps anyone else with this problem.

    P.S. Great script, thank you so much, saved me a lot of time writing my own :D

  48. 166
    Steve

    Nice work, thanks

  49. 165
    Steve

    Does anyone know what to put for the $MYSQL_PATH variable if you’re being hosted on bluehost.com?

  50. 164
    Jason

    I’m using this only for the e-mail function, but am having an issue. It dumps the db and compresses with no issue, then says it is e-mailing to the address I specified, but I never get an e-mail. I have it set to delete after e-mailing, but upon checking via FTP, the backup files are still there (the tar is around 7 MB). However, it works fine with my smaller database. I’m sure this is an issue with the server (memory limit of some kind) and not the script, but is there anything I can do? This is a webserver, and not a server that I have shell access to or anything.

  51. 163
    Bob

    Using this script is it possible to turn off the compression and just get the .sql file dump instead?

  52. thanks its real good script

  53. You sir, are a lifesaver, I was halfway in, writing my own script before I found yours. Thanks for saving me a weeks worth of work!

  54. 160
    antialiasis

    Does this script work on IIS (with PHP and MySQL installed, obviously, but still IIS)?

  55. Only one thing to say, thanks a lot for all your scripts and WP plugins, you only made great, clean and usefull scripts ;)
    Thanks again for all your free work !

  56. 158
    Jack

    Man, I love you. I’m not gay but I really love you !

  57. 157
    arjen

    Hi all,

    I am installing this script on a W2k3 box.
    Everything seems fine exept the infamous “ZIP is not recognized as an internal or external command…” error.
    I have included ZIP in the PATH: (C:\Program Files\WinZip\WINZIP32.EXE)

    The config is like this:

    // Path to the mysql commands (mysqldump, mysqladmin, etc..)
    $MYSQL_PATH = ‘C:\MySQL\bin’;

    // Mysql connection settings (must have root access to get all DBs)
    $MYSQL_HOST = ‘localhost’;
    $MYSQL_USER = ‘root’;
    $MYSQL_PASSWD = ”;

    // Backup destination (will be created if not already existing)
    $BACKUP_DEST = ‘E:\80\backupdbs\db_backups’;

    // Temporary location (will be created if not already existing)
    $BACKUP_TEMP = ‘E:\80\backupdbs\tmp\backup_temp’;

    // Show script status on screen while processing
    // (Does not effect log file creation)
    $VERBOSE = true;

    // Name of the created backup file (you can use PHP’s date function)
    // Omit file suffixes like .tar or .zip (will be set automatically)
    $BACKUP_NAME = ‘mysql_backup_SCE’ . date(‘Y-m-d’);

    // Name of the standard log file
    $LOG_FILE = $BACKUP_NAME . ‘.log’;

    // Name of the error log file
    $ERR_FILE = $BACKUP_NAME . ‘.err’;

    // Which compression program to use
    // Only relevant on unix based systems. Windows system will use zip command.
    $COMPRESSOR = ‘bzip2′;

    Does anyone have any idea what to correct?

    Thanks in advance

  58. If you run manually from your browser you may find that you don’t have permission to write the directories in root /db_backups etc.

    If this is the case simply create db_backups amd tmp/backups_temp in the directory that the script is sitting. Be sure to chmod 777 them too.

  59. I have excluded from de databases a couple that i dont need, but i get the backup from those and from information_schem..

  60. Hi,

    I believe that I have the script set up correctly but I am having no success with it. Nice was not installed on the server so I have installed that. However, when the script is executed it is generating the following errors (one for each database):

    > Processing Databases..
    > sh: /mysqldump: No such file or directory
    > DUMP FAILED
    >
    > DUMP FAILED
    >
    > sh: /nice: No such file or directory
    > COMPRESSION FAILED
    >
    > COMPRESSION FAILED

    (Repeated 10 more times – presumably one for each database)

    and finishing up with:

    Archiving files..
    sh: /cd: No such file or directory
    FAILED

    FAILED

    *** ERRORS DETECTED! ***
    Check your email account ************** for more information!

    Emailing backup to ******************* ..
    PHP Warning: file_get_contents(): Unable to access /root/db_backups/mysql_backup_2008-08
    -12.tar in /root/scripts/backup_dbs.php on line 303
    PHP Warning: file_get_contents(/root/db_backups/mysql_backup_2008-08-12.tar): failed to
    open stream: No such file or directory in /root/scripts/backup_dbs.php on line 303

    There were errors!
    Emailing error log to *************** ..
    qmail-inject: fatal: unable to parse this line:
    From: ************>MIME-Version: 1.0
    FAILED to email error log.
    FAILED to email error log.

    (Despite the last few lines I am receiving an e-mail with the errors and an attached .tar file of 0 bytes).

    I am running under Plesk which seems to be problematical for some.

    Any help would be appreciated.

  61. Dear all,

    Could you please take a look http://saigon.whodigital.com/demo/bk/backup_dbs.php

    I give below error – do you have any idea for helping?

    Executing MySQL Backup Script v1.4
    Processing Databases..
    DUMP FAILED

    DUMP FAILED

    COMPRESSION FAILED
    zip warning: name not matched: C:\tmp/blog.sql

    zip error: Nothing to do! (C:/tmp/blog.sql.zip)
    COMPRESSION FAILED
    zip warning: name not matched: C:\tmp/blog.sql

    zip error: Nothing to do! (C:/tmp/blog.sql.zip)
    DUMP FAILED

  62. I too am having a issue with the zip portion on Windows. Winzip is installed on the server and included in the path. No matter what I try in the config or backup php I receive the messager ‘zip’ is not configured and an internal or external command.

  63. I manage to get it work, but now is the zip problem..I installed winzip but still have problem, is there a solution for this?

    appreciate for any help.

  64. I using wampserver, these are the error. Can any one help me on this?

    Warning: mkdir() [function.mkdir]: No such file or directory in D:\wamp\www\autobackup\backup_dbs.php on line 160

    Notice: Undefined index: f_log in D:\wamp\www\autobackup\backup_dbs.php on line 86
    Backup temp directory could not be created in /tmp/backup_temp

    Notice: Undefined index: f_err in D:\wamp\www\autobackup\backup_dbs.php on line 86
    Backup temp directory could not be created in /tmp/backup_temp
    Backup temp directory could not be created in /tmp/backup_temp

  65. 149
    Devin

    Executing MySQL Backup Script v1.4
    Processing Databases..
    DUMP FAILED
    sh: tmp/backup_temp/agp.sql: Permission denied

  66. 148
    Michael

    This is a great script, thanks. I wanted to be able to auto delete old versions of the file, so I googled and found / modified this script to help me. I also execute your script inside of this.

    #!/bin/bash
    ## RSFBS – Really Simple File Backup Script by DaiTengu.
    ##

    ## Variables go here!
    # General base backup directory, All the subdirectories will be
    # created under here.
    scriptdir=/var/www/scripts

    #Execute php backup of mysql db
    php $scriptdir/backup_dbs.php

    basedir=/var/www/db_backups

    # Let’s name our backup file, the date will be appended to this
    backupname=mysql_backup_

    # How many backups do we want to keep? This should be in the format
    # days, weeks, months, etc. Example: keep=”7 days”
    keep=”7 days”

    # Some stuff to properly name the files
    suffix=$(date +%F)
    olddate=$(date –date “$keep ago” +%F)

    ## Delete the old tar file!
    if [ -e $basedir/$backupname$olddate.tar ] ; then
    echo “Deleting old tar file…”
    rm -rf $basedir/$backupname$olddate.tar
    fi

    ## Delete the old log!
    if [ -e $basedir/$backupname$olddate.log ]; then
    echo “Deleting old log…”
    rm -rf $basedir/$backupname$olddate.log
    fi

    ## Oh hay! We’re all done! Let’s clean up and exit gracefully!
    echo “Done!”
    exit 0;

  67. 147
    Mai

    Getting this error. Any advice?

    Warning: mkdir(/db_backups) [function.mkdir]: Permission denied in MY URL on line 156

    Notice: Undefined index: f_log in MY URL on line 86
    Backup directory could not be created in /db_backups

    Notice: Undefined index: f_err in MY URL on line 86
    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups

  68. 146
    rolance

    For the previous windows XP users who reported the error: “zip is not recognized as an internal or external command,operable program or batch file” – the problem is either that you do not have zip.exe installed on your system (you will have to hunt it down) or you have zip but have not configured your path environment variable to make it accessible from the update php script. This is a nice script for unix users, but it doesn’t work ‘out of the box’ on windows and will take quite a bit of hacking, so newbies might want to move on.

  69. 145
    Ayuk Rolannd

    Thank you very much for the script this is wnat I have been looking for all day long, but i seen to have some errors in making the script work
    I am using Xampp install on windows so I want I have the following error trying to make the script backup my database automaticaly.

    DUMP FAILED
    ‘C:\Documents’ is not recognized as an internal or external command,
    operable program or batch file.
    DUMP FAILED
    ‘C:\Documents’ is not recognized as an internal or external command,
    operable program or batch file.
    COMPRESSION FAILED
    ‘zip’ is not recognized as an internal or external command,
    operable program or batch file.
    I don’t know how to go about this please try to help me i am new in
    database administration

  70. Thank you very much for the script…
    I keep getting this error…

    Warning: mysql_list_dbs() [function.mysql-list-dbs]: Unable to save MySQL query result in /data/13/1/112/58/1275710/user/1361670/htdocs/mysqldump/backup_dbs.php on line 187

    Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /data/13/1/112/58/1275710/user/1361670/htdocs/mysqldump/backup_dbs.php on line 189

    Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /data/13/1/112/58/1275710/user/1361670/htdocs/mysqldump/backup_dbs.php on line 241
    Archiving files..
    FAILED
    tar: db_backups/mysql_backup_2008-05-17.tar: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now
    FAILED
    tar: db_backups/mysql_backup_2008-05-17.tar: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now

  71. 143
    Miles

    Hi Excelent but cant get it to work, it reports all db’s backed up & compressed it even sends the email witht he attached zip file. when i open the file though it is empty. i have tried adjusting the config file as follows:
    // Path to the mysql commands (mysqldump, mysqladmin, etc..)
    $MYSQL_PATH = 'C:\Program Files\MySQL\MySQL Server 5.0\bin';

    still the same empty zip file although all reports sucessful backup. is there anything else i can try?

  72. 142
    Paul

    Thanks for the script. It was working fine for me on two different servers. However, after updating the script to the most recent version on one of the servers I get

    Warning: Cannot modify header information – headers already sent by (output started at /home/***/public_html/****/backup_dbs.php:1) in /home/***/public_html/***/backup_dbs.php on line 131

    Warning: Cannot modify header information – headers already sent by (output started at /home/****/public_html/***/backup_dbs.php:1) in /home/****/public_html/***/backup_dbs.php on line 132

    Errors.

    Any ideas why?

  73. Hi, first of all thank you for creating this script!

    I’ve succeeded installing your script. When I ran it; the backup file was created successfully although i saw error message as follows:

    
    Failed loading /usr/local/IonCube/ioncube_loader_lin_5.2.so:  /usr/local/IonCube/ioncube_loader_lin_5.2.so: cannot open shared object file: No such file or directory
    

    Do i really need this IonCube?

    Thanks before.

  74. Hi Guys,
    Love this script but im having one issue. See below
    Im using a windows xp machine with winzip installed

    Dumped DB: mainzpanel COMPRESSION FAILED ‘zip’ is not recognized as an internal or external command, operable program or batch file. COMPRESSION FAILED ‘zip’ is not recognized as an internal or external command, operable program or batch file. Emailing mainzpanel backup to

  75. If you are getting the following error and error log will not show anything else …
    “2007-10-24 03:10:02: Executing MySQL Backup Script v1.4
    2007-10-24 03:10:02: Processing Databases..”

    you need to install php5-mysql package.
    Ubuntu you can do so by running the following command:

    for PHP5

    
    # sudo apt-get install php5-mysql   
    

    for PHP4
    
    # sudo apt-get install php4-mysql   
    

    Now everything works so cool … thx for such a cool utility.

    Dash

  76. –> M. Keijzer

    It seems that you *might* need to verify User/Group permissions.

    Check that ‘apache’ (or whatever user and/or group used by your web server) have WRITE permission on the sub-folder(s) you configured.

    You may also need WRITE permission for this user / group on the root or main folder, since sub-folders are created if non-existent.

    I’m not sure about Windows 2003 but I had the same issue running on Cent OS 5.1 and after fixing permissions everything works perfectly.

  77. I use the backup-script on Windows Server 2003 with PHP and MySQL.
    I created the directory’s, it does write a log-file, but is doesnt’t write the backup-files.
    What do I have to configure?

    Of course on my Ubuntu-Linux testing-server it works perfectly…

  78. For anyone using GoDaddy with php 5.0 and MySQL 5. This is the path needed for mysql commands (mysqldump, mysqladmin, etc..)

    $MYSQL_PATH = ‘/usr/local/mysql-5.0/bin’;

  79. 135
    daniele

    hi,
    i’m trying this script but i experienced this:

    The server encountered an internal error or misconfiguration and was unable to complete your request.
    
    Please contact the server administrator, postmaster@site.it and inform them of the time the error occurred, and anything you might have done that may have caused the error.
    
    More information about this error may be available in the server error log.

    what happen?

    thanks a lot, daniele.-

  80. thanks, its great, i added hours/minutes to the filename so that it doesnt overwrite the older file from the same day (useful for reverting to eariler DB from that day)

    $BACKUP_NAME = ‘mysql_backup_’ . date(‘Y-m-d_Hi’);

    Thanks!

  81. 133
    Omid

    Hi again
    Now I have this error:

    Warning: mkdir() [function.mkdir]: No such file or directory in /home/user/public_html/mydb/backup_dbs.php on line 156

    Notice: Undefined index: f_log in /home/user/public_html/mydb/backup_dbs.php on line 86
    Backup directory could not be created in home/user/export_mu

    Notice: Undefined index: f_err in /home/user/public_html/mydb/backup_dbs.php on line 86
    Backup directory could not be created in home/user/export_mu
    Backup directory could not be created in home/user/export_mu

    Could you please tell me what`s exact reason of above error ?
    I couldn`t find my answer in other comments :(

  82. 132
    Omid

    Hi
    Warning: exec() has been disabled for security reasons in /home/name/public_html/mydb/backup_dbs.php on line 219
    How could I modify above warning ?

  83. 131
    X.A.

    Works like a charm!

  84. I had hoped that this script would be my saviour, but despite my best efforts I cannot get it to work – purely because of the site I am running it on using PLESK which does not allow me to change database user permissions or to run as root user (despite it being a dedicated box).

    All I get is:

    
    Executing MySQL Backup Script v1.4
    Processing Databases..
    DUMP FAILED
    
    DUMP FAILED
    
    COMPRESSION FAILED
    
    COMPRESSION FAILED
    
    Archiving files.. 
    FAILED
    
    FAILED
    
    
    *** ERRORS DETECTED! ***
    Check your email account *************** for more information!
    
    
    Emailing backup to *************** .. 
    
    There were errors!
    Emailing error log to *************** .. 
    FAILED to email error log.
    FAILED to email error log.
    

    I tried using username root and the password I have for SSH access but that doesnt work either. If anyone can give me any pointers I really would appreciate it.

    I have no doubt that I’ll be using the script on other sites, its just a shame that I cannot get it to work on the one site I needed it on :(

  85. wow.. i was lost in a world of pearl and bashings.. and this script did the work, right off the bat.. thanks a million.

  86. 128
    Karl Roos

    Strange :S
    I get this..

    Warning: mkdir() [function.mkdir]: Permission denied in /home/web28141/domains/roosstudios.com/public_html/Backup/backup_dbs.php on line 156

    Notice: Undefined index: f_log in /home/web28141/domains/roosstudios.com/public_html/Backup/backup_dbs.php on line 86
    Backup directory could not be created in /db_backups

    Notice: Undefined index: f_err in /home/web28141/domains/roosstudios.com/public_html/Backup/backup_dbs.php on line 86
    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups

  87. Thanks for this brilliant script!

    I’ve set it up so it backs up to the server daily and emails me a backup weekly :)

    Martin

  88. 126
    Rafaiel Sabatini

    what will be $MYSQL_PATH in windows. Could you please give an example.Thanks

  89. When I manually run the script, This is what I get to see:

    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups

  90. 124
    Tim

    I am running a MySQL DB backup script. The script has been working fine for 1-2 weeks. However, it is getting an error today.

    PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 15288321 bytes) in /home/[deleted]/public_html/[deleted]/backup_dbs.php on line 305

    Here is the code that causes the error.

    $data = chunk_split(base64_encode(file_get_contents($BACKUP_DEST.’/’.$BACKUP_NAME)));

    Do you think it is the way the code that is written can’t handle the growning DB? The memory that it tries to allocate does increase with each failed script execution.

  91. Bump on Post 119. I also would like some information on the EXLUDE_DB function. Otherwise the script works just fine (it backs up my DB:s too a Gmail account, thanks Google for 6 GB storage!).

  92. 122
    yehsay

    I am looking to install this on my Mac OS X Server and was wondering if it works? I have installed it but am receiving this error “2007-11-27 15:41:12: DUMP FAILED
    mysqldump: Got error: 1045: Access denied for user ‘root’@'172.25.64.227′ (using password: YES) when trying to connect”

    My web server has 2 IPs that it is running, how can I limit it to the the other IP. Also, when I manually run the script, my .sql files are 0kb in size. Am i doing something wrong here. Please assist. Thank you.

  93. 121
    Jasper

    Never mind my comment, I just couldn’t figure the odd way the messages are ordered. (from down to up, yet from 1 to 8 – I expected either from up to down, from 1 to 8 or down to up, from 8 to 1. I saw from down to up and falsely concluded it would be from 8 to 1.)

  94. 120
    Jasper

    I had that very, very same errors. CHmodding to 777 helped, though.

    The solution to create the folders already worked as a temporary solution for the first error thrown – it gave me the second error Henry posted. After CHModding the both folders to 777, the script ran without any errors.
    The script deletes the temporary directory however, so creating the directories already is not going to be any step towards a permanent solution.

  95. I would like to use the “Exclude” function, but for some reason, it is not excluding any database. I have the excluded databases listed with a “,” and space in between databases. Is there another way to list then, like with no space between the “,” and next database name? Also, it backs up the “information_schema” database.

    Any ideas on what is or what I am doing wrong? Other than this, it works fine. But I do not want all databases emailed.

    Thanks.

  96. ok i have a strange problem
    i have installed the script and if i run it from IE or firefox it works a treat but if i run it as a cron job it seems to just hang all i get in the log is

    "2007-10-24 03:10:02: Executing MySQL Backup Script v1.4
    2007-10-24 03:10:02: Processing Databases.."

    and nothing else
    the error file is blank
    so it appears the the cron job is starting the script ok but it just doesnt seem like the script will complete
    any idea’s?

  97. I just wanted to tell you a BIG THANK YOU for creating this script.
    It was a real help for me as I have a slow internet connection and its a real pain in the head to manually download those big backups.

  98. Hi I am try desperatley to get your script working. I have set the permissions of the directory and the 2 files to 777, however I still keep geting the following messsage on the screen when I try running it: A file permissions error has occurred. Please check the permissions on the script and the directory it is in and try again. Have you got any ideas for me thanks

  99. 115
    mike

    and what i mean by that (the breaking up files) is not doing each sql separately, but to where it will take a set size, and break the zip files up into those sizes and email each part as a separate email.

    as to the second part, i have a few directories that i need to have backed up with the databases, as they are interlinked (basically the site if you upload a file, will put it in the db (the page reference) and save it to a directory)

  100. 114
    mike

    2 things, is there a way to have it break up zip files (windows) and email the sections separately, as the files can become VERY large, and 2, is there a way to tell it to backup directories and make them part of the backup?

  101. 113
    Jonny

    I had the same problem reported below with the creation of the backup directory failing.

    I fixed it by specifying the full path to where I wanted the backup directory. So if you want them in the directory the backup script is stored, change the path in config to the same path as is shown in the error message (less the backup_dbs.php bit).

    So for:

    /home/chs/calellabarcelona.com/home/html/admin/backup/backup_dbs.php

    Set the backup path in config to:

    /home/chs/calellabarcelona.com/home/html/admin/backup/

  102. @Geo: do you have ‘exec’ function enabled in PHP? If not, this script won’t work…

    I like this script, but I have a problem when restoring the backup: phpMyAdmin returns ‘error in your SQL syntax’. If I do manual backup with phpMyAdmin and restore that, it works. Any ideas?

  103. This seems like it’ll do it but my problem is that it never creates any output at all. It creates the log file and it says it dumped the databases but NADA….
    I need to use gzip since I don’t have tar. I’m on a novell server so I am a little bit uncertain about the paths but since it creates the log file it should be ok.
    I also get the download page, and I don’t know why…..
    Anybody got a clue?

  104. Hi. Thank you very much for a useful code. I have installed it, and have tested it by running the php files from browsers IE (Internet Explorer), Opera and Firefox. The program works fine in Opera and Firefox, and the following code is reported on the screen:

    Executing MySQL Backup Script v1.4
    Processing Databases..
    Dumped DB: XYZ
    Compressed DB: XYZ
    Archiving files..
    Backup complete!

    However, when running from IE the job is being done (DB backup is created), but suddenly an error message appears in the IE browser:

    Internet Explorer can not download backup_dbs.php from http://www.cosmotorg.net.

    Why is the program causing IE to try to download anything at all? It shouldn’t be necessary. The progress should be reported on the screen, as it happens in Opera and Firefox.

  105. Will this script work on a 200MB DB in phpadmin, the .sql backup file is a little over 300MB? If so would it need any changes different than your instructions?

    Of course I do not want the backup e-mailed to me. :-)

    Thank You for your time!
    David

  106. 107
    Mathias

    I am having the exact same problem as Gabi (#106).

    Exact message is:

    <br />
    <b>Warning</b>:  mkdir(/db_backups): Permission denied in <b>/hsphere/local/home/mjcraig/bluenetwork.org/DB_Backup/backup_dbs.php</b> on line <b>156</b><br />
    <br />
    <b>Notice</b>:  Undefined variable:  f_log in <b>/hsphere/local/home/mjcraig/bluenetwork.org/DB_Backup/backup_dbs.php</b> on line <b>86</b><br />
    Backup directory could not be created in /db_backups
    <br />
    <b>Notice</b>:  Undefined variable:  f_err in <b>/hsphere/local/home/mjcraig/bluenetwork.org/DB_Backup/backup_dbs.php</b> on line <b>86</b><br />
    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups
    

  107. 106
    Gabi

    Hi all,

    I’ve installed and configured but have a permission error in mkdir. Then i have created the directory and do 777 perms but have the same result:

    Warning: mkdir() [function.mkdir]: Permission denied in /home/chs/calellabarcelona.com/home/html/admin/backup/backup_dbs.php on line 156

    Notice: Undefined index: f_log in /home/chs/calellabarcelona.com/home/html/admin/backup/backup_dbs.php on line 86
    Backup directory could not be created in /db_backups
    Notice: Undefined index: f_err in /home/chs/calellabarcelona.com/home/html/admin/backup/backup_dbs.php on line 86
    Backup directory could not be created in /db_backups Backup directory could not be created in /db_backups

  108. Muner: Here are some instructions for importing a database using PHPMyAdmin:

    http://www.modwest.com/help/kb6-335.html

  109. 104
    Muner khan

    how can i restore the back like i m using php interface n want to back n restore from php interface ..i have done creating db dump..but dont know how to recover it ..
    please help needed

  110. 103
    Emerson

    Is it possible to add something at the end of the script to delete yesterday’s backup file and log?

    Thanks ;)

  111. Bill: I have only used this on a few different servers, all of which I had root access to. The only other thing you can do, is in your control panel, where you assigned your user to your database, is make sure you have all permissions allowed, including lock tables. If you cannot do this, your host might be able to set it for you. Otherwise, you may not be able to use this script, as the locking is done by the command that actually dumps the dbs, and I am not aware of a way to bypass it since it needs exclusive access to the db to do it.

  112. I got a response that informed me the problem is the permissions available on shared hosting accounts, the do not allow the locktable command to be used.”

    Is there a solution to this as it seems that you need to “own” the box you are trying to use this script on. I do not have root access since it is a shared hosting environment.

    I would still like to use this script if it is possible.

    Bill

  113. This is on a shared hosting environment. I can log into phpMyAdmin with the exact same user/pass combo to manage my db’s and I can export via the interface. My host said to try localhost.localdomain.

    Your thoughts?

  114. Bill: It sounds like a permission error. Have you tried with the root mysql login?

  115. I have figured out the fodler issue by having to type the entire path, but I am confused as to the below error.

    2007-05-06 10:38:37: Executing MySQL Backup Script v1.4
    2007-05-06 10:38:37: Processing Databases..
    2007-05-06 10:38:37: DUMP FAILED
    mysqldump: Got error: 1044: Access denied for user ‘USERNAME_GOES_HERE’@'localhost’ to database db_name_goes_here_-officials’ when using LOCK TABLES
    2007-05-06 10:38:37: Compressed DB: db_name_goes_here_-_officials
    2007-05-06 10:38:37: Archiving files..
    2007-05-06 10:38:37: Backup complete!
    2007-05-06 10:38:37: *** ERRORS DETECTED! ***
    Check your email account $$$@$$$$$.$$$ for more information!
    2007-05-06 10:38:37: There were errors!
    2007-05-06 10:38:37: Emailing error log to $$$@$$$$$.$$$ ..

  116. It’s worth pointing out that I was having a fair bit of trouble with the script at first. It was failing to create the tar file. I thought it was a permissions issue at first, but then realised that my system didn’t support bzip2. I changed it to gzip and it works a treat now – thanks!

  117. Version 2.1 has been released. It includes a new option, which allows you to specify a comma separated list of databases to exclude from the backup.

  118. Jak: From the error message, it sounds like it is using too much memory. Perhaps the amount of memory PHP is set to use is too low for the size of your databases. You would have to ask your host about that one.

  119. [...] backup: Here is a great site that will allow for auto backup of your SQL database. There is even an option to [...]

  120. I received the following error message from an email that was sent from the script:

    Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to
    allocate 10158081 bytes) in /home/net/dbback/backup_dbs.php on line
    294

    What does the error means and how can I fix it.

    The script is set to email me the backup file. I see the backup (tar) file that was to be sent im the db_backups directory. The error log file in the same directory is empty.

  121. file_get_contents(c:/db_backups/mysql_backup_2007-03-06.zip) [function.file-get-contents]: failed to open stream: No such file or directory in C:\AppServ\www\backup\backup_dbs.php on line 293

    any ideas?

  122. when I ran the script I get the error :

    Compressed DB: balonlac_arkamarka
    Archiving files..
    FAILED
    tar: db_backups/mysql_backup_2007-03-06.tar: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now
    FAILED
    tar: db_backups/mysql_backup_2007-03-06.tar: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now

    ok, here is the part I couldn’t get;
    in the tmp folder I have a file called
    balonlac_arkamarka.sql.bz2
    (so this part works fine, and have the files in zip)
    and in the backup folder I have a file called
    mysql_backup_2007-03-06.log
    (this shows that folder is accsesible by the script)
    but I got the error. In the time being it is ok but’m planning to set up a cron job, so I’ve to fix it but couldn’t find where the problem is.
    (by the way there was a comment look like this one but this is not the same case)
    thanks …

  123. Phillip: See comment 86.

  124. Hi,

    I’ve just configured and uploaded the two files.

    When i navigate to the path in my browser i am given the following error message:

    Warning: mkdir() [function.mkdir]: Permission denied in /websites/LinuxPackage03/fa/nc/yd/fancydressretail.co.uk/public_html/backup_dbs.php on line 155

    Notice: Undefined index: f_log in /websites/LinuxPackage03/fa/nc/yd/fancydressretail.co.uk/public_html/backup_dbs.php on line 85
    Backup directory could not be created in /db_backups
    Notice: Undefined index: f_err in /websites/LinuxPackage03/fa/nc/yd/fancydressretail.co.uk/public_html/backup_dbs.php on line 85
    Backup directory could not be created in /db_backups Backup directory could not be created in /db_backups

    The section where i’m not sure what to put in the config is the $MYSQL_PATH = ‘/usr/bin’; as i am not sure where i need to look to find and alter this path.

    If anyone could let me know how to go about this it woulb be appreciated.

    Many Thanks

  125. Igor: mysqldump is not part of php – It is the program used to dump the contents of mysql databases. You might have to search your server for the location of it.

  126. Hi list,

    I’d LOVE to get this script in plcae on my host!

    I keep getting the same error as Brian (post number 20). Mye error shows:

    2007-02-27 08:28:13: DUMP FAILED
    sh: line 1: /usr/bin/mysqldump: No such file or directory

    So, I need to change the directory in my script config-file but I don’t know to which location? Would a ‘phpinfo’ help to get that info? (mine can be found at http://www.bmwboxersupplies.com/tmp/phpinfo.php)

  127. Paul: It looks like the main problem is those permission denied errors. It causes a chain reaction making the rest of the script fail. Are you running the script as root? Does the root user account have access to the mysql root account?

  128. Hi,Sorry to trouble you but I am experiencing a slight problem. When I run the script, the backup file seems to make it as far as the tmp/backup_temp folder and the two logs are producced in the backups folder. However, I am still receiving an error message (below) and would be really grateful for any advice please.

    Executing MySQL Backup Script v1.4 Processing Databases.. Dumped DB: db139096744 COMPRESSION FAILED nice: tmp/backup_temp/db139096744.sql: Permission denied COMPRESSION FAILED nice: tmp/backup_temp/db139096744.sql: Permission denied Archiving files.. FAILED tar: backups/pco_backup_2007-02-26.tar: Cannot open: No such file or directory tar: Error is not recoverable: exiting now FAILED tar: backups/pco_backup_2007-02-26.tar: Cannot open: No such file or directory tar: Error is not recoverable: exiting now *** ERRORS DETECTED! *** Check your email account paul@xyz.co.uk for more information! There were errors! Emailing error log to paul@xyz.co.uk ..
    Warning: file_get_contents(backups/pco_backup_2007-02-26.err) [function.file-get-contents]: failed to open stream: No such file or directory in /homepages/30/d116518341/htdocs/admin/backup_dbs.php on line 330

    Warning: closedir(): supplied argument is not a valid Directory resource in /homepages/30/d116518341/htdocs/admin/backup_dbs.php on line 372

    Warning: rmdir(tmp/backup_temp) [function.rmdir]: No such file or directory in /homepages/30/d116518341/htdocs/admin/backup_dbs.php on line 375

  129. Dennis: Thanks for the info :)

  130. Oh.. before I forgot, I think we can call this a bug (although I doesn’t hurt anyone :D ):
    in the exec function when running mysqldump from shell command there is something like “2>&1 >$BACKUP_TEMP/$db.sql”, which by simple logic will not work properly. I would work good if changed to “>$BACKUP_TEMP/$db.sql 2>&1″, because you should first specify STDOUT point (by “>$BACKUP_TEMP/$db.sql”) and only after that you can point STDERR to STDOUT (by “2>&1″). In your case STDERR is pointed to terminal… :) so you loose all your error output..
    Have a nice day

  131. Nice script. I was just looking for a ready-to-use one to backup my website, cause I get a bit scary when thinking of all my work (and paid members’ profiles :D ) crashing down.
    I am just too lazy to write a program myself, but it was a great pleasure for me to modify it a bit (I guess I will send a modified version to you later when I have some time, it is good enough.. at least I think so :D )
    I added a capability to list databases you want to backup, and also tables to exclude for every db listed (as I thought it is much easier to exclude unneeded tables than to list needed ones :D )…
    Have a nice day!

  132. 81
    Mastermind

    Nice examples thanks!
    Can you make a phpbb 3.x multi-forum mod when rc1 version will be released?
    There are thousands of people looking for this…

  133. 80
    Mastermind

    Wow you guys are making a fantastic job by publishing those tutorials and ready to download scripts! I am a php newbie so this is like gold for me, because I’m learning from best secured scripts…
    I want to make a little suggestion for php guru’s here :) > Can you make a multi-forum mod for phpbb 3.x? when rc1 will be released? There are more people looking for this than you can imagine!! Thanks again…

  134. Rob: Here is one method. Find this line in the script:

    $db = $db_row->Database;

    Right after it, add something like this for each one you want to skip:

    if ($db == 'database_whatever') break;

  135. Where are the details on exluding databases? I see the link in the page contents, but not in the page.
    Thanks….

  136. 77
    Erik

    I’ve tried re-downloading, but with no change. I’m not very experienced in the Linux world, is there some special configuration of PHP or MySQL that needs to be taken in concideration? Is there nothing that needs to be changed in the main file? I’ve noticed that there is nowhere I can configure witch database to backup, does the script automatically search for the databases? I really can’t figure this out..

  137. Erik: If it is not adding anything to the error file, this generally means that something is failing early on in the script. Most commonly, a configuration problem.

    It would also not hurt to re-download a fresh copy just in case something was accidentally changed in the code, or a bad download.

  138. 75
    Erik

    Hi, I’ve tried getting this to wotk for a long time now. I’m running as root, and when I run “php backup_dbs.php” it says “Executing MySQL Backup Script v1.4 – Processing Databases..”
    Then when I check the folder /db_backups, there are only the .err and the .log file there, no backup file! Argh! The .err file is empty, and the .log file just says the same thing as the script. Of course no email is sent. What am I doing wrong?

  139. 74
    Sean

    Got it! The problem was the location of the output dir ($BACKUP_DEST). When the script begins to compress files, its current location is your $BACKUP_TEMP. When it tried to place files into $BACKUP_DEST it couldn’t find it because that location is actually two folders down (i.e. ../../$BACKUP_DEST).

    So here is my change -
    Line 244: exec("cd $BACKUP_TEMP ; $USE_NICE tar cf ../../$BACKUP_DEST/$BACKUP_NAME * 2>&1", $output, $res);

    I also had to leave out the first preceding “/” in my $BACKUP_DEST and $BACKUP_TEMP variables.

    Thanks for your help – I hope this will help someone else!
    Sean

  140. 73
    Sean

    Thanks for the quick reply! The folder is empty, the file never gets created. I made sure the script was able to write to the directory… all of the .sql and bz2 files are sitting in the temp folder, but when it goes to compress them all into one file, I get that pesky error.

    I am understanding the script correctly, right? It takes all the files in the temp folder and then compresses them into one file, right?

    Thanks again for your help!
    Sean

  141. Sean: Have you looked in that directory to see if the file is there, but with perhaps another name? Or is it empty?

  142. 71
    Sean

    I have been at this for a 1.5 hours now and it’s breakin me down :P I keep getting the following…

    tar: /db_backups/mysql_backup_2007-01-17.tar: Cannot open: No such file or directory

    I’ve tried a few things on my own as well as some research, but no luck. Any help would be appreciated!

    Sean

  143. Omar: Since you do not have full control of the server, this script will not work for you very well.

    The good news is, it is very likely that your host has some sort of backup system in place already. Or you could ask them if there is some way you can download the backups regularly. Most will let you do this.

  144. Well the thing is I am not the host of the server and I am not on a dedicated server either. I just have my own account on the server which hosts many people.

  145. Omar: Are you running this as root? If so you should not be getting the permission denied error.

  146. I get this error everytime I try to run the files and cannot figure out why

    Warning: mkdir(/db_backups) [function.mkdir]: Permission denied in /home/hellomo/public_html/BAK/backup_dbs.php on line 155

    Notice: Undefined variable: f_log in /home/hellomo/public_html/BAK/backup_dbs.php on line 85
    Backup directory could not be created in /db_backups

    Notice: Undefined variable: f_err in /home/hellomo/public_html/BAK/backup_dbs.php on line 85
    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups

  147. Ruta: I personally have not ever used it on a Windows server, but it should certainly work. Someone I was working with had contributed some code including support for Windows, which was tested and used by him.

  148. 65
    Ruta Lietuvninkas

    Has anyone actually gotten this script to work on Windows? If so, PLEASE let us know how cause I’ve been trying to get this to work for hours (no problem on Linux).

  149. Hi there… I have this lines in the start of the dumb .sql file
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8 */;
    /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
    /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
    /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=’NO_AUTO_VALUE_ON_ZERO’ */;
    /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

    The problem is that my db is using latin1 and the collate is utf8_general_ci and the back up is very wrong ( encoding).

  150. Backup: I do not think this will work very well on shared hosting – you probably do not even have shell access on it. You could always ask your host to see if they have any kind of backup system you can use though.

  151. How can configure it on shared hosting ? do we need extra privilages ?

  152. 61
    DeletedMYSQL

    Ok…I figured it out after losing the files. Temporary doesn’t have to mean that the script owns the directory. I’m sure some users will use c:\windows\temp or %temp% as their directory, which could have the same results if another program is using the directory or they have downloaded unzipped/unrar’d files open.

    I’m not slamming the script, I love it. I just think it needs to be a little more picky about what it touches :)

  153. 60
    Austin

    Bad idea to put a temp directory in a directory that isn’t (I’m sure you realized that by now). You should use something like C:\temp\mysql because if you read the code, this script will delete all the files in the directory it made when it cleans up. I suppose your way will work as well, but that really isn’t how a temporary directory is designed.

  154. 59
    DeletedMYSQL

    Well, I’m running Windows and wanted my backups in c:\mysql\backups.
    For a temp directory I figured it would put the sql files in a dir then remove the sql files it made, naturally. So I set the temp path to c:\mysql\.
    That caused the entire mysql directory’s contents (aside from folders) to be removed.

    I recoded it to delete only the files it created now so there’s no more issue with my install.

  155. 58
    Austin

    Did you happen to change the $BACKUP_TEMP path so it’s just ‘/tmp’ ?? Because that will do it, you should leave it at default. And why did you delete everything in the mysql directory? I’m not sure I’m following you.

  156. 57
    DeletedMYSQL

    This code will delete ALL files in your temp dir, even if they weren’t created by the script. USERS BEWARE!!!

    I deleted everything in my mysql directory :(

  157. Austin’s custom version of this script is now available for download above. It is a modified version which emails each database separately, which may help if you find that the standard version generates attachments that are too large.

  158. Austin: Nice work. If you would like to contribute your version, feel free :) I will add it to the site (email me if interested)

  159. 54
    Austin

    I tweaked it a little bit so it’d email me each database seperately. This was attachments would go through to free email providers like GMail.

  160. On my other server (plesk) i get the access denied for user admin@localhost passowrd:YES.

    I have managed to get the dump work on the command line using:

    /usr/bin/mysqldump -uadmin -p*********** –all-databases > /var/www/vhosts/*********/httpdocs/allbackups.sql

    Does your code need altering for plesk installations? I tried hacking at the $db_auth, but had no joy! It works fine as is on my WHM/cpanel vps.

  161. Great script, i get an error saying the email failed to send. Why might this be? The archive is just 50mb, so it’s not a size issue…

  162. This script really needs to be ran from root either through a shell or cron, and not just from a web browser.

  163. I also recieve the same type error, probally a mistake on my part. Altough I am using sql user access that can see all DB in mysql.

    Warning: Cannot modify header information – headers already sent by (output started at /home/marlarbi/public_html/Cron/backup_dbs_config.php:120) in /home/marlarbi/public_html/Cron/backup_dbs.php on line 132

    Warning: Cannot modify header information – headers already sent by (output started at /home/marlarbi/public_html/Cron/backup_dbs_config.php:120) in /home/marlarbi/public_html/Cron/backup_dbs.php on line 133

    Warning: mkdir(/db_backups): Permission denied in /home/marlarbi/public_html/Cron/backup_dbs.php on line 157

    Notice: Undefined variable: f_log in /home/marlarbi/public_html/Cron/backup_dbs.php on line 87
    Backup directory could not be created in /db_backups
    Notice: Undefined variable: f_err in /home/marlarbi/public_html/Cron/backup_dbs.php on line 87
    Backup directory could not be created in /db_backups Backup directory could not be created in /db_backups

  164. Hi, this script seems absolutely perfect for what a need, an automatic sql backup emailed to a remote server. But i’m getting this error below, any suggestions on what i can do to fix the issue?

    
    
    <b>Warning</b>:  mkdir() [<a href='function.mkdir' rel="nofollow">function.mkdir</a>]: open_basedir restriction in effect. File(/db_backups) is not within the allowed path(s): (/home/duplex:/usr/lib/php:/usr/local/lib/php:/tmp) in <b>/home/duplex/public_html/backup_dbs.php</b> on line <b>155</b>
    
    
    <b>Notice</b>:  Undefined variable:  f_log in <b>/home/duplex/public_html/backup_dbs.php</b> on line <b>85</b>
    Backup directory could not be created in /db_backups
    
    <b>Notice</b>:  Undefined variable:  f_err in <b>/home/duplex/public_html/backup_dbs.php</b> on line <b>85</b>
    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups

  165. [...] Wer keinen direkten Zugriff auf den MySQL Server und somit keine direkte Möglichkeit von seinen Datenbanken Backups zu machen, dem möchte ich gerne dieses PHP MySQL Backup Script empfehlen. [...]

  166. Thanks for all the help getting it sorted for my site Admin, just the cron job to sort out now. I’ve been wanting to get automated db backups running for a long time, and you were a great help.

    Thanks,

    Jason

  167. I know this is not really relevent to your script, but I would appreciate your input on it.

    Let’s say I had access to the most recent version of my database at any time from the url http://username:password@domain.com:2082/getsqlbackup/dbname.gz – would it be possible to set up a script or cron job to download that file automatically and email it to me every 24 hours?

    Thanks,

    Jason

  168. Jason Golod: I do not have a version for directories, although you could just create a little shell script to do it, and set it to a cron job.

    Jason: Now that I look at your error messages again, you would have some problems with this script even if you could use that one function. You may not have much luck with any script like this – you may have some way to automate backups from your host’s control panel though, if you have one.

  169. [...] If you are looking for a way to backup all of your MySQL tables daily and have them emailed to you, I found an awesome MySQL backup script that takes about 1 minute to configure and works perfectly right out of the box. Of course, you may have trouble emailing all of the files to yourself if you have a lot of dbs but, the script can make the backup to a local drive and you can then setup another cron job to ftp that file somewhere or not. [...]

  170. Hey, wanted to say thanks. This is not only a great script, but well documented as well. Thanks for making it public. BTW, do you have a modified version to backup a set of directories?

  171. I guess my host has disabled it for security reasons, so I can’t see them enabling it just for me.

    Am I likely to have this problem with all database backup scripts, or should I continue my search?

    Thanks,

    Jason

  172. Jason: The problem starts with that first function (mysql_list_dbs). It uses that to get a list of the databases. If it cannot do that, it cannot back them up. I am not sure really how you would go about enabling that – I have not ever had to. Perhaps your host can change the option? You may not have access to it.

  173. I get the following error when trying to execute the cript:

    Executing MySQL Backup Script v1.4
    Processing Databases..

    Warning: mysql_list_dbs() has been disabled for security reasons in /home/bzone/public_html/backup_dbs.php on line 182

    Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/bzone/public_html/backup_dbs.php on line 184

    Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/bzone/public_html/backup_dbs.php on line 231
    Archiving files..

    Notice: Undefined variable: output in /home/bzone/public_html/backup_dbs.php on line 244

    Notice: Undefined variable: res in /home/bzone/public_html/backup_dbs.php on line 244

    Warning: exec() has been disabled for security reasons in /home/bzone/public_html/backup_dbs.php on line 244

    Notice: Undefined variable: res in /home/bzone/public_html/backup_dbs.php on line 248
    Backup complete!
    Emailing backup to jason@badgezone.com ..

    Warning: file_get_contents(/home/bzone/public_html/db_backups/bz_db_backup_2006-09-27.tar) [function.file-get-contents]: failed to open stream: No such file or directory in /home/bzone/public_html/backup_dbs.php on line 293

    Warning: rmdir(/home/bzone/public_html/tmp/backup_temp) [function.rmdir]: Permission denied in /home/bzone/public_html/backup_dbs.php on line 375

    Will I not be able to make use of this script? I don’t have access to the server, but I do have access to cPanel and WHM.

    Thanks.

    Jason

  174. Daniel: Ah, good to hear! :) I will have to remember that one in case I see it happen again.

  175. 38
    Daniel

    I just wanted to let you know the problem is solved. PHP was choking on the memory limit. I set memory_limit = 16M in php.ini, restarted the server, and everything worked perfectly. It was originally at 8 MB.

  176. 37
    Daniel

    OK, I did some more testing and the error is definitly at the mail function. I set $EMAIL_BACKUP =false; and it does delete the temp files and everything works perfectly. I have triple checked and the mail variables are set the same as the other servers which work fine. The only difference is the size of the database (3.07 MB when compressed). Is there a size limit on mail attatchments in the php mail() function?

  177. 36
    Daniel

    I did try a different email address, but no luck. When I run the script through SSH it says that it is sending the email but it does not say “deleting temp files” afterwards. It does say that when I run it on the other servers. I have $DEL_AFTER = true;

  178. Daniel: Strange. Have you tried having the backup sent to another email address? I am not sure what else to suggest – I am thinking though :) If something is failing you really should be seeing some sort of error.

  179. 34
    Daniel

    Hello Admin,

    Yes, the test works and the email goes through correctly.

  180. Daniel: Are you sure you have access to the PHP mail() function on this server? You could test it in a PHP script:

    <?php mail('you@domain.com', 'Subject', 'Message', '-f you@domain.com'); ?>

  181. 32
    Daniel

    Thank you for writing such an excellent script. I have installed this on 5 of my accounts and it works extremely well. I have one account though that it refuses to work on and I have run out of ideas to fix it. It is installed in exactly the same location as my other accounts, and the variables are set exactly the same (except the password). All accounts are VPS’s on the same dedicated server and are set up exactly the same.

    The problem is that the first time it runs, it appears to complete (when initiating it through SSH) but it never emails the backup. It doesn’t delete the temp file, and then the next time it runs, it has an issue because the file already exists. It looks like the first installation ended up with the temp files being assigned different permissions so I can not delete them.

    I really need to get this working because this is my most important account.

    TIA, Daniel

  182. 31
    Richard

    -

  183. Pedro: I have not ever used this script in a Windows environment. I suppose you might be able to use WinZip or something and just adjust the script accordingly. Maybe another Windows user can suggest something for you.

  184. 29
    Pedro Fonseca

    i need the zip.exe for windows 32, right??

    Where can i find it?? thanks

  185. PigFat: The path to MySQL depends on your configuration.

    Also, this script has to be ran under the root account. If you do not have access to the root account on the server, you cannot use this script. This is why you are getting most of those errors.

  186. 27
    PigFat

    Im Gettnig Errors :(

    Warning: mkdir(/db_backups): Permission denied in /home/pigfat/public_html/test/backup_dbs.php on line 155

    Notice: Undefined variable: f_log in /home/pigfat/public_html/test/backup_dbs.php on line 85
    Backup directory could not be created in /db_backups

    Notice: Undefined variable: f_err in /home/pigfat/public_html/test/backup_dbs.php on line 85
    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups

  187. 26
    PigFat

    Where is the path to mysql???

  188. Colin: The very last line in the script is this:

    rmdir($BACKUP_TEMP);

    So it should be deleting the temp directory when it is through. Did you change the location of the temp directory? If so, make sure it is a directory that can be safely deleted. Also, are you running the script as root?

  189. Nice script! It works great, the first time. But, it seems to leave the temp files in the temp directory, so the second time it gives an error saying the file exists and compression failed. Any way to make sure the temp files get deleted?

  190. It is a security risk, but not for the purposes of this script really, since you would (if done properly) be the only one who can change this file.

    Do you know of another method? I would be curious to hear it. (I do not mean that sarcastically :) )

  191. This script uses the php exec() function. Unfortunately, this function is a security risk and is disabled in most systems.

  192. duh.

    Figured it out. Wrong path to mysql.

  193. I keep getting this emailed to me:

    2006-03-02 22:43:36: DUMP FAILED
    sh: line 1: /home/content/e/c/s/ecspc/html/busqlphp/mysqldump: No such file or directory
    2006-03-02 22:43:36: FAILED
    nice: tar: No such file or directory

    And a page that says:
    Executing MySQL Backup Script v1.4 Processing Databases.. DUMP FAILED sh: line 1: /home/content/e/c/s/ecspc/html/busqlphp/mysqldump: No such file or directory DUMP FAILED sh: line 1: /home/content/e/c/s/ecspc/html/busqlphp/mysqldump: No such file or directory Compressed DB: dodgerdogs Archiving files.. FAILED nice: tar: No such file or directory FAILED nice: tar: No such file or directory *** ERRORS DETECTED! *** Check your email account REMOVEDFOR THISPOST for more information! Emailing backup to REMOVEDFORTHISPOST ..
    Warning: file_get_contents(/home/content/e/c/s/ecspc/html/busqlphp/destination/mysql_backup_2006-03-02.tar): failed to open stream: No such file or directory in /home/content/e/c/s/ecspc/html/busqlphp/backup_dbs.php on line 293
    There were errors! Emailing error log to REMOVEDFORTHISPOST ..

  194. Eventually I will test the web-based usage of this script ;)

    Jon: It really just depends on your web host. Almost all hosts have some sort of control panel where you can setup your databases etc., such as phpmyadmin. There will be an option in there to import/restore database files. You can ask your host to be sure, but you should not have to install any thing new in order to restore db backups. It should be built in to your control panel.

  195. Do you have a scrip that will allow me to restore the files that i have backed up . Or could you tell me how i could do this.

  196. I had some delays actually.. I will post back tonight though :)

  197. 16
    henry

    Any Joy?

  198. It may still be a permission error, but I will test it myself and let you know today :)

  199. 14
    henry

    Thanks for the quick reply, adjusted so it can find the exact dir and now get another error. Is this to do with the host not allowing scripts to execute? Ive set chmod 777 on both dirs and still no joy.

    Warning: fopen(backup/mysql_backup_2005-10-20.log): failed to open stream: Permission denied in /home/.sites/16/site186/web/backup_dbs.php on line 165
    Cannot create log file: backup/mysql_backup_2005-10-20.log

    Notice: Undefined index: f_err in /home/.sites/16/site186/web/backup_dbs.php on line 85
    Cannot create log file: backup/mysql_backup_2005-10-20.log
    Cannot create log file: backup/mysql_backup_2005-10-20.log

  200. It sounds like you do not have permission to create those directories. The default is /db_backups but if you do not have root access, you may need to edit the configuration so that it creates the directories in your local user space.

    Or if you are running it from a browser, you may need to create the directories first, and use the full server path to them in the config (/home/user/public_html/backups) etc..

  201. 12
    henry

    Tried on diff servers and get the same error:

    Warning: mkdir(/db_backups): Permission denied in /home/.sites/16/site186/web/backup_dbs.php on line 155

    Notice: Undefined index: f_log in /home/.sites/16/site186/web/backup_dbs.php on line 85
    Backup directory could not be created in /db_backups

    Notice: Undefined index: f_err in /home/.sites/16/site186/web/backup_dbs.php on line 85
    Backup directory could not be created in /db_backups
    Backup directory could not be created in /db_backups

  202. The new version has been released! Read for details.

  203. Oh I see.. yes, that issue has been fixed. The version you have assumed that if you ran the script as root, you would automatically have the access (I have a password for mysql root and it works).

    But fear not, the new version has variables added for the mysql stuff. It is actually much much better in general in terms of what it assumes. It also has much nicer logging support, etc.. It can even be used under Windows (assuming you make all the required variable changes, and have an acceptable zip/tar program installed). But you will be able to read all that once the page is updated :)

  204. 9
    Wassim

    It happens the second I run the script. It appears most people don’t use a password for the MySQL root user? Looking forward to the PHP version.

    mysqldump: Got error: 1045: Access denied for user: ‘root@localhost’ (Using password: NO) when trying to connect
    mysqladmin: connect to server at ‘localhost’ failed

  205. Do you get that message when you first run it? Or is it at one particular point of the script? Btw – there is a new version which I am testing and will release soon. It uses php instead of perl, and has many new options. If all else fails, maybe it will work better for you.

  206. 7
    Wassim

    I’m trying to use this but getting access denied running it as root. I can run the command it executes via command line with the -u and -p options and it works, but, when I try to add those options I still access denied. Any ideas?

  207. That would probably be easy to do. I may do that for my next update, so keep checking back. :)

  208. Good work really.

    I have a suggestion.
    It will be great if you can add a feature where the application can upload the backed-up databsed onto a different ftp location. I mean a different domain. The reason, i lost my server once, all backup was also store on the same machine and nothing was spared.

    Good Luck.

  209. Glad to hear it :)

  210. Thanks Admin.
    Worked like a charm. Only caveat was not forgetting the third curly bracket.

  211. Hello. I just updated the tutorial, adding a section on how to exclude databases. Let me know if it works for you.

    As far as the SCP functionality, I just added it by request, and while I have tested it, I do not use it myself. If you have not used SCP before, I would learn the basics before letting the script do it. The connection has to be manually set up at least once, so that it sees the security certificate.

  212. Hello,
    Couple of questions.
    1. Seem to remember that you mentioned the SCP function doesn’t work properly?
    2. Any chance that a parameter can be added to exclude certain databases?
    Thank you.

Leave a Comment

Before you comment: If you are having an issue with a script, please make sure you have read the entire article. Also, please read through the comments because most common issues have already been discussed many times. Thanks.


Be sure to wrap all code in <code></code> tags.