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

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 04, 2006 at 10:11 PM 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 guest on September 04, 2006 at 10:12 PM BST #

Post a Comment:
Comments are closed for this entry.
About

This is the old blog of Chris Gerhard. It has mostly moved to http://chrisgerhard.wordpress.com

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today