Hi
Clive King has a nice blog entry showing this in action
http://blogs.sun.com/clive/entry/replication_using_zfs

with associated script at:
http://blogs.sun.com/clive/resource/zfs_repl.ksh

Which I think answers most of your questions.

Enda
Ross wrote:
> Hey folks,
> 
> Is anybody able to help a Solaris scripting newbie with this? I want to put 
> together an automatic script to take snapshots on one system and send them 
> across to another. I've shown the manual process works, but only have a very 
> basic idea about how I'm going to automate this.
> 
> My current thinking is that I want to put together a cron job that will work 
> along these lines:
> 
> - Run every 15 mins
> - take a new snapshot of the pool
> - send the snapshot to the remote system with zfs send / receive and ssh.
> (am I right in thinking I can get ssh to work with no password if I create a 
> public/private key pair? http://www.go2linux.org/ssh-login-using-no-password)
> - send an e-mail alert if zfs send / receive fails for any reason (with the 
> text of the failure message)
> - send an e-mail alert if zfs send / receive takes longer than 15 minutes and 
> clashes with the next attempt
> - delete the oldest snapshot on both systems if the send / receive worked
> 
> Can anybody think of any potential problems I may have missed? 
> 
> Bearing in mind I've next to no experience in bash scripting, how does the 
> following look?
> 
> **********************************************************************
> #!/bin/bash
> 
> # Prepare variables for e-mail alerts
> SUBJECT="zfs send / receive error"
> EMAIL="[EMAIL PROTECTED]"
> 
> NEWSNAP="build filesystem + snapshot name here"
> RESULTS=$(/usr/sbin/zfs snapshot $NEWSNAP)
> # how do I check for a snapshot failure here?  Just look for non blank 
> $RESULTS?
> if $RESULTS; then
>    # send e-mail
>    /bin/mail -s $SUBJECT $EMAIL $RESULTS
>    exit
> fi
> 
> PREVIOUSSNAP="build filesystem + snapshot name here"
> RESULTS=$(/usr/sbin/zfs send -i $NEWSNAP $PREVIOUSSNAP | ssh -l *user* 
> *remote-system* /usr/sbin/zfs receive *filesystem*)
> # again, how do I check for error messages here?  Do I just look for a blank 
> $RESULTS to indicate success?
> if $RESULTS ok; then
>    OBSOLETESNAP="build filesystem + name here"
>    zfs destroy $OBSOLETESNAP
>    ssh -l *user* *remote-system* /usr/sbin/zfs destroy $OBSOLETESNAP
> else 
>    # send e-mail with error message
>    /bin/mail -s $SUBJECT $EMAIL $RESULTS
> fi
> **********************************************************************
> 
> One concern I have is what happens if the send / receive takes longer than 15 
> minutes. Do I need to check that manually, or will the script cope with this 
> already? Can anybody confirm that it will behave as I am hoping in that the 
> script will take the next snapshot, but the send / receive will fail and 
> generate an e-mail alert?
> 
> thanks,
> 
> Ross
> --
> This message posted from opensolaris.org
> _______________________________________________
> zfs-discuss mailing list
> zfs-discuss@opensolaris.org
> http://mail.opensolaris.org/mailman/listinfo/zfs-discuss

_______________________________________________
zfs-discuss mailing list
zfs-discuss@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/zfs-discuss

Reply via email to