#!/usr/bin/php
<?php
$password = $argv[1];
$host = $argv[2];
$user = $argv[3];
if (!$password)
{
    echo "pty_mysql_backup.sh version 1.0\n";
    echo "Copyright (C) 2019 by cpueblo, PlatyHouse Co.,LTD.\n";
    echo "Web site: https://www.platyhouse.com/\n\n";
    echo "Usage ./pty_mysql_backup_all_database.sh <MYSQL ROOT PASSWORD> <HOST (default: localhost)> <USERNAME (default: root)> <DBNAME>\n";
    exit;
}

if (!$host)    $host = "localhost";
if (!$user)    $user = "root";

mysql_backup_all($host, $user, $password);

echo "finished\n";

function mysql_backup_all($host, $user, $password)
{
    $cmd = "mysqldump -u $user -p$password -h $host --all-databases --add-drop-table --add-drop-database --complete-insert --extended-insert > pty_mysql_backup_all_onefile.sql";
    echo $cmd;
    system($cmd);
}

?>
