def createSnapshot(place, stamp, bwlimit = None, timelimit = None): initCache() # Force ZFS cache - probably has already been initialized, but be safe zfs.initCache() if not exists(place.name, stamp) or not snapshots[place.name][stamp].hasZFS() == Snapshot.Status.complete: sys.exit("ERROR: Trying to create tarsnap snapshot but no ZFS snap ({},{})".format(place,stamp,)) extraArgs = [ ] if bwlimit: extraArgs.extend(["--maxbw",str(bwlimit)]) snap = snapshots[place.name][stamp] path = zfs.pathForSnapshot(snap) now = arrow.now().timestamp intermediateName = "snappy-%s-%s-intermediate-%s" % (place.name, stamp, now) print("snapTS: %s" % intermediateName) result = runTarsnap(extraArgs + ["-c","-f",intermediateName,path], timeout = timelimit) addToCache(intermediateName) tssnapname = "snappy-%s-%s" % (place.name, stamp) print("snapTS: %s" % tssnapname) runTarsnap(["-c","-f",tssnapname,path], timeout = timelimit) addToCache(tssnapname) for partial in [intermediateName] + snap._tarsnap_partials + snap._tarsnap_intermediates: print("Cleaning up %s" % partial) runTarsnap(["-d","-f",partial]) removeFromCache(partial)
def createSnapshot(place, stamp, bwlimit=None, timelimit=None): initCache() # Force ZFS cache - probably has already been initialized, but be safe zfs.initCache() if not exists(place.name, stamp) or not snapshots[ place.name][stamp].hasZFS() == Snapshot.Status.complete: sys.exit( "ERROR: Trying to create tarsnap snapshot but no ZFS snap ({},{})". format( place, stamp, )) extraArgs = [] if bwlimit: extraArgs.extend(["--maxbw", str(bwlimit)]) snap = snapshots[place.name][stamp] path = zfs.pathForSnapshot(snap) now = arrow.now().timestamp intermediateName = "snappy-%s-%s-intermediate-%s" % (place.name, stamp, now) print("snapTS: %s" % intermediateName) result = runTarsnap(extraArgs + ["-c", "-f", intermediateName, path], timeout=timelimit) addToCache(intermediateName) tssnapname = "snappy-%s-%s" % (place.name, stamp) print("snapTS: %s" % tssnapname) runTarsnap(["-c", "-f", tssnapname, path], timeout=timelimit) addToCache(tssnapname) for partial in [intermediateName ] + snap._tarsnap_partials + snap._tarsnap_intermediates: print("Cleaning up %s" % partial) runTarsnap(["-d", "-f", partial]) removeFromCache(partial)
def loadSnapshots(): zfs.initCache() tarsnap.initCache()