Skip to content

Instantly share code, notes, and snippets.

@katzefudder
Created August 7, 2014 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katzefudder/f90985649a2862dadee1 to your computer and use it in GitHub Desktop.
Save katzefudder/f90985649a2862dadee1 to your computer and use it in GitHub Desktop.
MySQL Dump Script for various TYPO3 tables, excludes caching tables
<?php
/**
* 2014 Florian Dehn <f.dehn@wdv.de>
*/
$opts = '';
$opts .= 'u:';
$opts .= 'h:';
$opts .= 'd:';
$longOpts = array(
'file:'
);
$options = getopt($opts, $longOpts);
$ignoreTables = array(
'cf_cache_hash',
'cf_cache_hash_tags',
'cf_cache_news_category',
'cf_cache_news_category_tags',
'cf_cache_pages',
'cf_cache_pagesection',
'cf_cache_pagesection_tags',
'cf_cache_pages_tags',
'cf_cache_rootline',
'cf_cache_rootline_tags',
'cf_extbase_datamapfactory_datamap',
'cf_extbase_datamapfactory_datamap_tags',
'cf_extbase_object',
'cf_extbase_object_tags',
'cf_extbase_reflection',
'cf_extbase_reflection_tags',
);
function dumpTypo3($options, $ignoreTable = array()) {
if (PHP_SAPI === 'cli' || empty($_SERVER['REMOTE_ADDR'])) {
if (empty($options['u']) || empty($options['h']) || empty($options['d']) || empty($options['file'])) {
echo "Wrong Parameters. Usage: php ".__FILE__." -u user -h host -d database --file database.sql\n";
echo "Example: php dump.php -u USER -h HOST -d DATABASE --file PATH \n";
return;
}
$ignore = ' --ignore-table=';
$ignoreString = '';
if (!empty($ignoreTable)) {
foreach ($ignoreTable as $ignored) {
$ignoreString .= $ignore.$options['d'].'.'.$ignored.' ';
}
} else {
$ignoreString = '';
}
echo "Tryning to dump \"".$options['d']."\" from \"".$options['h']."\"\n";
$string = 'mysqldump -u '.$options['u'].' -h '.$options['h'].' -p '.$options['d'].' > '.$options['file'].' '.$ignoreString;
exec($string);
return;
}
echo "This script must be run from command line\n";
}
dumpTypo3($options, $ignoreTables);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment