Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ae7880d6b |
+16
@@ -7,6 +7,19 @@ 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 } } = {}
|
||||
|
||||
@@ -56,6 +69,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 +86,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 +96,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)
|
||||
|
||||
Reference in New Issue
Block a user