PHP Deployment Scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
neatoDeploy/app/utils/mysql.php

43 lines
1.6 KiB

<?php
namespace utils;
class mysql {
public static function exec($db, $password, $sql, $user = "root") {
$dsn = "-D {$db} -u {$user} -p{$password}";
exec(\neato::get_user_bin . 'mysql '. safe_cmd_quotes($dsn) . ' -e ' . safe_cmd($sql), $output, $exit_code);
display($output);
check_for_error($exit_code, "Unable to run MySQL command: {$sql}");
return $exit_code;
}
public static function import($db, $password, $file, $user = "root") {
$dsn = "-D {$db} -u {$user} -p{$password}";
exec(\neato::get_user_bin . 'mysql '. safe_cmd_quotes($dsn) . ' <' . safe_cmd($file), $output, $exit_code);
display($output);
check_for_error($exit_code, "Unable to Import MySQL file: {$file}");
return $exit_code;
}
public static function backup($db, $password, $file, $user = "root") {
$what = ($db == 'all') ? '-A' : "-B {$db}";
$dsn = "{$what} -u {$user} -p{$password}";
exec(\neato::get_user_bin . 'mysqldump '. safe_cmd_quotes($dsn) . ' | gzip > $(date +\%Y_\%m_\%d-\%T)'. safe_cmd($file) . '.sql.gz', $output, $exit_code);
display($output);
check_for_error($exit_code, "Unable to Export MySQL file: {$file}");
return $exit_code;
}
public static function gunzip($file) {
exec(\neato::get_bin . 'gunzip ' . safe_cmd($file) . '.sql.gz', $output, $exit_code);
display($output);
check_for_error($exit_code, "Unable to unzip MySQL file: {$file}");
return $exit_code;
}
public static function remove_old($path = '', int $days_old = 10) {
exec(\neato::get_user_bin . 'find ' . $path . ' -name "*.gz" -mtime +'.$days_old.' -delete');
}
}