forked from Ivasoft/objectivefs-docker-volume
This commit is contained in:
61
main.go
61
main.go
@@ -334,7 +334,7 @@ func (d *ofsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error)
|
||||
// Destroy old snapshots
|
||||
for i, name := range setMinus(existingSnapshots, expectedSnapshots) {
|
||||
expectedOutput := "Snapshot '" + name + "' destroyed."
|
||||
if output, err := applyEnv(exec.Command("/sbin/mount.objectivefs", "destroy", name, "-f"), v.Env).Output(); err != nil || string(output) != expectedOutput {
|
||||
if output, err := applyEnv(exec.Command("/sbin/mount.objectivefs", "destroy", name, "-f"), v.Env).Output(); err != nil || strings.TrimSpace(string(output)) != expectedOutput {
|
||||
log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Warn("Failed to destroy an expired snapshot.")
|
||||
} else {
|
||||
log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Debug("Snapshot destroyed.")
|
||||
@@ -561,59 +561,6 @@ func (p *ofsDriver) removeVolumeInfo(tx *bolt.Tx, volumeName string) error {
|
||||
return bucket.Delete([]byte(volumeName))
|
||||
}
|
||||
|
||||
/*
|
||||
func parseSnapshotRules(rulesS string) ([]snapshotRule, error) {
|
||||
var result []snapshotRule
|
||||
rules := strings.Split(rulesS, " ")
|
||||
|
||||
for _, i := range rules {
|
||||
var rule snapshotRule
|
||||
|
||||
countAndRest := strings.SplitN(i, "@", 2)
|
||||
if len(countAndRest) != 2 || len(countAndRest[1]) < 2 {
|
||||
return nil, fmt.Errorf("Failed to parse snapshot rule '" + i + "'")
|
||||
}
|
||||
|
||||
if count, err := strconv.ParseInt(countAndRest[0], 10, 32); err != nil {
|
||||
return nil, fmt.Errorf("Failed to parse snapshot rule '" + i + "'")
|
||||
} else {
|
||||
rule.count = int(count)
|
||||
}
|
||||
|
||||
period := countAndRest[1]
|
||||
var multiplier time.Duration
|
||||
switch period[len(period)-1] {
|
||||
// see https://objectivefs.com/howto/snapshots
|
||||
case 'm':
|
||||
multiplier = time.Minute
|
||||
case 'h':
|
||||
multiplier = time.Hour
|
||||
case 'd':
|
||||
multiplier = 24 * time.Hour
|
||||
case 'w':
|
||||
multiplier = 7 * 24 * time.Hour
|
||||
case 'n':
|
||||
multiplier = 4 * 7 * 24 * time.Hour // Simple month (4 weeks)
|
||||
case 'q':
|
||||
multiplier = 12 * 7 * 24 * time.Hour // Simple quarter (12 weeks)
|
||||
case 'y':
|
||||
multiplier = 48 * 7 * 24 * time.Hour // Simple year (48 weeks)
|
||||
default:
|
||||
return nil, fmt.Errorf("Failed to parse snapshot period '" + period + "'")
|
||||
}
|
||||
|
||||
if periodCount, err := strconv.ParseInt(period[:len(period)-1], 10, 32); err != nil {
|
||||
return nil, fmt.Errorf("Failed to parse snapshot rule '" + i + "'")
|
||||
} else {
|
||||
rule.period = multiplier * time.Duration(periodCount)
|
||||
}
|
||||
|
||||
result = append(result, rule)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}*/
|
||||
|
||||
func applyEnv(cmd *exec.Cmd, env []string) *exec.Cmd {
|
||||
cmd.Env = env
|
||||
return cmd
|
||||
@@ -624,7 +571,7 @@ func generateSnapshotsFromRulesForNow(rules string) (map[string]bool, error) {
|
||||
var result = make(map[string]bool)
|
||||
scanner := bufio.NewScanner(strings.NewReader(string(timesB)))
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
if strings.HasPrefix(line, "Number of automatic snapshots:") || strings.HasPrefix(line, "Automatic schedule:") {
|
||||
continue
|
||||
}
|
||||
@@ -645,7 +592,7 @@ func parseExistingSnapshots(data string, expectedPrefix string) (map[string]stri
|
||||
var result = make(map[string]string)
|
||||
scanner := bufio.NewScanner(strings.NewReader(data))
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
if strings.HasPrefix(line, "NAME") {
|
||||
// Skip column headers
|
||||
continue
|
||||
@@ -699,7 +646,7 @@ func isObjectiveFsMount(path string) (bool, error) {
|
||||
scanner := bufio.NewScanner(strings.NewReader(string(data)))
|
||||
// On success the first line contains column headers (in our case "Mounted on")
|
||||
// and the second line contains the nearest mount point on the root path
|
||||
return scanner.Scan() && scanner.Scan() && scanner.Text() == path, nil
|
||||
return scanner.Scan() && scanner.Scan() && strings.TrimSpace(scanner.Text()) == path, nil
|
||||
} else {
|
||||
return false, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user