I'm trying to backup my database using this script, but it isn't working as expected, could you please have a look and tell me how can I fix it to work with vB 3.5.0?
PHP Code:
<?php
/* ####################################
Automated backup
by: Brad.loo
Version: 1.3.1
###################################### */
error_reporting(E_ALL & ~E_NOTICE);
// ######################## Begin edits ######################
define('DB_HOST', 'localhost'); // database host
define('DB_USER', 'user'); // database username
define('DB_PASSWORD', 'password'); // database password
define('DB_NAME', 'database'); // vbulletins database name
define('DUMP_PATH', 'path/to/backup'); // path to where db backup will be stored
define('DUMP_MAKE_TAR', 1); // set this to 1 for the backup to be compressed in a .tar.gz file
// ####################### End Edits ##########################
// for some reason beyound me query was un-defined for some users, so this is here as an attempt to fix it...
require_once('./global.php');
if ($DB_site == NULL)
{
exit;
}
// Get date for file name and log
$file_date = date('m-d-y');
$file_name = filename;
// Get .sql file
exec('mysqldump --add-drop-table -h' .DB_HOST. ' -u' .DB_USER. ' -p' .DB_PASSWORD. ' ' .DB_NAME. ' 2>' .DUMP_PATH. '/' .$file_date. '-error.txt >' .DUMP_PATH. '/' .$file_name. '.sql');
$log_db = 'Saved backup of databse to ' . DUMP_PATH . ' at ' . $file_date . ' (file name ' . $file_name . '.sql';
// Do we make a tar?
if (DUMP_MAKE_TAR == '1')
{
// now archive and compress the backup, also delete .sql file
exec('gtar -cSz --remove-files -C' .DUMP_PATH. ' -f' .DUMP_PATH. '/' .$file_name. '.tar.gz ' .$file_name. '.sql ' .$file_date. '-error.txt');
$log_db = 'Saved backup of databse to ' . DUMP_PATH . ' at ' . $file_date . ' (file name ' . $file_name . '.tar.gz';
}
// logs
log_cron_action($log_db, $nextitem);
echo('Database backup script was invoked without error, to check that it was done correctly see if the file was written to the folder you specified in the configuration variables. It may take some time before your server finishes backing up depending on the size of your database');
?>
PS: where it says: gtar -cSz --remove-files [...]
It must be gtar instead of tar, as I'm using FreeBSD.
Thanks in advance.