Skip to content

Commit 6a79075

Browse files
committed
zsd: special output for mrBliss/snapshot-timemachine
To support mrBliss/snapshot-timemachine[1] the new flag '-snapshot-timemachine' was included. When given, the output would be: - without headings - fields separated with a single tab - filepath in the snapshot included - absolute date (format: MMM D HH:MI) [1] https://github.com/mrBliss/snapshot-timemachine closes #12
1 parent 9afa5e3 commit 6a79075

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

cmd/zsd/main.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import (
2121
var version string = "SNAPSHOT"
2222

2323
type CliConfig struct {
24-
logLevel plog.LogLevel
25-
printVersion bool
26-
scriptingOutput bool
24+
logLevel plog.LogLevel
25+
printVersion bool
26+
scriptingOutput bool
27+
snapshotTimemachineOutput bool
2728
}
2829

2930
func main() {
@@ -77,7 +78,7 @@ func main() {
7778
action := flag.Arg(1)
7879
switch action {
7980
case "list":
80-
if !cliCfg.scriptingOutput {
81+
if !(cliCfg.scriptingOutput || cliCfg.snapshotTimemachineOutput) {
8182
fmt.Printf("scan the last %d days for other file versions\n", config.Get.DaysToScan)
8283
}
8384

@@ -91,7 +92,12 @@ func main() {
9192

9293
cacheFileVersions(scanResult.FileVersions)
9394

94-
if !cliCfg.scriptingOutput {
95+
if cliCfg.snapshotTimemachineOutput {
96+
for idx, v := range scanResult.FileVersions {
97+
fmt.Printf("%d\t%s\t%s\t%s\n",
98+
idx, v.Snapshot.Name, v.Backup.Path, v.Snapshot.Created.Format("Jan 2 15:04"))
99+
}
100+
} else if !cliCfg.scriptingOutput {
95101

96102
// find the longest snapshot name to format the output table
97103
width := 0
@@ -262,6 +268,8 @@ func parseFlags() CliConfig {
262268
flag.IntVar(&config.Get.DaysToScan, "d", config.Get.DaysToScan, "days to scan")
263269
flag.BoolVar(&cliCfg.scriptingOutput, "H", false,
264270
"Scripting mode. Do not print headers, print absolute dates and separate fields by a single tab")
271+
flag.BoolVar(&cliCfg.snapshotTimemachineOutput, "snapshot-timemachine", false,
272+
"Special output for Snapshot-timemachine (https://github.com/mrBliss/snapshot-timemachine)")
265273

266274
// logging
267275
cliCfg.logLevel = plog.Note
@@ -272,7 +280,7 @@ func parseFlags() CliConfig {
272280
zfsCfg := &config.Get.ZFS
273281
flag.BoolVar(&zfsCfg.UseSudo, "use-sudo", zfsCfg.UseSudo, "use sudo when executing 'zfs' commands")
274282
flag.BoolVar(&zfsCfg.MountSnapshots, "mount-snapshots", zfsCfg.MountSnapshots,
275-
"mount snapshot (only necessary if it's not mounted by zfs automatically")
283+
"mount snapshot (only necessary if it's not mounted by zfs automatically)")
276284

277285
flag.Parse()
278286
return *cliCfg

site.org

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ OPTIONS:
362362
days to scan (default 2)
363363
-mount-snapshots
364364
mount snapshot (only necessary if it's not mounted by zfs automatically)
365+
-snapshot-timemachine
366+
Special output for Snapshot-timemachine (https://github.com/mrBliss/snapshot-timemachine)
365367
-use-sudo
366368
use sudo when executing 'zfs' commands
367369
-v debug output

0 commit comments

Comments
 (0)