Browse Source

I can recognize automatic snapshots now.

master
Robert R. Russell 1 year ago
parent
commit
ccf2be3506
  1. 1
      .gitignore
  2. 32
      main.go

1
.gitignore

@ -0,0 +1 @@
zfsbackup

32
main.go

@ -9,7 +9,7 @@ import (
const zfsRegexStart string = "zfs-auto-snap"
const zfsRegexIncrement string = "(?P<increment>yearly|monthly|weekly|daily|hourly|frequent)"
const zfsRegexDateStamp string = "(?P<month>[[:digit:]]{2})-(?P<day>[[:digit:]]{2})-(?P<hour>[[:digit:]]{2})(?P<minute>[[:digit:]]{2})"
const zfsRegexDateStamp string = "(?P<year>[[:digit:]]{4})-(?P<month>[[:digit:]]{2})-(?P<day>[[:digit:]]{2})-(?P<hour>[[:digit:]]{2})(?P<minute>[[:digit:]]{2})"
var zfsRegex = regexp.MustCompile(zfsRegexStart + "_" + zfsRegexIncrement + "-" + zfsRegexDateStamp)
@ -21,9 +21,8 @@ func testSnapshot(possible string, increment string) (bool, bool) {
var isASnapshot = true
if matches[1] == increment {
return isASnapshot, true
} else {
return isASnapshot, false
}
return isASnapshot, false
}
func isAYearlySnapshot(possible string) bool {
@ -56,26 +55,19 @@ func isAFrequentSnapshot(possible string) bool {
return isFrequent
}
const poolNameRegex string = "(?:[[:word:]-.]+)+(?:/?[[:word:]-.]+)*"
var snapshotLineRegex = regexp.MustCompile("^" + poolNameRegex + "@" + zfsRegex.String() + ".*$")
func main() {
//fmt.Println(snapshotLineRegex.MatchString("dpool/www@zfs-auto-snap_frequent-2020-08-04-1830\t0B\t-\t201M\t-"))
input := bufio.NewScanner(os.Stdin)
for input.Scan() {
if isAYearlySnapshot(input.Text()) {
fmt.Printf("%s\t%s\n", input.Text(), "Is a yearly snapshot.")
}
if isAMonthlySnapshot(input.Text()) {
fmt.Printf("%s\t%s\n", input.Text(), "Is a monthly snapshot.")
}
if isAWeeklySnapshot(input.Text()) {
fmt.Printf("%s\t%s\n", input.Text(), "Is a weekly snapshot.")
}
if isADailySnapshot(input.Text()) {
fmt.Printf("%s\t%s\n", input.Text(), "Is a daily snapshot.")
}
if isAnHourlySnapshot(input.Text()) {
fmt.Printf("%s\t%s\n", input.Text(), "Is an hourly snapshot.")
}
if isAFrequentSnapshot(input.Text()) {
fmt.Printf("%s\t%s\n", input.Text(), "Is a frequent snapshot.")
if snapshotLineRegex.MatchString(input.Text()) {
fmt.Println(snapshotLineRegex.FindStringSubmatch(input.Text()))
fmt.Println(snapshotLineRegex.SubexpNames())
} else {
fmt.Printf("%s\t%s\n", input.Text(), "Is not a snapshot.")
}
}
if err := input.Err(); err != nil {

Loading…
Cancel
Save