CLI to export/import any database to/from SQLite

Require PHP 5.5+ https://github.com/FreshRSS/FreshRSS/pull/2495
This commit is contained in:
Alexandre Alapetite
2019-08-18 22:18:42 +02:00
parent 38a4b22f7b
commit a7bd8aec7d
10 changed files with 303 additions and 14 deletions

View File

@@ -0,0 +1,28 @@
#!/usr/bin/php
<?php
require(__DIR__ . '/_cli.php');
$params = [
'user:',
'filename:',
];
$options = getopt('', $params);
if (!validateOptions($argv, $params) || empty($options['user']) || empty($options['filename'])) {
fail('Usage: ' . basename(__FILE__) . ' --user username --filename /path/to/db.sqlite');
}
$username = cliInitUser($options['user']);
$filename = $options['filename'];
if (pathinfo($filename, PATHINFO_EXTENSION) !== 'sqlite') {
fail('Only *.sqlite files are supported!');
}
echo 'FreshRSS exporting database to SQLite for user “', $username, "”…\n";
$databaseDAO = FreshRSS_Factory::createDatabaseDAO($username);
$ok = $databaseDAO->dbCopy($filename, FreshRSS_DatabaseDAO::SQLITE_EXPORT);
done($ok);