1 Commits
Author SHA1 Message Date
sugoidogo 8eab92841f handle and log unknown items
Main / release (push) Successful in 41s
2026-01-14 00:43:01 -08:00
+16 -3
View File
@@ -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)