mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix --dbOnly option for dump
This commit is contained in:
1 file changed
+10
-8
@@ -39,7 +39,7 @@ export function register(cli: CAC) {
|
|||||||
child.spawn('mongo', [url], { stdio: 'inherit' });
|
child.spawn('mongo', [url], { stdio: 'inherit' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
cli.command('backup').action(() => {
|
cli.command('backup').option('--dbOnly', 'Only dump database', { default: false }).action(() => {
|
||||||
const url = getUrl();
|
const url = getUrl();
|
||||||
exec('mongodump', [url, `--out=${dir}/dump`], { stdio: 'inherit' });
|
exec('mongodump', [url, `--out=${dir}/dump`], { stdio: 'inherit' });
|
||||||
const target = `${process.cwd()}/backup-${new Date().toISOString().replace(':', '-').split(':')[0]}.zip`;
|
const target = `${process.cwd()}/backup-${new Date().toISOString().replace(':', '-').split(':')[0]}.zip`;
|
||||||
@@ -51,18 +51,20 @@ export function register(cli: CAC) {
|
|||||||
const stat = fs.statSync(target);
|
const stat = fs.statSync(target);
|
||||||
logger.success(`Database backup saved at ${target} , size: ${size(stat.size)}`);
|
logger.success(`Database backup saved at ${target} , size: ${size(stat.size)}`);
|
||||||
});
|
});
|
||||||
cli.command('restore <filename>').action(async (filename) => {
|
cli.command('restore <filename>').option('-y', 'Assume yes', { default: false }).action(async (filename) => {
|
||||||
const url = getUrl();
|
const url = getUrl();
|
||||||
if (!fs.existsSync(filename)) {
|
if (!fs.existsSync(filename)) {
|
||||||
logger.error('Cannot find file');
|
logger.error('Cannot find file');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const rl = readline.createInterface(process.stdin, process.stdout);
|
if (!argv.options.y) {
|
||||||
const answer = await rl.question(`Overwrite current database with backup file ${filename}? [y/N]`);
|
const rl = readline.createInterface(process.stdin, process.stdout);
|
||||||
rl.close();
|
const answer = await rl.question(`Overwrite current database with backup file ${filename}? [y/N]`);
|
||||||
if (answer.toLowerCase() !== 'y') {
|
rl.close();
|
||||||
logger.warn('Abort.');
|
if (answer.toLowerCase() !== 'y') {
|
||||||
return;
|
logger.warn('Abort.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exec('unzip', [filename, '-d', dir], { stdio: 'inherit' });
|
exec('unzip', [filename, '-d', dir], { stdio: 'inherit' });
|
||||||
exec('mongorestore', [`--uri=${url}`, `--dir=${dir}/dump/hydro`, '--drop'], { stdio: 'inherit' });
|
exec('mongorestore', [`--uri=${url}`, `--dir=${dir}/dump/hydro`, '--drop'], { stdio: 'inherit' });
|
||||||
|
|||||||
Reference in new issue
Block a user