Created
April 27, 2013 17:39
-
-
Save amscotti/5473914 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/local/bin/python | |
#Used to make snapshot of all the file systems on a zpool. | |
import commands | |
import subprocess | |
import time | |
import os | |
timestamp = time.strftime("%Y%m%d-%H%M") | |
zpoolName = "storage" | |
zfsList = commands.getoutput("zfs list -o name | grep %s/" % zpoolName) | |
for zfsFileSystems in zfsList.split("\n"): | |
print "Snapshoting-> %s" % (zfsFileSystems) | |
commands.getoutput("zfs snapshot %s@%s" % (zfsFileSystems, timestamp)) |
This file contains 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
#!/usr/local/bin/python | |
#Used to remove old snapshots of all the file systems on a zpool. | |
import commands | |
import subprocess | |
import time | |
import datetime | |
now = datetime.datetime.now() | |
zpoolName = "storage" | |
zfsList = commands.getoutput("zfs list -H -t snapshot | awk '{print $1}' | grep %s/" % zpoolName) | |
for zfsSnapshot in zfsList.split("\n"): | |
dateSnapshot = datetime.datetime.strptime(zfsSnapshot.split("@")[1], "%Y%m%d-%H%M") | |
if (now - dateSnapshot) >= datetime.timedelta(days = 30): | |
print "Removing-> %s" % (zfsSnapshot) | |
commands.getoutput("zfs destroy %s" % (zfsSnapshot)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment