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="admin at example.com" 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
Hi Mertol, Yes, I''m using zfs send -i to just send the changes rather than the whole thing. I''ll have a think about your suggestion for deleting snapshots too, that does sound like a good idea. Unfortunately I won''t be able to synchronise any applications with this script. It''s backing up a filestore used by VMware ESX, so could be holding any number of machines. The aim of this is purely to give me a crash consistent backup of those virtual machines just in case. We have other software in place for our regular backups, this is our belt & braces disaster recovery copy :). Ross> Date: Fri, 26 Sep 2008 12:53:06 +0300> From: Mertol.Ozyoney at Sun.COM> Subject: RE: [zfs-discuss] Scripting zfs send / receive> To: myxiplx at hotmail.com> > Hi Ross ;> > I am no expert in scripting but I was a software engineer once :)> It''s good to desing the script to be able to tolerate errors. > > Instead of sending the snapshot I''d recommending sending difference of snap> shots. > Also instead of deleting the oldest snapshot I recommend deleting all but> newest X number of snapshots. (incase for some reason script is unable to> delete a snap shot, it will clean them in the next run, as it will always> leave a fix number of snap shots alive) > > Also you may want your script talk to application running on the Fs before> and after snapshot to make the snapshot consistent. > > My 2 cents...> > Best regards> Mertol> > > > Mertol Ozyoney > Storage Practice - Sales Manager> > Sun Microsystems, TR> Istanbul TR> Phone +902123352200> Mobile +905339310752> Fax +902123352222> Email mertol.ozyoney at sun.com> > > > -----Original Message-----> From: zfs-discuss-bounces at opensolaris.org> [mailto:zfs-discuss-bounces at opensolaris.org] On Behalf Of Ross> Sent: Friday, September 26, 2008 12:43 PM> To: zfs-discuss at opensolaris.org> Subject: [zfs-discuss] Scripting zfs send / receive> > 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="admin at example.com"> > 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 at opensolaris.org> http://mail.opensolaris.org/mailman/listinfo/zfs-discuss>_________________________________________________________________ Get all your favourite content with the slick new MSN Toolbar - FREE http://clk.atdmt.com/UKM/go/111354027/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.opensolaris.org/pipermail/zfs-discuss/attachments/20080926/a286bb37/attachment.html>
Enda O''Connor ( Sun Micro Systems Ireland)
2008-Sep-26 10:13 UTC
[zfs-discuss] Scripting zfs send / receive
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="admin at example.com" > > 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 at opensolaris.org > http://mail.opensolaris.org/mailman/listinfo/zfs-discuss