Created
October 21, 2016 20:55
-
-
Save cathode/652067322218de9a4d52fc2ae58f916b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Start() | |
{ | |
while (true) | |
{ | |
var now = DateTime.Now; | |
var actions = this.Policies.Select(p => p.GetNextAction(now)).OrderBy(k => k.Creation); | |
var next = actions.FirstOrDefault(); | |
var toRun = actions.Where(e => e.Creation == next.Creation).ToArray(); | |
var sleepTime = (next.Creation - now); | |
Logger.Write("Sleeping {0} until next snapshot action.", sleepTime); | |
this.SleepUntil(next.Creation); | |
foreach (var act in actions) | |
{ | |
foreach (var ds in act.Datasets) | |
{ | |
Logger.Write("Performing snapshot on {0} (recursive: {1}), will expire {2}.", ds.Name, ds.Recursive, act.Expiration); | |
var args = string.Format("snapshot {0} -o zsm:expiration=\"{1}\" {2}@auto-{3:yyyy.MM.dd-HH.mm.ss}", ds.Recursive ? "-r" : "", act.Expiration, ds.Name, act.Creation); | |
try | |
{ | |
this.zfs(args); | |
} | |
catch (Exception ex) | |
{ | |
Logger.Write(ex); | |
} | |
} | |
} | |
} | |
} | |
private void SleepUntil(DateTime end) | |
{ | |
var remain = end - DateTime.Now; | |
while (remain.TotalMilliseconds > 0) | |
{ | |
Thread.Sleep(remain); | |
remain = end - DateTime.Now; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment