The dot in ... --- ...

Chris Gerhard's Weblog

« BBT ride | Main | Cleaning up zfs... »

20060904 Monday September 04, 2006

Samba meets ZFS

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.


Tags


( Sep 04 2006, 11:08:38 PM BST ) Permalink Trackback

   
Comments:

how about this? if you set your date format to be "+%Y%m%d" without the hyphens in between, then it's really easy: #!/bin/pfksh -p # number of days worth of zfs snapshots to keep keepdays=7 snapshots=`zfs ist -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 done if the lines get mangled, i can email it to you. i use this to cleanup my backups to only keep one week's worth of ZFS snapshots.

Posted by stevel on September 05, 2006 at 05:11 AM BST #

hrm. lemme try with a pre tag around it
#!/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
done

Posted by 192.18.43.249 on September 05, 2006 at 05:12 AM BST #

Post a Comment:

Comments are closed for this entry.

Valid HTML! Valid CSS!

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.