3 Commits
Author SHA1 Message Date
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
+18 -1
View File
@@ -7,11 +7,25 @@ import path from "node:path"
import strftime from 'strftime'
import { spawnSync } from "node:child_process"
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('/etc/snapback/log.txt');
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: 'pipe' })
console.log(result.stdout,result.stderr)
if (result.error) throw result.error
if (result.status !== 0) process.exit(result.status)
return result
@@ -56,6 +70,7 @@ program.command('install').description('installs snapback on your system')
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)
@@ -72,6 +87,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]
@@ -81,6 +97,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)