Skip to content

Samba meets ZFS

September 4, 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.


Tags topic:[Solaris] topic:[ZFS] topic:[Samba]

Advertisements

From → Solaris

2 Comments
  1. 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.

  2. Anonymous permalink

    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
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: