Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8eab92841f |
+16
-3
@@ -22,8 +22,8 @@ function logToFile() {
|
||||
});
|
||||
}
|
||||
|
||||
let config: { [key: string]: string } = {}
|
||||
let index: { [key: string]: { [key: string]: string } } = {}
|
||||
let config: { [key: string]: string|undefined } = {}
|
||||
let index: { [key: string]: { [key: string]: string|undefined }|undefined } = {}
|
||||
|
||||
function sugoiSpawn(...command: string[]) {
|
||||
const result = spawnSync(command.shift()!, command, { stdio: ['ignore',logfd,logfd] })
|
||||
@@ -72,7 +72,7 @@ program.command('create-snapshot-post <subvolume> <fstype> <number>')
|
||||
.description('create a backup after a snapshot')
|
||||
.action(function (subvolume, fstype, number) {
|
||||
logToFile()
|
||||
if (!config[subvolume]) return
|
||||
if (!config[subvolume]) {console.log(subvolume + ' not configured for snapback'); return}
|
||||
const destination = strftime(config[subvolume])
|
||||
const dirname = path.dirname(destination)
|
||||
try { fs.mkdirSync(dirname, { 'recursive': true }) } catch {}
|
||||
@@ -81,6 +81,7 @@ program.command('create-snapshot-post <subvolume> <fstype> <number>')
|
||||
'--create', '--file', destination,
|
||||
'--auto-compress', '--dereference', '.'
|
||||
)
|
||||
if(!index[subvolume]) index[subvolume]={}
|
||||
index[subvolume][number] = destination
|
||||
console.log('created backup at '+destination)
|
||||
})
|
||||
@@ -89,7 +90,15 @@ program.command('delete-snapshot-post <subvolume> <fstype> <number>')
|
||||
.description('delete a backup after deleting a snapshot')
|
||||
.action(function (subvolume, fstype, number) {
|
||||
logToFile()
|
||||
if (!index[subvolume]) {
|
||||
console.log('no backups indexed for ' + subvolume)
|
||||
return
|
||||
}
|
||||
const destination = index[subvolume][number]
|
||||
if (!destination) {
|
||||
console.log('no backup indexed for ' + subvolume + ':' + number)
|
||||
return
|
||||
}
|
||||
fs.unlinkSync(destination)
|
||||
delete index[subvolume][number]
|
||||
console.log('deleted backup at '+destination)
|
||||
@@ -100,6 +109,10 @@ program.command('delete-config-post <subvolume> <fstype>')
|
||||
.action(function (subvolume, fstype) {
|
||||
logToFile()
|
||||
delete index[subvolume]
|
||||
if (!config[subvolume]) {
|
||||
console.log(subvolume + ' not configured for snapback')
|
||||
return
|
||||
}
|
||||
const destination = strftime(config[subvolume])
|
||||
const dirname = path.dirname(destination)
|
||||
console.log('existing backups remain at '+dirname)
|
||||
|
||||
Reference in New Issue
Block a user