Created
September 5, 2009 09:00
-
-
Save jasonrm/181352 to your computer and use it in GitHub Desktop.
Take and manage ZFS snapshots on Mac OS X 10.5/10.6
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/bin/php | |
<?php | |
print("zfsSnapshot.php : Starting ZFS snapshots\n"); | |
$howFarBackInTime_Hours = 8; | |
$howFrequentIsScriptCalled_Minutes = 10; | |
$keepThisMany = $howFarBackInTime_Hours * 60 / $howFrequentIsScriptCalled_Minutes; | |
print("zfsSnapshot.php : Keeping $keepThisMany snapshots\n"); | |
exec('zfs list -o name -t filesystem | sed 1d', $filesystemList); | |
foreach ($filesystemList as $filesystem){ | |
print "Taking snapshot on [$filesystem]\n"; | |
exec('zfs snapshot "' . $filesystem . '@' . date(DATE_ATOM) . '"'); | |
$zfsList='zfs list -t snapshot | grep -Eo "' . $filesystem . '@[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9](.[0-9][0-9]:[0-9][0-9])?"'; | |
exec($zfsList, $snapshotList); | |
$numberToDelete=count($snapshotList) - $keepThisMany; | |
foreach ($snapshotList as $snapshot){ | |
if ($numberToDelete > 0){ | |
print "Deleting old snapshot [" . $snapshot . "]\n"; | |
print exec('zfs destroy "' . $snapshot . '"'); | |
$numberToDelete -= 1; | |
} | |
else break; | |
} | |
unset($snapshotList); | |
} | |
print("zfsSnapshot.php : Finished ZFS snapshots\n\n"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment