ZFS Replicator Script, New Edition

Many crates on a bicycle. A metaphor for ZFS snapshot replicationAbout a year ago, I blogged about a useful script that handles recursive replication of ZFS snapshots across pools. It helped me migrate my pool from a messy configuration into the clean two-mirrored-pairs configuration I have now.

Meanwhile, the fine guys at the ZFS developer team introduced recursive send/receive into the ZFS command, which makes most of what the script does a simple -F flag to the zfs(1M).

Unfortunately, this new version of the ZFS command has not (yet?) been ported back to Solaris 10, so my ZFS snapshot replication script is still useful for Solaris 10 users, such as Mike Hallock from the School of Chemical Sciences at the University of Illinois at Urbana-Champaign (UIUC). He wrote:

Your script came very close to exactly what I needed, so I took it upon myself to make changes, and thought in the spirit of it all, to share those changes with you.

The first change he in introduced was the ability to supply a pattern (via -p) that selects some of the potentially many snapshots that one wants to replicate. He's a user of Tim Foster's excellent automatic ZFS snapshot service like myself and wanted to base his migration solely on the daily snapshots, not any other ones.

Then, Mike wanted to migrate across two different hosts on a network, so he introduced the -r option that allows the user to specify a target host. This option simply pipes the replication data stream through ssh at the right places, making ZFS filesystem migration across any distance very easy.

The updated version including both of the new features is available as zfs-replicate_v0.7.tar.bz2. I didn't test this new version but the changes look very good to me. Still: Use at your own risk.

Thanks a lot, Mike! 

Comments:

Thanks for the great script. I am using the -r option to replicate snapshots to a remote host. There seems to be a problem where it will only send the first snapshot, but no others. If I remove the -r host option, replication works fine on the localhost. All snapshots are replicated as expected.

I've spent some time trying to understand why the -r option doesn't work. I added many echos to debug, but I can't figure it out.

I have verified that the ssh command works without a password running the commands the script uses, and that doesn't seem to be an issue. Also the first snapshot does get sent, so it looks like the connections are made and data is sent for the first attempt.

Any ideas?

Posted by curt w on August 19, 2008 at 02:09 PM CEST #

Hi Curt,

thank you for using the script.

I ran into the same issue when I was replicating snapshots on a single system. The reason it did not work was that somehow between the first full snapshot and one or more incremental snapshots thereafter the zfs receive command complained about the filesystem having been modified in-between.

The solution was to use the -F option to zfs receive (see the man page). You have to be on a recent version of Solaris 10 or OpenSolaris to use this feature. -F is available from the zfs-replicate script as well.

I suggest you check if your particular update of Solaris 10 supports the -F version to zfs receive, then retry the script using -F.

Cheers,
Constantin

Posted by Constantin Gonzalez on August 20, 2008 at 02:26 AM CEST #

Hi Curt,

I think I've run into something similar to what you describe. Everything works fine for me except for when I run the script from cron - it only looks at the first snapshot.

Try replacing the copy_snap_multiple function in the script with the following, and see if things work better for you.

copy_snap_multiple() {
typeset dest=$1
typeset snapshot=""
typeset destsnap=""
typeset desttest=""
typeset lastsnap=""

typeset snaps=0
set -A snapshots

while read snapshot; do
snapshots[$snaps]=$snapshot
snaps=$snaps+1
done

x=0
while [ $x -lt $snaps ]; do
snapshot=${snapshots[$x]}

copy_snap $snapshot $dest $lastsnap
lastsnap=$snapshot

x=$x+1
done
}

Let me know if this fixes it for you. It seems to be working so far for me.

Posted by Mike Hallock on August 27, 2008 at 12:15 PM CEST #

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

Tune in and find out useful stuff about Sun Solaris, CPU and System Technology, Web 2.0 - and have a little fun, too!

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
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
Bookmarks
TopEntries
Blogroll
OldTopEntries