7 Commits
Author SHA1 Message Date
sugoidogo fb4e872990 fix output piping
Main / release (push) Successful in 42s
2026-01-14 00:30:11 -08:00
sugoidogo e3893f594e fix subcommand output
Main / release (push) Successful in 42s
2026-01-14 00:21:48 -08:00
sugoidogo 2457617bdc redirect subcommand output to file
Main / release (push) Successful in 41s
2026-01-14 00:17:04 -08:00
sugoidogo 8ae7880d6b log output to file
Main / release (push) Successful in 40s
2026-01-14 00:09:38 -08:00
sugoidogo 81ab7be40c reload systemd after install
Main / release (push) Successful in 41s
2026-01-13 23:51:00 -08:00
sugoidogo 422a36bbeb fix create-config
Main / release (push) Successful in 41s
2026-01-13 23:45:15 -08:00
sugoidogo e49b1d9a4b BREAKING CHANGE: rename service
Main / release (push) Successful in 42s
2026-01-13 23:18:41 -08:00
3 changed files with 24 additions and 5 deletions
+1 -1
View File
@@ -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
View File
@@ -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