From d47e7d0912d575e011bc2084f3889d102bcd9e9c Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sat, 26 Oct 2019 20:07:52 +0200 Subject: [PATCH] directories are now relative to its config file location --- src/backup.ts | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/backup.ts b/src/backup.ts index 352aa89..5f2a874 100644 --- a/src/backup.ts +++ b/src/backup.ts @@ -4,34 +4,38 @@ import { config, VERBOSE } from './autorestic' import { getEnvFromBackend } from './backend' import { Locations, Location } from './types' import { exec } from './utils' - +import { CONFIG_FILE } from './config' +import { resolve, dirname } from 'path' export const backupSingle = (name: string, from: string, to: string) => { - const writer = new Writer(name + to.blue + ' : ' + 'Backing up... ⏳') - const backend = config.backends[to] - const cmd = exec('restic', ['backup', from], { env: getEnvFromBackend(backend) }) + const writer = new Writer(name + to.blue + ' : ' + 'Backing up... ⏳') + const backend = config.backends[to] + const pathRelativeToConfigFile = resolve(dirname(CONFIG_FILE), from) - if (VERBOSE) console.log(cmd.out, cmd.err) - writer.done(name + to.blue + ' : ' + 'Done ✓'.green) -} + const cmd = exec('restic', ['backup', pathRelativeToConfigFile], { + env: getEnvFromBackend(backend), + }) + if (VERBOSE) console.log(cmd.out, cmd.err) + writer.done(name + to.blue + ' : ' + 'Done ✓'.green) +} export const backupLocation = (name: string, backup: Location) => { - const display = name.yellow + ' ▶ ' - if (Array.isArray(backup.to)) { - let first = true - for (const t of backup.to) { - const nameOrBlankSpaces: string = first ? display : new Array(name.length + 3).fill(' ').join('') - backupSingle(nameOrBlankSpaces, backup.from, t) - if (first) first = false - } - } else - backupSingle(display, backup.from, backup.to) + const display = name.yellow + ' ▶ ' + if (Array.isArray(backup.to)) { + let first = true + for (const t of backup.to) { + const nameOrBlankSpaces: string = first + ? display + : new Array(name.length + 3).fill(' ').join('') + backupSingle(nameOrBlankSpaces, backup.from, t) + if (first) first = false + } + } else backupSingle(display, backup.from, backup.to) } - export const backupAll = (backups: Locations = config.locations) => { - console.log('\nBacking Up'.underline.grey) - for (const [name, backup] of Object.entries(backups)) - backupLocation(name, backup) -} \ No newline at end of file + console.log('\nBacking Up'.underline.grey) + for (const [name, backup] of Object.entries(backups)) + backupLocation(name, backup) +}