Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8549cfd4da | ||
|
|
81086a7628 | ||
|
|
02ff1b58f7 | ||
|
|
8eab92841f | ||
|
|
fb4e872990 | ||
|
|
e3893f594e | ||
|
|
2457617bdc | ||
|
|
8ae7880d6b | ||
|
|
81ab7be40c | ||
|
|
422a36bbeb |
+19
-4
@@ -4,11 +4,12 @@ import { program } from "commander"
|
||||
import { parseJSON, parseTOML, stringifyJSON } from "confbox"
|
||||
import fs from "node:fs"
|
||||
import path from "node:path"
|
||||
import util from 'node:util'
|
||||
import strftime from 'strftime'
|
||||
import { spawnSync } from "node:child_process"
|
||||
|
||||
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: 'inherit' })
|
||||
@@ -49,13 +50,14 @@ program.command('install').description('installs snapback on your system')
|
||||
}
|
||||
fs.renameSync(argv0, lib_snapper + '/plugins/99-snapback')
|
||||
sugoiSpawn('chmod', '+x', lib_snapper + '/plugins/99-snapback')
|
||||
sugoiSpawn('systemctl','daemon-reload')
|
||||
console.log('snapback installed')
|
||||
})
|
||||
|
||||
program.command('create-snapshot-post <subvolume> <fstype> <number>')
|
||||
.description('create a backup after a snapshot')
|
||||
.action(function (subvolume, fstype, number) {
|
||||
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 {}
|
||||
@@ -64,6 +66,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)
|
||||
})
|
||||
@@ -71,7 +74,15 @@ program.command('create-snapshot-post <subvolume> <fstype> <number>')
|
||||
program.command('delete-snapshot-post <subvolume> <fstype> <number>')
|
||||
.description('delete a backup after deleting a snapshot')
|
||||
.action(function (subvolume, fstype, number) {
|
||||
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)
|
||||
@@ -81,6 +92,10 @@ program.command('delete-config-post <subvolume> <fstype>')
|
||||
.description('delete metadata of deleted subvolume, retaining backups')
|
||||
.action(function (subvolume, fstype) {
|
||||
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)
|
||||
@@ -88,4 +103,4 @@ program.command('delete-config-post <subvolume> <fstype>')
|
||||
|
||||
program.parse()
|
||||
|
||||
if (Object.keys(index).length) fs.writeFileSync(program.opts().indexFile,stringifyJSON(index), 'utf8')
|
||||
fs.writeFileSync(program.opts().indexFile,stringifyJSON(index), 'utf8')
|
||||
@@ -1,5 +1,5 @@
|
||||
[Service]
|
||||
Type=exec
|
||||
ExecStartPre=-btrfs subvolume create %I
|
||||
ExecStartPre=-snapper --config %i create-config %I --template snapback
|
||||
ExecStartPre=-snapper --config %i create-config --template snapback %I
|
||||
ExecStart=snapper --config %i create --cleanup-algorithm number
|
||||
Reference in New Issue
Block a user