Browse Source

refactored the regular expressions to their own files.

master
Robert R. Russell 1 year ago
parent
commit
0ca50139d1
  1. 11
      main.go
  2. 15
      zfsbackup/regex.go
  3. 23
      zfsbackup/snapshot.go

11
main.go

@ -5,13 +5,10 @@ import (
"fmt"
"os"
"regexp"
"zfsbackup/zfsbackup"
)
const zfsRegexStart string = "zfs-auto-snap"
const zfsRegexIncrement string = "(?P<increment>yearly|monthly|weekly|daily|hourly|frequent)"
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)
var zfsRegex = regexp.MustCompile(zfsbackup.ZfsSnapshotNameRegex)
func testSnapshot(possible string, increment string) (bool, bool) {
var matches = zfsRegex.FindStringSubmatch(possible)
@ -55,9 +52,7 @@ func isAFrequentSnapshot(possible string) bool {
return isFrequent
}
const poolNameRegex string = "(?:[[:word:]-.]+)+(?:/?[[:word:]-.]+)*"
var snapshotLineRegex = regexp.MustCompile("^" + poolNameRegex + "@" + zfsRegex.String() + ".*$")
var snapshotLineRegex = regexp.MustCompile("^" + zfsbackup.PoolNameRegex + "@" + zfsbackup.ZfsSnapshotNameRegex + ".*$")
func main() {
//fmt.Println(snapshotLineRegex.MatchString("dpool/www@zfs-auto-snap_frequent-2020-08-04-1830\t0B\t-\t201M\t-"))

15
zfsbackup/regex.go

@ -0,0 +1,15 @@
package zfsbackup
/*
PoolNameRegex will match a zfs pool and filesystem tree
*/
const PoolNameRegex string = "(?:[[:word:]-.]+)+(?:/?[[:word:]-.]+)*"
const zfsRegexStart string = "zfs-auto-snap"
const zfsRegexIncrement string = "(?P<increment>yearly|monthly|weekly|daily|hourly|frequent)"
const zfsRegexDateStamp string = "(?P<year>[[:digit:]]{4})-(?P<month>[[:digit:]]{2})-(?P<day>[[:digit:]]{2})-(?P<hour>[[:digit:]]{2})(?P<minute>[[:digit:]]{2})"
/*
ZfsSnapshotNameRegex will match the name of a snapshot created by zfs-auto-snapshot
*/
const ZfsSnapshotNameRegex string = zfsRegexStart + "_" + zfsRegexIncrement + "-" + zfsRegexDateStamp

23
zfsbackup/snapshot.go

@ -0,0 +1,23 @@
package zfsbackup
/*
Snapshot represents a snapshot on a zfs pool and filesystem.
*/
type Snapshot struct {
pool string
fsTree string
Year uint
Month uint
Day uint
Hour uint
Minute uint
}
/*
ParseSnapshot parses a string into a Snapshot.
It returns nil on error.
*/
func ParseSnapshot(input string) *Snapshot {
return nil
}
Loading…
Cancel
Save