WP-DBManager Backup DB Fix For Windows

For this blog I like to use a plugin called WP-DBManager. It's a great tool for easily maintaining your blog's database right from the administration console. Unfortunately, being on a Windows host, sometimes plugins don't work as intended, so you have to make some adjustments.

For this plugin I kept getting this error whenever I tried to run the backup script:

Warning: filesize(): Stat failed for (blah, blah)
Warning: unlink(blah, blah) no such file or directory

To fix it I had to do a few things:

1. The actual command to create the backup needs to be fixed, so it can run properly on the command prompt. Find the file named database-backup.php in the plugin's directory. Place double quotes around the path part of the command and remove all others. Lines 47 and 51.

$backup['command'] = '"' . $backup['mysqldumppath'].'" --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' --add-drop-table --skip-lock-tables '.DB_NAME.' | gzip > '.$backup['filepath'];

$backup['command'] = '"' . $backup['mysqldumppath'] . '" --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' --add-drop-table --skip-lock-tables '.DB_NAME.' > '.$backup['filepath'];

2. The function that runs the command is called execute_packup(). This function is located in a file named wp-dbmanager.php in the plugin's directory. Find this function (line 205) and remove the if statement and leave only the passthru() command. Similar to this:

function execute_backup($command) {
    $backup_options = get_option('dbmanager_options');
    check_backup_files();
    /*if(substr(PHP_OS, 0, 3) == 'WIN') {
        $writable_dir = $backup_options['path'];
        $tmpnam = $writable_dir.'/wp-dbmanager.bat';
        $fp = fopen($tmpnam, 'w');
        fwrite($fp, $command);
        fclose($fp);
        system($tmpnam.' > NUL', $error);
        unlink($tmpnam);
    } else {*/

        passthru($command, $error);
    //}
    return $error;
}

3. If you want to have the gzip functionality you will need to download and place gzip.exe in the system32 folder of the server. You can download gzip from here.

NOTES:

  • Make sure the the Internet Guest Account has write permissions to the backup-db directory.
  • There is probably a better way to do this, perhaps using the exec() command in the if statement, but this one seems to work just fine.
  • Not necessary - On my server I had to put @ symbols in front of the filesize() and unlink() functions in the database-backup.php file, so that the they would not throw the php warning message and continue through to show the actual error message on the plugin page.

2 Comments

  1. Posted November 7, 2008 at 9:16 am | Permalink

    Hey

    I have done this but i have stil the problem.
    Warning: filesize(): Stat failed for (blah, blah)
    Warning: unlink(blah, blah) no such file or directory

    what could i do?
    THX

  2. deciacco
    Posted November 7, 2008 at 10:01 am | Permalink

    Sebastian,

    If the command doesn't run, then the file is never created giving you that error. When I was debugging it, I was able to get the value of $backup['command'] to see the exact command being executed. I even ran it at the command prompt manually to see that it worked. (I don't remember how I got it to show the command so I could use it, but I either did an echo or when you use the @ symbol in front of the two functions as outlined in my notes above, you can then get the command to show as part of the error. Again, you might have to use an echo or something, can't remember for sure.) Once you can see the command and try it yourself and you know the command works, it's only a matter of how php executes the command. Double check that you have quotes in the right places on the command. Also, make sure that you do have mysqldump.exe where the plugin thinks it's supposed to be, and that the permissions on the directory at set properly.

    I hope this helps. I know for sure it worked on my server, so theoretically this should work for you as well.

    Good luck!

Post a Comment

Your email is never shared. Required fields are marked *

*
*