Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb4e872990 | ||
|
|
e3893f594e | ||
|
|
2457617bdc | ||
|
|
8ae7880d6b | ||
|
|
81ab7be40c | ||
|
|
422a36bbeb | ||
|
|
e49b1d9a4b |
+1
-1
@@ -16,7 +16,7 @@ for (const target of targets) {
|
||||
sugoiSpawn('deno', 'compile',
|
||||
'--target', target,
|
||||
'--include', 'src/snapper-template.txt',
|
||||
'--include', 'src/snapper@.service',
|
||||
'--include', 'src/snapback@.service',
|
||||
'--output', 'dist/snapback-'+target,
|
||||
'--permission-set','src/main.ts'
|
||||
)
|
||||
|
||||
+22
-3
@@ -7,11 +7,26 @@ import path from "node:path"
|
||||
import strftime from 'strftime'
|
||||
import { spawnSync } from "node:child_process"
|
||||
|
||||
const logfd = fs.openSync('/etc/snapback/log.txt', 'w')
|
||||
|
||||
function logToFile() {
|
||||
// Source - https://stackoverflow.com/a/35542360
|
||||
// Posted by Anatol - user3173842
|
||||
// Retrieved 2026-01-14, License - CC BY-SA 3.0
|
||||
|
||||
var access = fs.createWriteStream('',{'fd':logfd});
|
||||
process.stdout.write = process.stderr.write = access.write.bind(access);
|
||||
|
||||
process.on('uncaughtException', function (err) {
|
||||
console.error((err && err.stack) ? err.stack : err);
|
||||
});
|
||||
}
|
||||
|
||||
let config: { [key: string]: string } = {}
|
||||
let index: { [key: string]: { [key: string]: string } } = {}
|
||||
|
||||
function sugoiSpawn(...command: string[]) {
|
||||
const result = spawnSync(command.shift()!, command, { stdio: 'inherit' })
|
||||
const result = spawnSync(command.shift()!, command, { stdio: ['ignore',logfd,logfd] })
|
||||
if (result.error) throw result.error
|
||||
if (result.status !== 0) process.exit(result.status)
|
||||
return result
|
||||
@@ -36,12 +51,12 @@ program.command('*').description('snapback ignores unknown commands')
|
||||
program.command('install').description('installs snapback on your system')
|
||||
.action(function () {
|
||||
const template = fs.readFileSync(import.meta.dirname + '/snapper-template.txt')
|
||||
const service = fs.readFileSync(import.meta.dirname + '/snapper@.service')
|
||||
const service = fs.readFileSync(import.meta.dirname + '/snapback@.service')
|
||||
let lib_snapper = '/usr/libexec/snapper'
|
||||
if (!fs.existsSync(lib_snapper)) lib_snapper = '/usr/lib/snapper'
|
||||
if (!fs.existsSync('/etc/snapper/config-templates')) fs.mkdirSync('/etc/snapper/config-templates')
|
||||
fs.writeFileSync('/etc/snapper/config-templates/snapback', template, 'utf8')
|
||||
fs.writeFileSync('/etc/systemd/system/snapper@.service', service, 'utf8')
|
||||
fs.writeFileSync('/etc/systemd/system/snapback@.service', service, 'utf8')
|
||||
fs.mkdirSync(lib_snapper + '/plugins', { recursive: true })
|
||||
let argv0 = process.argv0
|
||||
if (['node','deno','bun'].includes(path.basename(argv0).replace('.exe',''))) {
|
||||
@@ -49,12 +64,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) {
|
||||
logToFile()
|
||||
if (!config[subvolume]) return
|
||||
const destination = strftime(config[subvolume])
|
||||
const dirname = path.dirname(destination)
|
||||
@@ -71,6 +88,7 @@ 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) {
|
||||
logToFile()
|
||||
const destination = index[subvolume][number]
|
||||
fs.unlinkSync(destination)
|
||||
delete index[subvolume][number]
|
||||
@@ -80,6 +98,7 @@ program.command('delete-snapshot-post <subvolume> <fstype> <number>')
|
||||
program.command('delete-config-post <subvolume> <fstype>')
|
||||
.description('delete metadata of deleted subvolume, retaining backups')
|
||||
.action(function (subvolume, fstype) {
|
||||
logToFile()
|
||||
delete index[subvolume]
|
||||
const destination = strftime(config[subvolume])
|
||||
const dirname = path.dirname(destination)
|
||||
|
||||
@@ -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