Skip to content

Commit

Permalink
zsd: special output for mrBliss/snapshot-timemachine
Browse files Browse the repository at this point in the history
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
  • Loading branch information
j-keck committed Jun 17, 2020
1 parent 9afa5e3 commit 6a79075
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 14 additions & 6 deletions cmd/zsd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
var version string = "SNAPSHOT"

type CliConfig struct {
logLevel plog.LogLevel
printVersion bool
scriptingOutput bool
logLevel plog.LogLevel
printVersion bool
scriptingOutput bool
snapshotTimemachineOutput bool
}

func main() {
Expand Down Expand Up @@ -77,7 +78,7 @@ func main() {
action := flag.Arg(1)
switch action {
case "list":
if !cliCfg.scriptingOutput {
if !(cliCfg.scriptingOutput || cliCfg.snapshotTimemachineOutput) {
fmt.Printf("scan the last %d days for other file versions\n", config.Get.DaysToScan)
}

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

cacheFileVersions(scanResult.FileVersions)

if !cliCfg.scriptingOutput {
if cliCfg.snapshotTimemachineOutput {
for idx, v := range scanResult.FileVersions {
fmt.Printf("%d\t%s\t%s\t%s\n",
idx, v.Snapshot.Name, v.Backup.Path, v.Snapshot.Created.Format("Jan 2 15:04"))
}
} else if !cliCfg.scriptingOutput {

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

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

flag.Parse()
return *cliCfg
Expand Down
2 changes: 2 additions & 0 deletions site.org
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ OPTIONS:
days to scan (default 2)
-mount-snapshots
mount snapshot (only necessary if it's not mounted by zfs automatically)
-snapshot-timemachine
Special output for Snapshot-timemachine (https://github.com/mrBliss/snapshot-timemachine)
-use-sudo
use sudo when executing 'zfs' commands
-v debug output
Expand Down

0 comments on commit 6a79075

Please sign in to comment.