mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2025-09-06 10:30:39 +00:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
878a7bd752 | |||
f6860115a3 | |||
f43e73ce41 | |||
6b4277b57b | |||
d4b8a7223f | |||
cfcc010bc5 | |||
1fd009b819 | |||
91e902d7ef |
@@ -1,3 +1,3 @@
|
||||
## 0.21
|
||||
## 0.25
|
||||
|
||||
- switched to commander
|
||||
- disable color in CI mode
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
> :Collapse label=CLI
|
||||
>
|
||||
> [General](/cli/general)
|
||||
> [Info](/cli/info)
|
||||
> [Check](/cli/check)
|
||||
> [Backup](/cli/backup)
|
||||
|
@@ -4,7 +4,7 @@
|
||||
autorestic backup [-l, --location] [-a, --all]
|
||||
```
|
||||
|
||||
Performes a backup of all locations if the `-a` flag is passed. To only backup some locations pass one or more `-l` or `--location` flags.
|
||||
Performs a backup of all locations if the `-a` flag is passed. To only backup some locations pass one or more `-l` or `--location` flags.
|
||||
|
||||
```bash
|
||||
autorestic backup -l my-location
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# check
|
||||
# Check
|
||||
|
||||
```bash
|
||||
autorestic check [-b, --backend] [-a, --all]
|
||||
|
@@ -4,7 +4,7 @@
|
||||
autorestic cron
|
||||
```
|
||||
|
||||
This command is modtly intended to be triggered by an automated system like systemd or crontab.
|
||||
This command is mostly intended to be triggered by an automated system like systemd or crontab.
|
||||
|
||||
It will run cron jobs es [specified in the cron section](/locations/cron) of a specific location.
|
||||
|
||||
|
@@ -10,6 +10,6 @@ This is avery handy command which enables you to run any native restic command o
|
||||
autorestic exec -a -- snapshots
|
||||
```
|
||||
|
||||
With `exec` you can basically run every cli command that you would be able to run with the restic cli. It only prefillst path, key, etc.
|
||||
With `exec` you can basically run every cli command that you would be able to run with the restic cli. It only pre-fills path, key, etc.
|
||||
|
||||
> :ToCPrevNext
|
||||
|
29
docs/cli/general.md
Normal file
29
docs/cli/general.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# General
|
||||
|
||||
## `--version`
|
||||
|
||||
Prints the current version
|
||||
|
||||
```bash
|
||||
autorestic --version
|
||||
```
|
||||
|
||||
## `--c, --config`
|
||||
|
||||
Specify the config file to be used.
|
||||
If omitted `autorestic` will search for for a `.autorestic.yml` in the current directory and your home directory.
|
||||
|
||||
```bash
|
||||
autorestic -c /path/to/my/config.yml
|
||||
```
|
||||
|
||||
## `--ci`
|
||||
|
||||
> Available since version 0.22
|
||||
|
||||
Run the CLI in CI Mode, which means there will be no interactivity.
|
||||
This can be useful when you want to run cron e.g. as all the output will be saved.
|
||||
|
||||
```bash
|
||||
autorestic --ci
|
||||
```
|
@@ -1,7 +1,7 @@
|
||||
# info
|
||||
# Info
|
||||
|
||||
Displays the config file that autorestic is refering to.
|
||||
Usefull when you want to quickly see what locations are being backuped where.
|
||||
Displays the config file that autorestic is referring to.
|
||||
Useful when you want to quickly see what locations are being backed-up where.
|
||||
|
||||
**Pro tip:** if it gets a bit long you can read it more easily with `autorestic info | less` 😉
|
||||
|
||||
|
@@ -1,19 +1,21 @@
|
||||
# 🐣 Examples
|
||||
|
||||
## List all the snapshots for all the backends
|
||||
## Exec
|
||||
|
||||
### List all the snapshots for all the backends
|
||||
|
||||
```bash
|
||||
autorestic -a exec snapshots
|
||||
autorestic exec -a -- snapshots
|
||||
```
|
||||
|
||||
## Unlock a locked repository
|
||||
### Unlock a locked repository
|
||||
|
||||
If you accidentally cancelled a running operation this could be useful.
|
||||
|
||||
Only do this if you know what you are doing.
|
||||
|
||||
```bash
|
||||
autorestic -b my-backend exec unlock
|
||||
autorestic exec -b my-backend -- unlock
|
||||
```
|
||||
|
||||
> :ToCPrevNext
|
||||
|
@@ -39,9 +39,11 @@ Then paste this at the bottom of the file and save it. Note that in this specifi
|
||||
PATH="/usr/local/bin:/usr/bin:/bin"
|
||||
|
||||
# Example running every 5 minutes
|
||||
*/5 * * * * autorestic -c /srv/.autorestic.yml cron
|
||||
*/5 * * * * autorestic -c /srv/.autorestic.yml --ci cron
|
||||
```
|
||||
|
||||
Now you can add as many `cron` attributes as you wish ⏱
|
||||
> The `--ci` option is not required, but recommended
|
||||
|
||||
Now you can add as many `cron` attributes as you wish in the config file ⏱
|
||||
|
||||
> :ToCPrevNext
|
||||
|
21
package.json
21
package.json
@@ -9,19 +9,18 @@
|
||||
"docs:dev": "codedoc serve"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@codedoc/cli": "0.2.x",
|
||||
"@types/js-yaml": "3.x.x",
|
||||
"@types/minimist": "1.x.x",
|
||||
"@types/node": "14.x.x",
|
||||
"pkg": "4.4.x",
|
||||
"ts-node-dev": "^1.0.0-pre.40",
|
||||
"typescript": "3.9.x"
|
||||
"@codedoc/cli": "^0.2",
|
||||
"@types/js-yaml": "^3",
|
||||
"@types/node": "^14",
|
||||
"pkg": "^4.4",
|
||||
"ts-node-dev": "^1",
|
||||
"typescript": "^3.9"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "0.19.x",
|
||||
"clitastic": "0.0.1",
|
||||
"colors": "1.x.x",
|
||||
"commander": "^6.2.0",
|
||||
"axios": "^0.19",
|
||||
"clitastic": "^0.1.2",
|
||||
"colors": "^1",
|
||||
"commander": "^6.2",
|
||||
"cron-parser": "2.x.x",
|
||||
"js-yaml": "3.x.x",
|
||||
"uhrwerk": "1.x.x"
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { Writer } from 'clitastic'
|
||||
import { mkdirSync } from 'fs'
|
||||
|
||||
import { config, VERBOSE } from './'
|
||||
import { config, hasError, VERBOSE } from './'
|
||||
import { getEnvFromBackend } from './backend'
|
||||
import { LocationFromPrefixes } from './config'
|
||||
import { Locations, Location, Backend } from './types'
|
||||
@@ -68,6 +68,7 @@ export const backupSingle = (name: string, to: string, location: Location) => {
|
||||
|
||||
writer.done(`${name}${to.blue} : ${'Done ✓'.green} (${delta.finished(true)})`)
|
||||
} catch (e) {
|
||||
hasError()
|
||||
writer.done(`${name}${to.blue} : ${'Failed!'.red} (${delta.finished(true)}) ${e.message}`)
|
||||
}
|
||||
}
|
||||
|
69
src/index.ts
69
src/index.ts
@@ -1,5 +1,6 @@
|
||||
import 'colors'
|
||||
import colors from 'colors'
|
||||
import { program } from 'commander'
|
||||
import { setCIMode } from 'clitastic'
|
||||
|
||||
import { unlock, readLock, writeLock } from './lock'
|
||||
import { Config } from './types'
|
||||
@@ -16,24 +17,33 @@ import install from './handlers/install'
|
||||
import { uninstall } from './handlers/uninstall'
|
||||
import { upgrade } from './handlers/upgrade'
|
||||
|
||||
export const VERSION = '0.21'
|
||||
export const VERSION = '0.25'
|
||||
export const INSTALL_DIR = '/usr/local/bin'
|
||||
|
||||
let requireConfig: boolean = true
|
||||
let error: boolean = false
|
||||
|
||||
export function hasError() {
|
||||
error = true
|
||||
}
|
||||
|
||||
process.on('uncaughtException', (err) => {
|
||||
console.log(err.message)
|
||||
unlock()
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
let queue: Function = () => {}
|
||||
let queue: () => Promise<void> = async () => {}
|
||||
const enqueue = (fn: Function) => (cmd: any) => {
|
||||
queue = () => fn(cmd.opts())
|
||||
queue = async () => fn(cmd.opts())
|
||||
}
|
||||
|
||||
program.storeOptionsAsProperties()
|
||||
program.name('autorestic').description('Easy Restic CLI Utility').version(VERSION)
|
||||
|
||||
program.option('-c, --config <path>', 'Config file').option('-v, --verbose', 'Verbosity', false)
|
||||
program.option('-c, --config <path>', 'Config file')
|
||||
program.option('-v, --verbose', 'Verbosity', false)
|
||||
program.option('--ci', 'CI Mode. Removes interactivity from the shell', false)
|
||||
|
||||
program.command('info').action(enqueue(info))
|
||||
|
||||
@@ -50,7 +60,7 @@ program
|
||||
.option('-a, --all')
|
||||
.action(enqueue(check))
|
||||
|
||||
program.command('backup').description('Performs a backup').option('-b, --backend <backends...>').option('-a, --all').action(enqueue(backup))
|
||||
program.command('backup').description('Performs a backup').option('-l, --location <locations...>').option('-a, --all').action(enqueue(backup))
|
||||
|
||||
program
|
||||
.command('restore')
|
||||
@@ -80,31 +90,46 @@ program
|
||||
.option('-b, --backend <backends...>')
|
||||
.option('-a, --all')
|
||||
.action(({ args, all, backend }) => {
|
||||
queue = () => exec({ all, backend }, args)
|
||||
queue = async () => exec({ all, backend }, args)
|
||||
})
|
||||
|
||||
program.command('install').description('Installs both restic and autorestic to /usr/local/bin').action(enqueue(install))
|
||||
|
||||
program.command('uninstall').description('Uninstalls autorestic from the system').action(enqueue(uninstall))
|
||||
|
||||
program.command('upgrade').alias('update').description('Checks and installs new autorestic versions').action(enqueue(upgrade))
|
||||
program
|
||||
.command('upgrade')
|
||||
.alias('update')
|
||||
.description('Checks and installs new autorestic versions')
|
||||
.action(() => {
|
||||
requireConfig = false
|
||||
queue = upgrade
|
||||
})
|
||||
|
||||
const { verbose, config: configFile } = program.parse(process.argv)
|
||||
const { verbose, config: configFile, ci } = program.parse(process.argv)
|
||||
|
||||
export const VERBOSE = verbose
|
||||
export let config: Config = init(configFile)
|
||||
export let config: Config
|
||||
setCIMode(ci)
|
||||
if (ci) colors.disable()
|
||||
|
||||
try {
|
||||
const lock = readLock()
|
||||
if (lock.running) throw new Error('An instance of autorestic is already running for this config file'.red)
|
||||
async function main() {
|
||||
try {
|
||||
const lock = readLock()
|
||||
if (lock.running) throw new Error('An instance of autorestic is already running for this config file'.red)
|
||||
|
||||
writeLock({
|
||||
...lock,
|
||||
running: true,
|
||||
})
|
||||
queue()
|
||||
} catch (e) {
|
||||
console.error(e.message)
|
||||
} finally {
|
||||
unlock()
|
||||
writeLock({
|
||||
...lock,
|
||||
running: true,
|
||||
})
|
||||
|
||||
if (requireConfig) config = init(configFile)
|
||||
await queue()
|
||||
if (error) process.exit(1)
|
||||
} catch (e) {
|
||||
console.error(e.message)
|
||||
} finally {
|
||||
unlock()
|
||||
}
|
||||
}
|
||||
main()
|
||||
|
49
yarn.lock
49
yarn.lock
@@ -14,7 +14,7 @@
|
||||
dependencies:
|
||||
regenerator-runtime "^0.13.4"
|
||||
|
||||
"@codedoc/cli@0.2.x":
|
||||
"@codedoc/cli@^0.2":
|
||||
version "0.2.6"
|
||||
resolved "https://registry.yarnpkg.com/@codedoc/cli/-/cli-0.2.6.tgz#5e6e981f8eafefcab2b8c81ee6c14815baf2732c"
|
||||
integrity sha512-zn92PvMamXCteZudz1i606qa4bPXcXveNgb6oQTAiW7Lq+bRMZHUyKvA3Q3jVwlQtV7SidJg3jA4RwkMllktog==
|
||||
@@ -46,20 +46,15 @@
|
||||
"@nodelib/fs.scandir" "2.1.3"
|
||||
fastq "^1.6.0"
|
||||
|
||||
"@types/js-yaml@3.x.x":
|
||||
"@types/js-yaml@^3":
|
||||
version "3.12.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.12.5.tgz#136d5e6a57a931e1cce6f9d8126aa98a9c92a6bb"
|
||||
integrity sha512-JCcp6J0GV66Y4ZMDAQCXot4xprYB+Zfd3meK9+INSJeVZwJmHAW30BBEEkPzXswMXuiyReUGOP3GxrADc9wPww==
|
||||
|
||||
"@types/minimist@1.x.x":
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
|
||||
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=
|
||||
|
||||
"@types/node@14.x.x":
|
||||
version "14.14.6"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.6.tgz#146d3da57b3c636cc0d1769396ce1cfa8991147f"
|
||||
integrity sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw==
|
||||
"@types/node@^14":
|
||||
version "14.14.7"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.7.tgz#8ea1e8f8eae2430cf440564b98c6dfce1ec5945d"
|
||||
integrity sha512-Zw1vhUSQZYw+7u5dAwNbIA9TuTotpzY/OF7sJM9FqPOF3SPjKnxrjoTktXDZgUjybf4cWVBP7O8wvKdSaGHweg==
|
||||
|
||||
"@types/strip-bom@^3.0.0":
|
||||
version "3.0.0"
|
||||
@@ -145,7 +140,7 @@ aws4@^1.8.0:
|
||||
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
|
||||
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
|
||||
|
||||
axios@0.19.x:
|
||||
axios@^0.19:
|
||||
version "0.19.2"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"
|
||||
integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==
|
||||
@@ -243,12 +238,10 @@ chokidar@^3.4.0:
|
||||
optionalDependencies:
|
||||
fsevents "~2.1.2"
|
||||
|
||||
clitastic@0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/clitastic/-/clitastic-0.0.1.tgz#4b1a571447191cc311f5043b3ed49f3b6a0381d9"
|
||||
integrity sha512-Akvm5MK1x+vyHyyUlTCKGjkPFK0fuJe/wMf634grLZdopsys1vzv24d4MCU7O9DQldPM+TbIeExm2Wz7jSYaOA==
|
||||
dependencies:
|
||||
colors "^1.3.3"
|
||||
clitastic@^0.1.2:
|
||||
version "0.1.2"
|
||||
resolved "https://registry.yarnpkg.com/clitastic/-/clitastic-0.1.2.tgz#a2d4d14fe9c76fd4a180a2a0a4cccb2d27c2bcaf"
|
||||
integrity sha512-xBvBTAuDys0u4aLoBZ+pGIPeTM3cqykylRxmaGv78QdMKo/uq3jgbiZGBUWkWufHfLXPlkSb0nDQq4+oXbTHug==
|
||||
|
||||
color-convert@^2.0.1:
|
||||
version "2.0.1"
|
||||
@@ -262,7 +255,7 @@ color-name@~1.1.4:
|
||||
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
|
||||
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
|
||||
|
||||
colors@1.x.x, colors@^1.3.3:
|
||||
colors@^1:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
|
||||
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
|
||||
@@ -274,7 +267,7 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
|
||||
dependencies:
|
||||
delayed-stream "~1.0.0"
|
||||
|
||||
commander@^6.2.0:
|
||||
commander@^6.2:
|
||||
version "6.2.0"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.0.tgz#b990bfb8ac030aedc6d11bc04d1488ffef56db75"
|
||||
integrity sha512-zP4jEKbe8SHzKJYQmq8Y9gYjtO/POJLgIdKgV7B9qNmABVFVc+ctqSX6iXh4mCpJfRBOabiZ2YKPg8ciDw6C+Q==
|
||||
@@ -668,7 +661,7 @@ is-binary-path@~2.1.0:
|
||||
dependencies:
|
||||
binary-extensions "^2.0.0"
|
||||
|
||||
is-core-module@^2.0.0:
|
||||
is-core-module@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.1.0.tgz#a4cc031d9b1aca63eecbd18a650e13cb4eeab946"
|
||||
integrity sha512-YcV7BgVMRFRua2FqQzKtTDMz8iCuLEyGKjr70q8Zm1yy2qKcurbFEd79PAdHV77oL3NrAaOVQIbMmiHQCHB7ZA==
|
||||
@@ -1037,7 +1030,7 @@ pkg-fetch@^2.6.9:
|
||||
semver "^6.3.0"
|
||||
unique-temp-dir "^1.0.0"
|
||||
|
||||
pkg@4.4.x:
|
||||
pkg@^4.4:
|
||||
version "4.4.9"
|
||||
resolved "https://registry.yarnpkg.com/pkg/-/pkg-4.4.9.tgz#be04f8d03795772b7c4394724ae7252d7c2a4519"
|
||||
integrity sha512-FK4GqHtcCY2PPPVaKViU0NyRzpo6gCS7tPKN5b7AkElqjAOCH1bsRKgohEnxThr6DWfTGByGqba2YHGR/BqbmA==
|
||||
@@ -1184,11 +1177,11 @@ request@^2.88.0:
|
||||
uuid "^3.3.2"
|
||||
|
||||
resolve@^1.0.0, resolve@^1.1.6, resolve@^1.10.0, resolve@^1.15.1:
|
||||
version "1.18.1"
|
||||
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.18.1.tgz#018fcb2c5b207d2a6424aee361c5a266da8f4130"
|
||||
integrity sha512-lDfCPaMKfOJXjy0dPayzPdF1phampNWr3qFCjAu+rw/qbQmr5jWH5xN2hwh9QKfw9E5v4hwV7A+jrCmL8yjjqA==
|
||||
version "1.19.0"
|
||||
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c"
|
||||
integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==
|
||||
dependencies:
|
||||
is-core-module "^2.0.0"
|
||||
is-core-module "^2.1.0"
|
||||
path-parse "^1.0.6"
|
||||
|
||||
reusify@^1.0.4:
|
||||
@@ -1386,7 +1379,7 @@ trim-newlines@^1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613"
|
||||
integrity sha1-WIeWa7WCpFA6QetST301ARgVphM=
|
||||
|
||||
ts-node-dev@^1.0.0-pre.40, ts-node-dev@^1.0.0-pre.44:
|
||||
ts-node-dev@^1, ts-node-dev@^1.0.0-pre.44:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ts-node-dev/-/ts-node-dev-1.0.0.tgz#24a2270d225c29ce269de2a31f88b1b259fc84cb"
|
||||
integrity sha512-leA/3TgGtnVU77fGngBwVZztqyDRXirytR7dMtMWZS5b2hGpLl+VDnB0F/gf3A+HEPSzS/KwxgXFP7/LtgX4MQ==
|
||||
@@ -1454,7 +1447,7 @@ type-check@~0.3.2:
|
||||
dependencies:
|
||||
prelude-ls "~1.1.2"
|
||||
|
||||
typescript@3.9.x, typescript@^3.8.3:
|
||||
typescript@^3.8.3, typescript@^3.9:
|
||||
version "3.9.7"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
|
||||
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==
|
||||
|
Reference in New Issue
Block a user