@procedures/restic
v0.22.1
Published
The restic backup program as one procedure: backup, snapshots, restore and forget, with JSON output and no secret as input.
Maintainers
Readme
@procedures/restic
The restic backup program as one procedure. It starts restic with argv, never through a shell.
Install
pnpm add @procedures/restic @procedures/clientA host registers the procedures with createRegistry(resticModule), or with import "@procedures/restic/register" for the global registry. The package root and ./module register nothing.
Procedures
| Procedure | Effects | What it does |
| --- | --- | --- |
| restic.run | reads and writes fs, network, process, destructive | Runs a restic command (backup, snapshots, restore, forget, check) and reads its JSON output. |
Example
// RESTIC_REPOSITORY and RESTIC_PASSWORD are in the environment
const { json } = await client.exec(["restic", "run"], { path: ["snapshots"] });Secrets
restic reads the repository and its keys from the environment (RESTIC_REPOSITORY, RESTIC_PASSWORD, B2_ACCOUNT_ID, AWS_ACCESS_KEY_ID and the others), so no secret is an input. restic.run refuses --password-command, because that flag starts a program.
A host can give the secrets only to the restic process, with the env option of createResticModule() or runRestic():
- The values go on top of the environment of the host. The value
undefinedremoves a variable of the host. - The environment of the host does not change, and the output does not contain the values.
- The procedure input has no field for them. The caller of
restic.runcannot read or change them.
const registry = createRegistry(createResticModule({ env: { RESTIC_REPOSITORY: repository, RESTIC_PASSWORD: password } }));restic can write the repository address in its error text. Remove it before you show the text to a user.
Library functions
The package root exports the functions that restic.run uses:
| Function | What it does |
| --- | --- |
| runRestic(command, options) | Starts a restic command with argv, and reads its JSON output. |
| findRestic(options) | Finds the restic program. |
| resticArgv(command) | Gives the argv of a restic command. |
| createResticModule(options) | Gives the module with the settings of the host: env and run. |
commandhaspath,positional,args,repositoryandjson.jsonis true when the command does not set it, as inrestic.run.optionsofrunRestichasexecutable,env,cwd,timeout,signalandrun.runResticthrows when restic does not start. A failed command givessuccess: false, withexitCodeandstderr.runreplaces the function that starts restic. A test gives a fake runner.findResticgivesRESTIC_EXEwhen it is set. On Windows, it then looks for therestic*.exeof a WinGet package. Then it givesrestic, and thePATHgives the program.
const executable = await findRestic();
const result = await runRestic(
{ path: ["forget"], args: { "keep-daily": 14, "keep-weekly": 12, prune: true } },
{ executable, env: { RESTIC_REPOSITORY: repository, RESTIC_PASSWORD: password } },
);