AutoBackup - skip particular table

6 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: June 22, 2011   (RSS)

Re: [rjbathgate] AutoBackup - skip particular table

By Dave - June 21, 2011

Hi Rob,

This is the second request I've had in 24 hours for that feature. We could probably get that in the next release of both CMSB and the plugin.

Curious why the table needs to be skipped? And do you want it skipped from regular backups as well?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] AutoBackup - skip particular table

By rjbathgate - June 22, 2011

Hey Dave,

I need to skip a particular table because it's huge, and the backup function tends to run out of memory on that table, and the resulting file is 100MB.

And GZ down to 8mb means it's too big to auto email.

So I'm running the backup on all but this table (via skipping it in the database_functions.php file), ending up with a much more managable and emailable file size :)

Luckily, manually restoring this table in question isn't too hard if we ever needed to.

Re 'do you want it skipped form regular backups as well' - not sure what you mean, I'm skipping it from all backups done by the AutoBackup function, but it could be a super function to be able to skip tables on the hourly, but than backup entire lot daily, for example ;)

That way running an hourly backups the quick important stuff, whilst the daily (or whatever) backs up the whole lot

Cheers

Re: [rjbathgate] AutoBackup - skip particular table

By Dave - June 22, 2011

Hi Rob,

I've added a plugin filter for this to 2.10. To apply it yourself do the following:

- Open /lib/database_functions.php
- Search for "get tablesnames"
- Replace everything between that and " // backup database" with the code in red below:

// get tablenames to backup
if ($selectedTable) {
$tablenames = array( getTableNameWithPrefix($selectedTable) );
}
else {
$skippedTables = array(); // don't backup these table names
$skippedTables = applyFilters('backupDatabase_skippedTables', $skippedTables); // let users skip tables via plugins
$skippedTables = array_map('getTableNameWithPrefix', $skippedTables); // add table_prefix to all table names (if needed)
$allTables = getMysqlTablesWithPrefix();
$tablenames = array_diff($allTables, $skippedTables); // remove skipped tables from list
}


// backup database


Then write a plugin backupSkipTables.php

<?php


addFilter('backupDatabase_skippedTables', 'skipTheseTables', null, 1);

function skipTheseTables($skippedTables) {
$skippedTables[] = 'news2';
$skippedTables[] = 'something'; // copy this line for each table you want to skip
return $skippedTables;
}


Hope that helps! Let me know if that works for you. :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] AutoBackup - skip particular table

By rjbathgate - June 22, 2011

Cheers Dave!

This particular installation is 2.7, with a bunch of non-plugin hacks :) so can't apply to this instance, but definitely useful for future (and if I ever get around to turning my hacks into plugins for this install!)

For this install I have done it through editing database_functions.php as follows:

foreach ($tablenames as $unescapedTablename) {

if($unescapedTablename == 'cms_MYTABLENAME')
{
continue;
}


Super quick work though there Dave, thanks!!

Rob

Re: [rjbathgate] AutoBackup - skip particular table

By Dave - June 22, 2011

Hey Rob,

For 2.07 you just need to replace this code with the code above:
// get tablenames to backup
$tablenames = getMysqlTablesWithPrefix();
if ($selectedTable) {
$tablenames = array( getTableNameWithPrefix($selectedTable) );
}

// backup database


But if it's already working then glad to hear it!

All the best! :)
Dave Edis - Senior Developer
interactivetools.com