{"id":109,"date":"2011-07-11T17:37:24","date_gmt":"2011-07-11T17:37:24","guid":{"rendered":"http:\/\/www.davidhedges.info\/?p=109"},"modified":"2018-06-03T17:37:52","modified_gmt":"2018-06-03T17:37:52","slug":"a-script-to-migrate-cluster-volumes-for-backups","status":"publish","type":"post","link":"https:\/\/www.davidhedges.info\/index.php\/2011\/07\/11\/a-script-to-migrate-cluster-volumes-for-backups\/","title":{"rendered":"A script to migrate cluster volumes for backups"},"content":{"rendered":"<p>I&#8217;ve been a lot of linux work lately. We had an issue in the linux cluster if the volumes migrate to other servers in the cluster than where the backup server is that they either skip the volume or perform a full back of the volume. I didn&#8217;t see much out there about what others had done to do this, so I threw this together.<\/p>\n<p>here is a script I put together to migrate a set group of volumes back to the server if they are not already mounted:<\/p>\n<p>&#8212;beginning of script&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>#!\/bin\/bash<\/p>\n<p>#Enter the volumes that are to be migrated to this server<\/p>\n<p># if you need more than 10 also add an echo command as listed below (echo $VXX &gt;&gt;$TMPDIR\/vars.$RAND1)<\/p>\n<p>V1=<\/p>\n<p>V2=<\/p>\n<p>V3=<\/p>\n<p>V4=<\/p>\n<p>V5=<\/p>\n<p>V6=<\/p>\n<p>V7=<\/p>\n<p>V8=<\/p>\n<p>V9=<\/p>\n<p>V10=<\/p>\n<p>#Get the date<\/p>\n<p>DATE=`time &#8216;+%b %d %T&#8217;`<\/p>\n<p>#set temp directory<\/p>\n<p>TMPDIR=\/tmp<\/p>\n<p>#set counting varialbe<\/p>\n<p>NVC=1<\/p>\n<p># Get the hostname<\/p>\n<p>HOST=`hostname`<\/p>\n<p># generate a random key<\/p>\n<p>RANDOM=`date &#8216;+%s&#8217;`<\/p>\n<p>RAND1=$[($RANDOM % 999) + 1]<\/p>\n<p>echo $V1 &gt;$TMPDIR\/vars.$RAND1<\/p>\n<p>echo $V2 &gt;&gt;$TMPDIR\/vars.$RAND1<\/p>\n<p>echo $V3 &gt;&gt;$TMPDIR\/vars.$RAND1<\/p>\n<p>echo $V4 &gt;&gt;$TMPDIR\/vars.$RAND1<\/p>\n<p>echo $V5 &gt;&gt;$TMPDIR\/vars.$RAND1<\/p>\n<p>echo $V6 &gt;&gt;$TMPDIR\/vars.$RAND1<\/p>\n<p>echo $V7 &gt;&gt;$TMPDIR\/vars.$RAND1<\/p>\n<p>echo $v8 &gt;&gt;$TMPDIR\/vars.$RAND1<\/p>\n<p>echo $v9 &gt;&gt;$TMPDIR\/vars.$RAND1<\/p>\n<p>echo $V10 &gt;&gt;$TMPDIR\/vars.$RAND1<\/p>\n<p>sed &#8216;\/^$\/d&#8217; $TMPDIR\/vars.$RAND1 &gt; $TMPDIR\/vars1.$RAND1<\/p>\n<p>#number of volume variables<\/p>\n<p>NV=`wc -l $TMPDIR\/vars1.$RAND1 |awk &#8216;{print $1}&#8217;`<\/p>\n<p>cluster status |grep $HOST | awk &#8216;{print $1}&#8217;<\/p>\n<p>while [ $NVC -le $NV ]<\/p>\n<p>do<\/p>\n<p>LINE=`head -$NVC $TMPDIR\/vars1.$RAND1 | tail -1`<\/p>\n<p>VTEST=`cluster status |grep $HOST | awk &#8216;{print $1}&#8217; |grep $LINE`<\/p>\n<p>if [ &#8220;$(echo $LINE)&#8221; == &#8220;$(echo $VTEST)&#8221; ]; then<\/p>\n<p>echo &#8220;$DATE already mounted on this server&#8230; skipping $LINE&#8221;<\/p>\n<p>else<\/p>\n<p>echo &#8220;$DATE not mounted on this server.. .need to migrate $LINE&#8221;<\/p>\n<p>cluster migrate $LINE $HOST<\/p>\n<p>sleep 30<\/p>\n<p>fi<\/p>\n<p>(( NVC++))<\/p>\n<p>done<\/p>\n<p>#clean up temp files<\/p>\n<p>rm $TMPDIR\/*.$RAND1<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8211;end of script&#8212;&#8212;&#8212;&#8212;-<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been a lot of linux work lately. We had an issue in the linux cluster if the volumes migrate to other servers in the cluster than where the backup server is that they either skip the volume or perform a full back of the volume. I didn&#8217;t see much out there about what others [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[3],"tags":[],"class_list":["post-109","post","type-post","status-publish","format-standard","category-it-blog","entry"],"_links":{"self":[{"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":1,"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":110,"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/posts\/109\/revisions\/110"}],"wp:attachment":[{"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}