mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2024-12-22 08:16:25 +00:00
directories are now relative to its config file location
This commit is contained in:
parent
e47d6be854
commit
d47e7d0912
@ -4,34 +4,38 @@ import { config, VERBOSE } from './autorestic'
|
|||||||
import { getEnvFromBackend } from './backend'
|
import { getEnvFromBackend } from './backend'
|
||||||
import { Locations, Location } from './types'
|
import { Locations, Location } from './types'
|
||||||
import { exec } from './utils'
|
import { exec } from './utils'
|
||||||
|
import { CONFIG_FILE } from './config'
|
||||||
|
import { resolve, dirname } from 'path'
|
||||||
|
|
||||||
export const backupSingle = (name: string, from: string, to: string) => {
|
export const backupSingle = (name: string, from: string, to: string) => {
|
||||||
const writer = new Writer(name + to.blue + ' : ' + 'Backing up... ⏳')
|
const writer = new Writer(name + to.blue + ' : ' + 'Backing up... ⏳')
|
||||||
const backend = config.backends[to]
|
const backend = config.backends[to]
|
||||||
const cmd = exec('restic', ['backup', from], { env: getEnvFromBackend(backend) })
|
const pathRelativeToConfigFile = resolve(dirname(CONFIG_FILE), from)
|
||||||
|
|
||||||
if (VERBOSE) console.log(cmd.out, cmd.err)
|
const cmd = exec('restic', ['backup', pathRelativeToConfigFile], {
|
||||||
writer.done(name + to.blue + ' : ' + 'Done ✓'.green)
|
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) => {
|
export const backupLocation = (name: string, backup: Location) => {
|
||||||
const display = name.yellow + ' ▶ '
|
const display = name.yellow + ' ▶ '
|
||||||
if (Array.isArray(backup.to)) {
|
if (Array.isArray(backup.to)) {
|
||||||
let first = true
|
let first = true
|
||||||
for (const t of backup.to) {
|
for (const t of backup.to) {
|
||||||
const nameOrBlankSpaces: string = first ? display : new Array(name.length + 3).fill(' ').join('')
|
const nameOrBlankSpaces: string = first
|
||||||
backupSingle(nameOrBlankSpaces, backup.from, t)
|
? display
|
||||||
if (first) first = false
|
: new Array(name.length + 3).fill(' ').join('')
|
||||||
}
|
backupSingle(nameOrBlankSpaces, backup.from, t)
|
||||||
} else
|
if (first) first = false
|
||||||
backupSingle(display, backup.from, backup.to)
|
}
|
||||||
|
} else backupSingle(display, backup.from, backup.to)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const backupAll = (backups: Locations = config.locations) => {
|
export const backupAll = (backups: Locations = config.locations) => {
|
||||||
console.log('\nBacking Up'.underline.grey)
|
console.log('\nBacking Up'.underline.grey)
|
||||||
for (const [name, backup] of Object.entries(backups))
|
for (const [name, backup] of Object.entries(backups))
|
||||||
backupLocation(name, backup)
|
backupLocation(name, backup)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user