Monday September 04, 2006 There has been much progress on the new server at home which I will write up later. Today I'll dig into what I have done to make samba and ZFS play well together. As I mentioned getting Samba running was easy. However there is a bit more that you can do to make ZFS even and Samba even better together.
Why not have zfs take a snapshot whenever you login to the PC? So in addition to the regular snapshots I also get one of the home directory of each user when they login.
Just add this line to the [homes] section in the smb.conf:
root preexec = ksh -c '/usr/sbin/zfs snapshot tank/users/%u@smb$(/tank/local/smbdate)'
Then you need the smbdate script to print a good date. You can't just use the date command directly as Samba expands the % entries before they are passed to date. Hence I wrap it in a script:
#!/bin/ksh -p exec date +%F-%R
This results in snapshots like this each time a user logins on the PC
# zfs list | grep smb tank/users/cjg@smb2006-09-04-22:53 0 - 21.1G - #
At some point a script to clean up the old snapshots will be needed.
Except where otherwise noted, this site is
licensed under a Creative Commons License 2.0
This is a personal weblog, I do not speak for my employer.
Posted by stevel on September 05, 2006 at 05:11 AM BST #
#!/bin/pfksh -p # number of days worth of zfs snapshot backups to keep keepdays=7 snapshots=`zfs list -Ht snapshot | awk '{print $1}'` today=`date "+%Y%m%d"` echo "today: $today"; echo "removing snapshot backups older than $keepdays days" for snap in $snapshots; do date=`echo $snap | nawk -F'@' '{print $2}' | nawk -F'[_-]' '{print $2}'` if [ $date -lt $(($today-$keepdays)) ]; then echo "deleting $snap" /usr/sbin/zfs destroy $snap fi donePosted by 192.18.43.249 on September 05, 2006 at 05:12 AM BST #