Skip to content

Instantly share code, notes, and snippets.

@amscotti
Created April 27, 2013 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amscotti/5473914 to your computer and use it in GitHub Desktop.
Save amscotti/5473914 to your computer and use it in GitHub Desktop.
#!/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))
#!/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