|
|
@ -135,31 +135,24 @@ async function backupToRemote(config: RunConfig): Promise<void> { |
|
|
|
const borgpath = `ssh://${config.remote.host}${destpath}`; |
|
|
|
|
|
|
|
try { |
|
|
|
await localRun( |
|
|
|
["borg", "check", borgpath], |
|
|
|
"/tmp", |
|
|
|
{ BORG_PASSPHRASE: config.remote.passphrase }, |
|
|
|
); |
|
|
|
await borgRun(["check", borgpath], config.remote); |
|
|
|
} catch { |
|
|
|
await localRun( |
|
|
|
["borg", "init", "--encryption=repokey", "--make-parent-dirs", borgpath], |
|
|
|
"/tmp", |
|
|
|
{ BORG_PASSPHRASE: config.remote.passphrase }, |
|
|
|
await borgRun( |
|
|
|
["init", "--encryption=repokey", "--make-parent-dirs", borgpath], |
|
|
|
config.remote, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
const command: string[] = [ |
|
|
|
"borg", |
|
|
|
"create", |
|
|
|
`${borgpath}::{now}`, |
|
|
|
]; |
|
|
|
for (let [name, directory] of Object.entries(config.program.saves)) { |
|
|
|
command.push(makeAbsolute(directory, config.program.directory)); |
|
|
|
} |
|
|
|
await localRun( |
|
|
|
command, |
|
|
|
"/tmp", |
|
|
|
{ BORG_PASSPHRASE: config.remote.passphrase }, |
|
|
|
await borgRun( |
|
|
|
[ |
|
|
|
"create", |
|
|
|
`${borgpath}::{now}`, |
|
|
|
].concat( |
|
|
|
Object.values(config.program.saves).map((dir) => |
|
|
|
makeAbsolute(dir, config.program.directory) |
|
|
|
), |
|
|
|
), |
|
|
|
config.remote, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
@ -177,6 +170,22 @@ export function makeAbsolute(dir: string, cwd: string): string { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Run a borg command |
|
|
|
*/ |
|
|
|
async function borgRun( |
|
|
|
cmd: string[], |
|
|
|
remote: RemoteConfig, |
|
|
|
allow_fail = false, |
|
|
|
): Promise<void> { |
|
|
|
await localRun( |
|
|
|
["borg"].concat(cmd), |
|
|
|
"/tmp", |
|
|
|
{ BORG_PASSPHRASE: remote.passphrase }, |
|
|
|
allow_fail, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Run a local program |
|
|
|
*/ |
|
|
|