1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00
Oinktube/install/mysqlDump.php
Daniel Neto b4cde799a0 Update
2024-07-26 14:54:52 -03:00

56 lines
1.5 KiB
PHP

<?php
//streamer config
require_once __DIR__.'/../videos/configuration.php';
if (php_sapi_name() !== 'cli') {
return die('Command Line only');
}
ob_end_flush();
$prefix = 'mysqldump';
if(!empty($restore)){
$prefix = 'mysqldumpBackup';
}
$file = Video::getStoragePath().$prefix.'-'.date('YmdHis').'.sql';
$excludeTables = ['CachesInDB', 'audit']; // tables to exclude from the dump
// Create a connection to the database to retrieve all table names
$connection = new mysqli($mysqlHost, $mysqlUser, $mysqlPass, $mysqlDatabase, $mysqlPort);
if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error);
}
$res = sqlDAL::readSql("SHOW TABLES");
$row = sqlDAL::fetchAllAssoc($res);
foreach ($row as $value) {
$firstElement = reset($value);
if (!in_array($firstElement, $excludeTables)) {
$tables[] = $firstElement;
}else{
echo "Exclude from dump $firstElement".PHP_EOL;
}
}
if(empty($mysqlPort)){
$mysqlPort = 3306;
}
// Use the mysqldump command to get the database dump
$dumpCommand = "mysqldump --host=$mysqlHost --port=$mysqlPort --user='$mysqlUser' --password='$mysqlPass' "
. "--default-character-set=utf8mb4 --column-statistics=0 $mysqlDatabase $tableList > {$file}";
// Execute the command
system($dumpCommand, $output);
// Check the result
if ($output !== 0) {
echo $dumpCommand.PHP_EOL;
die("Error occurred while taking the database dump.");
}
echo "Database dumped successfully to {$file}".PHP_EOL;
?>