Files
laysite/bin/backup.php
T

27 lines
815 B
PHP

#!/usr/bin/env php
<?php
declare(strict_types=1);
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Content\SiteBackup;
[$command, $path, $confirm] = array_pad(array_slice($argv, 1), 3, null);
if (!is_string($path) || ($command !== 'export' && ($command !== 'import' || $confirm !== '--replace'))) {
fwrite(STDERR, "Usage: php bin/backup.php export snapshot.tar | import snapshot.tar --replace\n");
exit(2);
}
$path = str_starts_with($path, '/') ? $path : getcwd() . '/' . $path;
try {
if ($command === 'export') {
SiteBackup::export($path);
} else {
SiteBackup::import($path);
}
echo ($command === 'export' ? '备份已导出。' : '站点已还原。') . PHP_EOL;
} catch (Throwable $error) {
fwrite(STDERR, $error->getMessage() . PHP_EOL);
exit(1);
}