#!/usr/bin/env php '" . $table['Name'] . "'"); $sql = ''; if ($utf8) { $sql .= ' CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci'; } if ($innodb && $canInnoDB) { $sql .= (strlen($sql) ? ',' : '') . ' ENGINE=Innodb'; } $status = db_execute('ALTER TABLE `' . $table['Name'] . '`' . ($dynamic ? ' ROW_FORMAT=Dynamic, ':'') . $sql); if ($status === false) { print_or_log($installer, ' Failed' . PHP_EOL); record_log($installer, "FATAL: Conversion of Table '" . $table['Name'] . "' Failed. Command: 'ALTER TABLE `" . $table['Name'] . "` $sql'"); } else { print_or_log($installer, ' Successful' . PHP_EOL); } } else { print_or_log($installer, "Skipping Table -> '" . $table['Name'] . " too many rows '" . $table['Rows'] . "'" . PHP_EOL); } } else { print_or_log($installer, "Skipping Table -> '" . $table['Name'] . "'" . PHP_EOL); } } } function print_or_log($installer, $text) { if ($installer) { log_install_and_file(POLLER_VERBOSITY_MEDIUM, rtrim($text), 'CONVERT', true); } else { print $text; } } function record_log($installer, $text) { if ($installer) { log_install_and_file(POLLER_VERBOSITY_MEDIUM, rtrim($text), 'CONVERT', true); } else { cacti_log($text, false, 'CONVERT'); } } /* display_version - displays version information */ function display_version() { $version = get_cacti_cli_version(); print "Cacti Database Conversion Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } /* display_help - displays the usage of the function */ function display_help () { display_version(); print "\nusage: convert_tables.php [--debug] [--innodb] [--utf8] [--table=N] [--size=N] [--rebuild] [--dynamic]\n\n"; print "A utility to convert a Cacti Database from MyISAM to the InnoDB table format.\n"; print "MEMORY tables are not converted to InnoDB in this process.\n\n"; print "Required (one or more):\n"; print "-i | --innodb - Convert any MyISAM tables to InnoDB\n"; print "-u | --utf8 - Convert any non-UTF8 tables to utf8mb4_unicode_ci\n\n"; print "Optional:\n"; print "-t | --table=S - The name of a single table to change\n"; print "-n | --skip-innodb=\"table1 table2 ...\" - Skip converting tables to InnoDB\n"; print "-s | --size=N - The largest table size in records to convert. Default is 1,000,000 rows.\n"; print "-r | --rebuild - Will compress/optimize existing InnoDB tables if found\n"; print " --dynamic - Convert a table to Dynamic row format if available\n"; print "-f | --force - Proceed with conversion regardless of table size\n\n"; print "-d | --debug - Display verbose output during execution\n\n"; }