mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-04-04 14:43:32 -04:00
Add quiet option to cli/db-backup.php (#6593)
* Add quiet option to cli/db-backup.php * Fix CI test error * Fix README
This commit is contained in:
@@ -269,7 +269,7 @@ SQL;
|
||||
public const SQLITE_EXPORT = 1;
|
||||
public const SQLITE_IMPORT = 2;
|
||||
|
||||
public function dbCopy(string $filename, int $mode, bool $clearFirst = false): bool {
|
||||
public function dbCopy(string $filename, int $mode, bool $clearFirst = false, bool $verbose = true): bool {
|
||||
if (!extension_loaded('pdo_sqlite')) {
|
||||
return self::stdError('PHP extension pdo_sqlite is missing!');
|
||||
}
|
||||
@@ -354,7 +354,7 @@ SQL;
|
||||
|
||||
$idMaps = [];
|
||||
|
||||
if (defined('STDERR')) {
|
||||
if (defined('STDERR') && $verbose) {
|
||||
fwrite(STDERR, "Start SQL copy…\n");
|
||||
}
|
||||
|
||||
@@ -397,11 +397,11 @@ SQL;
|
||||
return self::stdError($error);
|
||||
}
|
||||
}
|
||||
if ($n % 100 === 1 && defined('STDERR')) { //Display progression
|
||||
if ($n % 100 === 1 && defined('STDERR') && $verbose) { //Display progression
|
||||
fwrite(STDERR, "\033[0G" . $n . '/' . $nbEntries);
|
||||
}
|
||||
}
|
||||
if (defined('STDERR')) {
|
||||
if (defined('STDERR') && $verbose) {
|
||||
fwrite(STDERR, "\033[0G" . $n . '/' . $nbEntries . "\n");
|
||||
}
|
||||
$entryTo->commit();
|
||||
|
||||
@@ -123,6 +123,7 @@ cd /usr/share/FreshRSS
|
||||
|
||||
./cli/db-backup.php
|
||||
# Back-up all users respective database to `data/users/*/backup.sqlite`
|
||||
# -q, --quiet suppress non-error messages
|
||||
|
||||
./cli/db-restore.php --delete-backup --force-overwrite
|
||||
# Restore all users respective database from `data/users/*/backup.sqlite`
|
||||
|
||||
@@ -6,15 +6,31 @@ require(__DIR__ . '/_cli.php');
|
||||
performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? '');
|
||||
$ok = true;
|
||||
|
||||
$cliOptions = new class extends CliOptionsParser {
|
||||
public string $quiet;
|
||||
|
||||
public function __construct() {
|
||||
$this->addOption('quiet', (new CliOption('quiet', 'q'))->withValueNone());
|
||||
parent::__construct();
|
||||
}
|
||||
};
|
||||
|
||||
if (!empty($cliOptions->errors)) {
|
||||
fail('FreshRSS error: ' . array_shift($cliOptions->errors) . "\n" . $cliOptions->usage);
|
||||
}
|
||||
|
||||
foreach (listUsers() as $username) {
|
||||
$username = cliInitUser($username);
|
||||
$filename = DATA_PATH . '/users/' . $username . '/backup.sqlite';
|
||||
@unlink($filename);
|
||||
$verbose = !isset($cliOptions->quiet);
|
||||
|
||||
echo 'FreshRSS backup database to SQLite for user “', $username, "”…\n";
|
||||
if ($verbose) {
|
||||
echo 'FreshRSS backup database to SQLite for user “', $username, "”…\n";
|
||||
}
|
||||
|
||||
$databaseDAO = FreshRSS_Factory::createDatabaseDAO($username);
|
||||
$ok &= $databaseDAO->dbCopy($filename, FreshRSS_DatabaseDAO::SQLITE_EXPORT);
|
||||
$ok &= $databaseDAO->dbCopy($filename, FreshRSS_DatabaseDAO::SQLITE_EXPORT, false, $verbose);
|
||||
}
|
||||
|
||||
done((bool)$ok);
|
||||
|
||||
Reference in New Issue
Block a user