Jump to content

Advisory: Database Backup


bsmither

Recommended Posts

Regarding CC613, for stores with moderate and larger databases, having CubeCart do a database backup has the possibility of resulting in a partial backup file, PHP crashing, and you seeing a blank white screen.

The problem is that the new means of reading short blips of the database and writing it to the file, opening and closing the file between blips, as a means (assuming) of staying within reasonable limits of memory consumption --- that new means is flawed.

If this happens to you, please use any external database maintenance utility to make the backup of your moderate and larger database.

This is only an advisory -- there will be no damage to your store files, nor to the database.

An issue has been posted in the Github.

 

Link to comment
Share on other sites

Can we not make a call to run mysqldump.exe on the desired databases / tables?

It seems to me that this would be the ideal solution, as mysqldump is a tool written explicitly for this purpose and would avoid all of the issues with trying to iterate over large amounts of data in PHP.

This tool is also a part of nearly all database installations - on one of my non-CubeCart sites, I wrote a cron script to automate the database backup:

require_once ($_SERVER['DOCUMENT_ROOT'] === 'C:/wamp/www/' ? 'C:/wamp/www/git/site_name' : '/home/site_name') . '/public_html/includes/config.inc.php';
require_once BASE_URI . 'hidden/db_cred.inc.php';
$pass = BASE_URI . 'hidden/my.cnf';
$exe = ($_SERVER['DOCUMENT_ROOT'] === 'C:/wamp/www/' ? 'C:/wamp/bin/mysql/mysql5.6.17/bin/mysqldump' : 'mysqldump');
$day = date('N'); // Day of week as numeral: 1 (Monday) to 7 (Sunday)
if ((int) $day === 7) {
	$date = date_parse(date('Y-m-d'));
	$day = 'w' . ceil($date['day'] / 7); // weekly backups maintained on rolling basis for 4 weeks
} else {
	$day = "d$day"; // daily backups maintained on rolling basis for 1 week
}
$filename = escapeshellarg(BASE_URI . "hidden/backups/site_name_db-$day.sql" . (LIVE ? ".gz" : ""));
$cmd = "$exe --defaults-file=$pass -h " . escapeshellarg(DB_HOST) . " -u " . escapeshellarg(DB_BACKUP_USER) . " --single-transaction " . escapeshellarg(DB_NAME) . (LIVE ? " | gzip" : "") . " > $filename";
$output = shell_exec($cmd);
if (!empty($output)) {
	throw new \Exception("Error(s) running script db_backup.php:\n$output");
}

This requires that there exist a file `my.cnf` containing the lines:

[client]
password=your_db_password

That allows the command line to execute the mysqldump command without the user needing to input their password.

Link to comment
Share on other sites

Just to satisfy my curiosity: how would phpMyAdmin (a PHP app) get around the same limitations imposed on any other PHP app running in a user environment that would otherwise bork CubeCart's procedure?

I think because phpMyAdmin is usually launched from within a Cpanel environment, maybe that environment has much more resources allocated to it.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...