Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
更新:优化备份功能
  • Loading branch information
zhuchunshu committed Jan 8, 2023
1 parent 7595e54 commit 5f0cd96
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions app/helpers.php
Expand Up @@ -756,6 +756,16 @@ function system_name(): bool | string | null
return str_replace("\n", '', shell_exec('echo $(uname)'));
}
}
if (! function_exists('cmd_which')) {
function cmd_which($bin): bool | string | null
{
$cmd = shell_exec('which ' . $bin);
if ($cmd) {
return str_replace("\n", '', $cmd);
}
return false;
}
}

if (! function_exists('get_user_agent')) {
/**
Expand Down Expand Up @@ -852,17 +862,20 @@ function backup(mixed $filename = null): string
} else {
$filename = BASE_PATH . '/runtime/backup/' . $filename;
}
$sql_backup_name = Str::random(40) . '.sql';
$sql_backup_name = BASE_PATH . '/runtime/backup/' . $sql_backup_name;
System::exec('mysqldump -u ' . config('databases.default.username') . ' -p' . config('databases.default.password') . ' ' . config('databases.default.database') . ' > "' . $sql_backup_name . '"');
$sql_backup_name = null;
if (cmd_which('mysqldump')) {
$sql_backup_name = Str::random(40) . '.sql';
$sql_backup_name = BASE_PATH . '/runtime/backup/' . $sql_backup_name;
System::exec('mysqldump -u ' . config('databases.default.username') . ' -p' . config('databases.default.password') . ' ' . config('databases.default.database') . ' > "' . $sql_backup_name . '"');
}
$backup_files = [
BASE_PATH . '/app',
public_path(),
BASE_PATH . '/.env',
BASE_PATH . '/composer.json',
BASE_PATH . '/composer.lock',
];
if (file_exists($sql_backup_name)) {
if ($sql_backup_name && file_exists($sql_backup_name)) {
$backup_files['backup.sql'] = $sql_backup_name;
}
$zippy = Zippy::load();
Expand Down

0 comments on commit 5f0cd96

Please sign in to comment.