<?php
// ----------------------------------------------------------------------------
// Script Author: Robert Holland
// Script Name: db_backup_script.php
// Creation Date: Fri Nov 17 2023 07:03:27 GMT-0700 (MST)
// Last Modified: 20231125105000
// Version: 1.0.1
// Purpose: Generate MariaDB database backup statements (This script only genrates non-system database backup statements. However,
// you can modify it to include the system databases).
// ----------------------------------------------------------------------------
include't4.php';
$dbshow = new Connection(); //Instantiate a new connection.
$dbshow->myQuery("show databases;"); //The databases shown will depend on the privileges of the user running the statement.
$rows = $dbshow->All();
function myfunction($value,$key)
{
$dbusername = "TheUserName";
$ThePassword = "ThePassword";
echo "TimeStamp=`date +\"%Y%m%d%H%M%S%Z\"`<br />";
echo "mysqldump -u{$dbusername} -p{$ThePassword} -c -e $value > \$TimeStamp.DBDump.$value.`hostname`.sql<br />";
echo "echo \"Compressing Database Dump. Please wait...\"<br />";
echo "tar -zcvf \$TimeStamp.DBDump.$value.`hostname`.sql.gz \$TimeStamp.DBDump.$value.`hostname`.sql<br /><br />";
}
// Remove these critical system databases from the output.
// information_schema, mysql, performance_schema, sys
$i=count($rows);
for($x = 0; $x < $i; $x++){
$y=$rows[$x];
// array_diff to exclude system databases from the generated output.
// If you would like to include the system databases in the generated mysqldump statements, simply delete the desired database name from the array below.
$y = array_diff($y, array("information_schema", "performance_schema","mysql","sys"));
array_walk($y,"myfunction");
}
?>