|
|
@ -19,6 +19,8 @@ import {
|
|
|
|
ConfigError,
|
|
|
|
ConfigError,
|
|
|
|
} from './utils'
|
|
|
|
} from './utils'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type Handlers = {
|
|
|
|
export type Handlers = {
|
|
|
|
[command: string]: (args: string[], flags: Flags) => void
|
|
|
|
[command: string]: (args: string[], flags: Flags) => void
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -29,7 +31,7 @@ const parseBackend = (flags: Flags): Backends => {
|
|
|
|
throw new Error(
|
|
|
|
throw new Error(
|
|
|
|
'No backends specified.'.red +
|
|
|
|
'No backends specified.'.red +
|
|
|
|
'\n--all [-a]\t\t\t\tCheck all.' +
|
|
|
|
'\n--all [-a]\t\t\t\tCheck all.' +
|
|
|
|
'\n--backend [-b] myBackend\t\tSpecify one or more backend'
|
|
|
|
'\n--backend [-b] myBackend\t\tSpecify one or more backend',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if (flags.all) return config.backends
|
|
|
|
if (flags.all) return config.backends
|
|
|
|
else {
|
|
|
|
else {
|
|
|
@ -47,7 +49,7 @@ const parseLocations = (flags: Flags): Locations => {
|
|
|
|
throw new Error(
|
|
|
|
throw new Error(
|
|
|
|
'No locations specified.'.red +
|
|
|
|
'No locations specified.'.red +
|
|
|
|
'\n--all [-a]\t\t\t\tBackup all.' +
|
|
|
|
'\n--all [-a]\t\t\t\tBackup all.' +
|
|
|
|
'\n--location [-l] site1\t\t\tSpecify one or more locations'
|
|
|
|
'\n--location [-l] site1\t\t\tSpecify one or more locations',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if (flags.all) {
|
|
|
|
if (flags.all) {
|
|
|
@ -77,7 +79,7 @@ const handlers: Handlers = {
|
|
|
|
Array.isArray(to) ? to.forEach(t => backends.add(t)) : backends.add(to)
|
|
|
|
Array.isArray(to) ? to.forEach(t => backends.add(t)) : backends.add(to)
|
|
|
|
|
|
|
|
|
|
|
|
checkAndConfigureBackends(
|
|
|
|
checkAndConfigureBackends(
|
|
|
|
filterObjectByKey(config.backends, Array.from(backends))
|
|
|
|
filterObjectByKey(config.backends, Array.from(backends)),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
backupAll(locations)
|
|
|
|
backupAll(locations)
|
|
|
|
|
|
|
|
|
|
|
@ -92,13 +94,13 @@ const handlers: Handlers = {
|
|
|
|
const env = getEnvFromBackend(
|
|
|
|
const env = getEnvFromBackend(
|
|
|
|
config.backends[
|
|
|
|
config.backends[
|
|
|
|
Array.isArray(location.to) ? location.to[0] : location.to
|
|
|
|
Array.isArray(location.to) ? location.to[0] : location.to
|
|
|
|
]
|
|
|
|
],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
exec(
|
|
|
|
exec(
|
|
|
|
'restic',
|
|
|
|
'restic',
|
|
|
|
['restore', 'latest', '--path', resolve(location.from), ...args],
|
|
|
|
['restore', 'latest', '--path', resolve(location.from), ...args],
|
|
|
|
{ env }
|
|
|
|
{ env },
|
|
|
|
)
|
|
|
|
)
|
|
|
|
w.done(name.green + '\t\tDone 🎉')
|
|
|
|
w.done(name.green + '\t\tDone 🎉')
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -113,7 +115,7 @@ const handlers: Handlers = {
|
|
|
|
Array.isArray(to) ? to.forEach(t => backends.add(t)) : backends.add(to)
|
|
|
|
Array.isArray(to) ? to.forEach(t => backends.add(t)) : backends.add(to)
|
|
|
|
|
|
|
|
|
|
|
|
checkAndConfigureBackends(
|
|
|
|
checkAndConfigureBackends(
|
|
|
|
filterObjectByKey(config.backends, Array.from(backends))
|
|
|
|
filterObjectByKey(config.backends, Array.from(backends)),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
forgetAll(flags['dry-run'], locations)
|
|
|
|
forgetAll(flags['dry-run'], locations)
|
|
|
|
|
|
|
|
|
|
|
@ -135,7 +137,8 @@ const handlers: Handlers = {
|
|
|
|
checkIfResticIsAvailable()
|
|
|
|
checkIfResticIsAvailable()
|
|
|
|
console.log('Restic is already installed')
|
|
|
|
console.log('Restic is already installed')
|
|
|
|
return
|
|
|
|
return
|
|
|
|
} catch (e) {}
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const w = new Writer('Checking latest version... ⏳')
|
|
|
|
const w = new Writer('Checking latest version... ⏳')
|
|
|
|
checkIfCommandIsAvailable('bzip2')
|
|
|
|
checkIfCommandIsAvailable('bzip2')
|
|
|
@ -158,7 +161,7 @@ const handlers: Handlers = {
|
|
|
|
if (!dl)
|
|
|
|
if (!dl)
|
|
|
|
return console.log(
|
|
|
|
return console.log(
|
|
|
|
'Cannot get the right binary.'.red,
|
|
|
|
'Cannot get the right binary.'.red,
|
|
|
|
'Please see https://bit.ly/2Y1Rzai'
|
|
|
|
'Please see https://bit.ly/2Y1Rzai',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const tmp = join(tmpdir(), name)
|
|
|
|
const tmp = join(tmpdir(), name)
|
|
|
@ -177,7 +180,7 @@ const handlers: Handlers = {
|
|
|
|
exec('mv', [extracted, INSTALL_DIR + '/restic'])
|
|
|
|
exec('mv', [extracted, INSTALL_DIR + '/restic'])
|
|
|
|
|
|
|
|
|
|
|
|
w.done(
|
|
|
|
w.done(
|
|
|
|
`\nFinished! restic is installed under: ${INSTALL_DIR}`.underline + ' 🎉'
|
|
|
|
`\nFinished! restic is installed under: ${INSTALL_DIR}`.underline + ' 🎉',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
uninstall() {
|
|
|
|
uninstall() {
|
|
|
@ -248,14 +251,14 @@ export const help = () => {
|
|
|
|
'\n' +
|
|
|
|
'\n' +
|
|
|
|
'\nExamples: '.yellow +
|
|
|
|
'\nExamples: '.yellow +
|
|
|
|
'https://git.io/fjVbg' +
|
|
|
|
'https://git.io/fjVbg' +
|
|
|
|
'\n'
|
|
|
|
'\n',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export const error = () => {
|
|
|
|
export const error = () => {
|
|
|
|
help()
|
|
|
|
help()
|
|
|
|
console.log(
|
|
|
|
console.log(
|
|
|
|
`Invalid Command:`.red.underline,
|
|
|
|
`Invalid Command:`.red.underline,
|
|
|
|
`${process.argv.slice(2).join(' ')}`
|
|
|
|
`${process.argv.slice(2).join(' ')}`,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|