<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>My Galagzee! &#187; automatic</title>
	<atom:link href="http://my.galagzee.com/tag/automatic/feed/" rel="self" type="application/rss+xml" />
	<link>http://my.galagzee.com</link>
	<description>Tech in a Galagzee, Not So Far Away.</description>
	<lastBuildDate>Wed, 28 Jul 2010 17:09:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Mounting an NFS share after boot, and checking up on it periodically&#8230;</title>
		<link>http://my.galagzee.com/2010/07/23/mounting-nfs-share-after-boot-and-checking-up-on-it-periodically/</link>
		<comments>http://my.galagzee.com/2010/07/23/mounting-nfs-share-after-boot-and-checking-up-on-it-periodically/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 19:20:51 +0000</pubDate>
		<dc:creator>Ville Walveranta</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[UNIX]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[boot]]></category>
		<category><![CDATA[circular]]></category>
		<category><![CDATA[nfs]]></category>

		<guid isPermaLink="false">http://my.galagzee.com/?p=433</guid>
		<description><![CDATA[I needed to automatically mount an NFS share after reboot. But the availability of that share could not be guaranteed &#8211; the system on the LAN offering the share might be down for maintenance when the system mounting the share is being rebooted. In such case there would be a lengthy wait during the boot]]></description>
			<content:encoded><![CDATA[<p>I needed to automatically mount an NFS share after reboot. But the availability of that share could not be guaranteed &#8211; the system on the LAN offering the share might be down for maintenance when the system mounting the share is being rebooted. In such case there would be a lengthy wait during the boot sequence until the mount attempt would time out.</p>
<p>So I wrote a short script to handle the situation. <del datetime="2010-07-28T17:01:44+00:00">When initialized at boot time through init.d or rc.d, it&#8217;ll first attempt to mount the share, but then times out in two seconds (this is a LAN NFS share so if the system offering the share is up there should not be a longer delay than that) and so the boot sequence is not slowed down terribly.</del> (see update below) Once boot is complete, the script is run via cron every five minutes. Depending on the criticality of the share you may want to make that time shorter or longer. In this case it is a backup share which is not critical for the system&#8217;s functioning.</p>
<p>This technique would handle circular mounts, too, but obviously you would run into trouble if the mounts are required for successful system boot.</p>
<p>For this to work successfully add a marker file, such as &#8220;.myremoteservertransfers&#8221; in my example script below, in the share folder on the system exporting the share. I usually set the undeletable attribute on the file to make sure it doesn&#8217;t get accidentally deleted.</p>
<p><B>Update:</b> Even with this code the boot sequence appears to hang until portmap times out (which takes quite a while) if the NFS share is not available at boot time. I removed the rc.d mount attempt and just shortened the cron poll period to 1 minute. That way the share will be up very quickly once it becomes available, yet the overhead caused by the periodic ping is minimal (both servers are on local LAN).</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow"><ol><li>#!/bin/sh</li><li>&nbsp;</li><li>SHELL=/bin/sh</li><li>PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin</li><li>&nbsp;</li><li># remote system name</li><li>remotesystem=myremoteserver</li><li>&nbsp;</li><li># remote share name</li><li>remoteshare=/nfsexports/backupshare</li><li>&nbsp;</li><li># local mount point</li><li>mountpoint=/localbackups/TRANSFERS/$<span class="br0">&#123;</span>myremoteserver<span class="br0">&#125;</span></li><li>&nbsp;</li><li># file to indicate local mount status</li><li>testfile=$mountpoint/.myremoteservertransfers</li><li>&nbsp;</li><li># --- end variables ---</li><li>&nbsp;</li><li># ping result to the remote system <span class="br0">&#40;</span>2 sec timeout<span class="br0">&#41;</span>; not empty is OK</li><li>remoteping=`ping -c1 -o -q -t2 $<span class="br0">&#123;</span>remotesystem<span class="br0">&#125;</span> | grep &quot; 0.0%&quot;`</li><li>&nbsp;</li><li>if <span class="br0">&#91;</span> &quot;$<span class="br0">&#123;</span>remoteping<span class="br0">&#125;</span>&quot; != &quot;&quot; <span class="br0">&#93;</span> ; then</li><li>&nbsp;</li><li>&nbsp;&nbsp; # server is available so query availability of the remote share; not empty is OK</li><li>&nbsp;&nbsp; offsiteshare=`showmount -e $<span class="br0">&#123;</span>remotesystem<span class="br0">&#125;</span> | grep &quot;$<span class="br0">&#123;</span>remoteshare<span class="br0">&#125;</span>&quot;`</li><li>&nbsp;</li><li>&nbsp;&nbsp; if <span class="br0">&#91;</span> &quot;$<span class="br0">&#123;</span>offsiteshare<span class="br0">&#125;</span>&quot; != &quot;&quot; <span class="br0">&#93;</span> ; then</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if <span class="br0">&#91;</span> ! -e $<span class="br0">&#123;</span>testfile<span class="br0">&#125;</span> <span class="br0">&#93;</span> ; then</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mount -r -t nfs $<span class="br0">&#123;</span>remotesystem<span class="br0">&#125;</span>:$<span class="br0">&#123;</span>remoteshare<span class="br0">&#125;</span> $<span class="br0">&#123;</span>mountpoint<span class="br0">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi</li><li>&nbsp;&nbsp; fi</li><li>fi</li><li>&nbsp;</li><li>exit <span style="">0</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
]]></content:encoded>
			<wfw:commentRss>http://my.galagzee.com/2010/07/23/mounting-nfs-share-after-boot-and-checking-up-on-it-periodically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FreeBSD Full / Incremental Filesystem Dump Shell Script</title>
		<link>http://my.galagzee.com/2009/07/17/freebsd-dump-filesystem-shell-script/</link>
		<comments>http://my.galagzee.com/2009/07/17/freebsd-dump-filesystem-shell-script/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 05:19:25 +0000</pubDate>
		<dc:creator>Ville Walveranta</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[UNIX]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[incremental]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://my.galagzee.com/?p=232</guid>
		<description><![CDATA[A FreeBSD shell script to dump filesystems with full, and automatically incremented incremental backups to a given directory location.]]></description>
			<content:encoded><![CDATA[<p>I wanted to automate filesystem dumps on my servers running FreeBSD 7.2.  After some searching I came across Vivek Gite&#8217;s <a href="http://bash.cyberciti.biz/backup/freebsd-dump-filesystem-shell-script/" target="_blank">FreeBSD Full / Incremental <strong>Tape</strong> Backup Shell Script</a> which gave me a lot of ideas.  Since I&#8217;m not using tape as the backup target I wanted to make a script specifically for that purpose while at the same time improve handling of some error conditions (such as, most importantly, checking for a missing level 0 dump before proceeding with an incremental dump) and add some new features such as autoincrement the dump level so that the dump level is not tied to specific day of the week.</p>
<p>Here&#8217;s my version of the script.  While it bears some resemblance to Vivek&#8217;s script, it is largely rewritten.  Read the script header for more information.</p>
<p><strong>NOTE!</strong> In his <a href="http://my.galagzee.com/2009/07/17/freebsd-dump-filesystem-shell-script/#comment-9988">comment</a> <em>James</em> pointed out a possible bug in the script.  The displayed script indeed had a problem: it was missing a backslash in front of the first dollar sign at:</p>
<p>eval &#8220;local fspath=<strong>\</strong>$${fsname}path&#8221;</p>
<p>This was caused by the script display plugin in WordPress that treated the backslash as an escape character (<a href="http://wordpress.org/support/topic/256742?replies=12#post-1168286" target="_blank">this has now been fixed</a>). To be on the safe side, please <strong><a href="http://my.galagzee.com/wp-content/uploads/2009/08/autodump-1.5a.tar">download the script as a tarball</a>.</strong> To further validate the integrity of the tarball, it should produce a md5 hash of 732ac44f11ba4484be4568e84929bb6a. </p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow"><ol><li></li><li>#!/bin/sh</li><li>&nbsp;</li><li># Autodump 1.5a <span class="br0">&#40;</span>released 01 August 2009<span class="br0">&#41;</span></li><li># Copyright <span class="br0">&#40;</span>c<span class="br0">&#41;</span> 2009 Ville Walveranta </li><li>#</li><li># A FreeBSD shell script to dump filesystems with full, and automatically </li><li># incremented incremental backups to a given directory location; this script</li><li># was written with the intent of saving the filesystem dumps not onto a tape</li><li># device but on another hard drive such as a different filesystem on the same </li><li># computer. The resulting dump files can be copied offsite with a separate </li><li># cron job.</li><li>#</li><li># This script creates the necessary directory structure below the defined </li><li># 'BASEDIR' as well as the necessary log file. This script also ensures that</li><li># the level 0 dump exists before creating an incremental dump; if it doesn't</li><li># the script automatically erases the incremental files for the current week </li><li># <span class="br0">&#40;</span>if any exist<span class="br0">&#41;</span> and starts over with a level 0 dump. This way you can start </li><li># using the script on any day of the week and level 0 dump is automatically </li><li># created on the first run.</li><li>#</li><li># When ran daily <span class="br0">&#40;</span>such as from a cron job<span class="br0">&#41;</span>, the script creates level 0 dump</li><li># on every Monday <span class="br0">&#40;</span>beginning the ISO week<span class="br0">&#41;</span>, or Sunday <span class="br0">&#40;</span>beginning of the U.S. </li><li># week<span class="br0">&#41;</span> and an incremental dump on all the other days of each week. The dumps </li><li># are compressed with gzip and saved below the 'BASEDIR' to an automatically </li><li># created directory whose name is derived from the list given in 'FSNAMES'. </li><li># Each week's dumps are organized into subfolders with name YYYY-WW <span class="br0">&#40;</span>'WW' </li><li># being the current week<span class="br0">&#41;</span>. By default three most recent weekly dumps </li><li># <span class="br0">&#40;</span>level 0 + incrementals<span class="br0">&#41;</span> are retained.</li><li>#</li><li># The script maintains each weekly folder's date at the _beginning_ date</li><li># of the dump <span class="br0">&#40;</span>i.e. Monday or Sunday of the current week<span class="br0">&#41;</span> at 00:00, not </li><li># at the most recent incremental's date/time.</li><li>#</li><li># By default the root <span class="br0">&#40;</span>/<span class="br0">&#41;</span> and usr <span class="br0">&#40;</span>/usr<span class="br0">&#41;</span> filesystems are dumped. To add more&nbsp;&nbsp;</li><li># add a &quot;friendly name&quot; to the 'FSNAMES' list <span class="br0">&#40;</span>it is used for the weekly folder</li><li># names, for dump filenames, and to reference the corresponding mount point</li><li># variable<span class="br0">&#41;</span>; then add the corresponding mount point variable <span class="br0">&#40;</span>i.e. if you </li><li># add &quot;var&quot; to 'FSNAMES', then add a variable varpath=/var<span class="br0">&#41;</span>. The &quot;path&quot; </li><li># ending of the mount point variable name is required. </li><li>#</li><li># Since the number of incremental dumps is limited to nine <span class="br0">&#40;</span>level 0 +</li><li># incremental levels 1-9<span class="br0">&#41;</span>, the script will allow maximum of one dump </li><li># to be created per day. However, since the level incrementing is dynamic</li><li># you can start the script on any day of the week, and run it on any</li><li># number of days during the rest of the week and you'll always get</li><li># level 0 plus the incremental dumps in sequential order. However, The </li><li># new weekly folder is always created on Monday or Sunday <span class="br0">&#40;</span>as chosen by</li><li># you<span class="br0">&#41;</span>. Note that the script determines whether &quot;today's&quot; dump exists </li><li># based on the modification date stamp of the most recent dump. Hence </li><li># it is a good idea to run this script in the early hours of each day </li><li># rather than in the very end of each day. Running the script, for </li><li># example, at 23:50 has the potential to push longer dump processes </li><li># over the midnight and so potentially cause the next day's dump to </li><li># be skipped.</li><li>#</li><li># Written for FreeBSD 7.2 but should work on most BSD and *NIX systems with</li><li># minor modifications.</li><li># -------------------------------------------------------------------------</li><li># Copyright <span class="br0">&#40;</span>c<span class="br0">&#41;</span> 2009 Ville Walveranta </li><li># &lt;http://my.galagzee.com/2009/07/17/freebsd-dump-filesystem-shell-script&gt;</li><li># This script is licensed under GNU GPL version 2.0 or above, and is provided</li><li># 'as-is' with no warranty which is to say that I'm not liable if it wipes out</li><li># your hard drive clean or doesn't back up your precious data. However, to the </li><li># best or my knowledge it is working as expected -- I'm using it myself. :-<span class="br0">&#41;</span></li><li># -------------------------------------------------------------------------</li><li># This script was inspired by </li><li># FreeBSD Full / Incremental Tape Backup Shell Script</li><li># by nixCraft project / Vivek Gite</li><li># at &lt;http://bash.cyberciti.biz/backup/freebsd-dump-filesystem-shell-script/&gt;</li><li># -------------------------------------------------------------------------</li><li>&nbsp;</li><li>&nbsp;</li><li>#### GLOBAL VARIABLES ###############################################</li><li>&nbsp;</li><li>WEEKSTARTS=Mon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Accepted values are &quot;Mon&quot; <span class="br0">&#40;</span>ISO standard<span class="br0">&#41;</span> or &quot;Sun&quot; <span class="br0">&#40;</span>U.S.<span class="br0">&#41;</span></li><li>KEEPDUMPS=30&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# in days; this is evaluated on the weekly level per start</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# of the week, so '30' keeps 3-4 weekly dumps</li><li>BASEDIR=/bak/dumps</li><li>GLOBALDUMPOPTS=Lua&nbsp;&nbsp;# add 'n' for wall notifications</li><li>LOGFILE=/var/log/dump.log</li><li>&nbsp;</li><li># to add more filesystems to be dumped add the dump name in 'FSNAMES'</li><li># and add the corresponding mount point variable <span class="br0">&#40;</span>dumpname+path=mountpoint<span class="br0">&#41;</span></li><li>FSNAMES=&quot;root usr&quot;&nbsp;&nbsp;# this is used for dump directory name </li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# and to ID the path from a variable below</li><li>rootpath=/</li><li>usrpath=/usr</li><li>&nbsp;</li><li>#####################################################################</li><li>&nbsp;</li><li>DUMP=/sbin/dump</li><li>GZIP=/usr/bin/gzip</li><li>LOGGER=/usr/bin/logger</li><li>&nbsp;</li><li>WEEKDAY=$<span class="br0">&#40;</span>date +&quot;%a&quot;<span class="br0">&#41;</span></li><li>DATE=$<span class="br0">&#40;</span>date +&quot;%Y%m%d&quot;<span class="br0">&#41;</span></li><li>HUMANDATE=$<span class="br0">&#40;</span>date +&quot;%d-%b-%Y&quot;<span class="br0">&#41;</span></li><li>HUMANDATE=`echo $HUMANDATE | tr '<span class="br0">&#91;</span>:lower:<span class="br0">&#93;</span>' '<span class="br0">&#91;</span>:upper:<span class="br0">&#93;</span>'`</li><li>HUMANTIME=$<span class="br0">&#40;</span>date +&quot;%H:%M <span class="br0">&#40;</span>%Z<span class="br0">&#41;</span>&quot;<span class="br0">&#41;</span></li><li>TODAYYR=$<span class="br0">&#40;</span>date +&quot;%Y&quot;<span class="br0">&#41;</span></li><li>TODAYMO=$<span class="br0">&#40;</span>date +&quot;%m&quot;<span class="br0">&#41;</span></li><li>TODAYDT=$<span class="br0">&#40;</span>date +&quot;%d&quot;<span class="br0">&#41;</span></li><li>&nbsp;</li><li># datestamp at midnight today</li><li>TODAYSTARTSTAMP=$<span class="br0">&#40;</span>date -j +%s &quot;$<span class="br0">&#123;</span>TODAYYR<span class="br0">&#125;</span>$<span class="br0">&#123;</span>TODAYMO<span class="br0">&#125;</span>$<span class="br0">&#123;</span>TODAYDT<span class="br0">&#125;</span>0000&quot;<span class="br0">&#41;</span></li><li>&nbsp;</li><li># default lastdump to midnight today; it will be checked</li><li># and and adjusted later</li><li>LASTDUMP=$TODAYSTARTSTAMP</li><li>&nbsp;</li><li># do not crete world-readable dumps!</li><li>umask 117</li><li>&nbsp;</li><li># make sure the logfile exists</li><li>if <span class="br0">&#91;</span> ! -e $LOGFILE <span class="br0">&#93;</span> ; then</li><li>&nbsp;&nbsp; touch $LOGFILE</li><li>&nbsp;&nbsp; chmod 660 $LOGFILE</li><li>fi</li><li>&nbsp;</li><li># make sure that entire week's incremental dumps are deposted</li><li># in the same directory, even when a week spans new year</li><li># NOTE: When the ending year has a partial 53rd week, there</li><li># won't be a dump folder for the first week of the new year.</li><li># The incremental dumps instead complete the 53rd week folder,</li><li># even when the 1st week of the new year begins mid-week. </li><li># However, the dates of the incremental dump files in the </li><li># 53rd week folder correctly reflect the dates of the </li><li># beginning year.</li><li>adjust_date<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></li><li>&nbsp;&nbsp; local dateoffset=$1</li><li>&nbsp;&nbsp; local epochnow=$<span class="br0">&#40;</span>date +%s<span class="br0">&#41;</span></li><li>&nbsp;&nbsp; local offsetsecs=`expr $dateoffset &quot;*&quot; 86400`</li><li>&nbsp;&nbsp; local newepoch=`expr $epochnow &quot;-&quot; $offsetsecs`</li><li>&nbsp;&nbsp; local year=`date -r $newepoch +&quot;%Y&quot;`</li><li>&nbsp;</li><li>&nbsp;&nbsp; if <span class="br0">&#91;</span> &quot;$WEEKSTARTS&quot; = &quot;Mon&quot; <span class="br0">&#93;</span> ; then</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local week=`date -r $newepoch +&quot;%W&quot;`</li><li>&nbsp;&nbsp; else</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local week=`date -r $newepoch +&quot;%U&quot;`</li><li>&nbsp;&nbsp; fi</li><li>&nbsp;&nbsp; NEWEPOCHISO=`date -r $newepoch +&quot;%Y%m%d0000&quot;`</li><li>&nbsp;</li><li>&nbsp;&nbsp; #system week starts from `0', there is no calendar week `0'</li><li>&nbsp;&nbsp; week=`expr $week &quot;+&quot; 1`</li><li>&nbsp;&nbsp; YWEEK=$<span class="br0">&#123;</span>year<span class="br0">&#125;</span>-$<span class="br0">&#123;</span>week<span class="br0">&#125;</span></li><li><span class="br0">&#125;</span></li><li>&nbsp;</li><li># determines the 'distance' from the level 0 dump in days</li><li>if <span class="br0">&#91;</span> &quot;$WEEKSTARTS&quot; = &quot;Mon&quot; <span class="br0">&#93;</span> ; then</li><li>&nbsp;&nbsp; case $WEEKDAY in</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mon<span class="br0">&#41;</span> adjust_date <span style="">0</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tue<span class="br0">&#41;</span> adjust_date <span style="">1</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wed<span class="br0">&#41;</span> adjust_date <span style="">2</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thu<span class="br0">&#41;</span> adjust_date <span style="">3</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fri<span class="br0">&#41;</span> adjust_date <span style="">4</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sat<span class="br0">&#41;</span> adjust_date <span style="">5</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sun<span class="br0">&#41;</span> adjust_date <span style="">6</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<span class="br0">&#41;</span> ;;</li><li>&nbsp;&nbsp; esac</li><li>else </li><li>&nbsp;&nbsp; case $WEEKDAY in</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sun<span class="br0">&#41;</span> adjust_date <span style="">0</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mon<span class="br0">&#41;</span> adjust_date <span style="">1</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tue<span class="br0">&#41;</span> adjust_date <span style="">2</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wed<span class="br0">&#41;</span> adjust_date <span style="">3</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thu<span class="br0">&#41;</span> adjust_date <span style="">4</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fri<span class="br0">&#41;</span> adjust_date <span style="">5</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sat<span class="br0">&#41;</span> adjust_date <span style="">6</span>;;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<span class="br0">&#41;</span> ;;</li><li>&nbsp;&nbsp; esac</li><li>fi</li><li>&nbsp;</li><li>mk_auto_dump<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp; local fsname=$1</li><li>&nbsp;</li><li>&nbsp;&nbsp; # get the current filesystem's path</li><li>&nbsp;&nbsp; # as defined in the corresponding variable</li><li>&nbsp;&nbsp; eval &quot;local fspath=\$$<span class="br0">&#123;</span>fsname<span class="br0">&#125;</span>path&quot;</li><li>&nbsp;</li><li>&nbsp;&nbsp; # composite the dump path</li><li>&nbsp;&nbsp; local dumppath=$<span class="br0">&#123;</span>BASEDIR<span class="br0">&#125;</span>/$<span class="br0">&#123;</span>fsname<span class="br0">&#125;</span>/$<span class="br0">&#123;</span>YWEEK<span class="br0">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp; # make sure the dump directory for this week exists;</li><li>&nbsp;&nbsp; # this automatically creates a new dump directory on </li><li>&nbsp;&nbsp; # every Monday or Sunday <span class="br0">&#40;</span>as selected by 'WEEKSTARTS'<span class="br0">&#41;</span></li><li>&nbsp;&nbsp; <span class="br0">&#91;</span> ! -d $dumppath <span class="br0">&#93;</span> &amp;&amp; mkdir -p $dumppath</li><li>&nbsp;</li><li>&nbsp;&nbsp; # get name of the last file in the current dump directory</li><li>&nbsp;&nbsp; local lastfile=`ls -ltr $dumppath | grep -v &quot;^d&quot; | tail -n 1 | awk '<span class="br0">&#123;</span> print $9 <span class="br0">&#125;</span>'`</li><li>&nbsp;</li><li>&nbsp;&nbsp; # assume that the 'lastfile', if it exists, was not created today</li><li>&nbsp;&nbsp; local dumped_today=false</li><li>&nbsp;</li><li>&nbsp;&nbsp; # if a file exists, check its modification date; </li><li>&nbsp;&nbsp; # if it is at or after 00:00 today, set a flag to skip the dump</li><li>&nbsp;&nbsp; if <span class="br0">&#91;</span> &quot;$lastfile&quot; != &quot;&quot; <span class="br0">&#93;</span> ; then</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local fq_lastfile=$<span class="br0">&#123;</span>dumppath<span class="br0">&#125;</span>/$lastfile</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if <span class="br0">&#91;</span> -e $fq_lastfile <span class="br0">&#93;</span> ; then</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # get the last modification time for the most recently created dumpfile</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LASTDUMP=`stat -f %m $fq_lastfile`</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if <span class="br0">&#91;</span> $LASTDUMP -ge $TODAYSTARTSTAMP <span class="br0">&#93;</span> ; then</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local dumped_today=true</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi</li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# get the first and the last dump level for this directory</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local levelcommand=&quot;ls $dumppath | sed -e 's/^<span class="br0">&#91;</span><span class="br0">&#91;</span>:digit:<span class="br0">&#93;</span><span class="br0">&#93;</span>*\_//' | sed -e 's/\..*$//'&quot;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local firstlevel=`eval $levelcommand | head -n 1`</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local lastlevel=`eval $levelcommand | tail -n 1`</li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# make sure level zero dump exists;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# if it doesn't, start over</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if <span class="br0">&#91;</span> &quot;$firstlevel&quot; != &quot;0&quot; <span class="br0">&#93;</span> ; then</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # it doesn't matter if a previous dump exists from today</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # since we're starting over as level 0 dump is missing</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local dumped_today=false</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local dumplevel=0</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rm -f $dumppath/*.gz</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # otherwise just increment the dump level</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # for levels 1-6, i.e. normally Tuesday thru Sunday</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local dumplevel=`expr $lastlevel &quot;+&quot; 1`</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi</li><li>&nbsp;&nbsp; else</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# no dump exists in this week's folder; reset level to '0'</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local dumplevel=0</li><li>&nbsp;&nbsp; fi</li><li>&nbsp;</li><li>&nbsp;&nbsp; # skip the entire dump process if a dumpfile has</li><li>&nbsp;&nbsp; # already been created for this filesystem today</li><li>&nbsp;&nbsp; if <span class="br0">&#91;</span> &quot;$dumped_today&quot; = &quot;false&quot; <span class="br0">&#93;</span> ; then&nbsp;&nbsp;</li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# define the dump filename</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local dumpfn=$<span class="br0">&#123;</span>DATE<span class="br0">&#125;</span>_$<span class="br0">&#123;</span>dumplevel<span class="br0">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo ---------------- &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo BEGINNING LEVEL $dumplevel DUMP OF \'$fsname\' \<span class="br0">&#40;</span>$<span class="br0">&#123;</span>fspath<span class="br0">&#125;</span>\<span class="br0">&#41;</span> FILESYSTEM ON $HUMANDATE AT $HUMANTIME &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo Creating a snapshot of \'$fspath\'.. &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# execute the dump</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$DUMP -$dumplevel -$GLOBALDUMPOPTS -f $<span class="br0">&#123;</span>dumppath<span class="br0">&#125;</span>/$<span class="br0">&#123;</span>dumpfn<span class="br0">&#125;</span> $fspath &gt;&gt; $LOGFILE 2&gt;&amp;1</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local dumpresult=$?</li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if <span class="br0">&#91;</span> &quot;$dumpresult&quot; != &quot;0&quot; <span class="br0">&#93;</span> ; then</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # log the dump result to syslog</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $LOGGER &quot;$DUMP LEVEL $dumplevel DUMP OF $fsname <span class="br0">&#40;</span>$<span class="br0">&#123;</span>fspath<span class="br0">&#125;</span><span class="br0">&#41;</span> FAILED!&quot;</li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;*** DUMP FAILED - LEVEL $dumplevel DUMP of $fsname <span class="br0">&#40;</span>$<span class="br0">&#123;</span>fspath<span class="br0">&#125;</span><span class="br0">&#41;</span> ***&quot; &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # log the dump result to syslog</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $LOGGER &quot;LEVEL $dumplevel DUMP of $fsname <span class="br0">&#40;</span>$<span class="br0">&#123;</span>fspath<span class="br0">&#125;</span><span class="br0">&#41;</span> COMPLETED SUCCESSFULLY!&quot;</li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # compress the dump</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo Compressing the dumpfile \'$<span class="br0">&#123;</span>dumpfn<span class="br0">&#125;</span>\'.. &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $GZIP -v $<span class="br0">&#123;</span>dumppath<span class="br0">&#125;</span>/$<span class="br0">&#123;</span>dumpfn<span class="br0">&#125;</span> &gt;&gt; $LOGFILE 2&gt;&amp;1</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo DONE &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &gt;&gt; $LOGFILE</li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # make sure dumps are not world readable <span class="br0">&#40;</span>security risk!<span class="br0">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo Updating dumpfile \'$<span class="br0">&#123;</span>dumpfn<span class="br0">&#125;</span>.gz\' permissions.. &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chmod -v -v 440 $<span class="br0">&#123;</span>dumppath<span class="br0">&#125;</span>/$<span class="br0">&#123;</span>dumpfn<span class="br0">&#125;</span>.gz &gt;&gt; $LOGFILE 2&gt;&amp;1</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo DONE &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &gt;&gt; $LOGFILE</li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # reset current dump dir's timestamp to that of the level 0 dump</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; touch -t $<span class="br0">&#123;</span>NEWEPOCHISO<span class="br0">&#125;</span> $<span class="br0">&#123;</span>dumppath<span class="br0">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # delete old dumps</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo Deleting old \'$fsname\' dumpfiles.. &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; find $BASEDIR/$fsname -mtime +$KEEPDUMPS -maxdepth 1 -print -exec rm -rf <span class="br0">&#123;</span><span class="br0">&#125;</span> \; &gt;&gt; $LOGFILE <span style="">2</span>&gt;&amp;<span style="">1</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo DONE &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &gt;&gt; $LOGFILE</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi</li><li>&nbsp;&nbsp; else</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local lastdump_readable=`date -j -r $LASTDUMP +&quot;%H:%M&quot;`</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local lastdump_readableZ=`date -j -r $LASTDUMP +&quot;%Z&quot;`</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local lastdumpmsg=&quot;Autodump for filesystem '$fsname' <span class="br0">&#40;</span>$fspath<span class="br0">&#41;</span> has already been executed today at $lastdump_readable <span class="br0">&#40;</span>$lastdump_readableZ<span class="br0">&#41;</span>.&quot;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo $lastdumpmsg</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$LOGGER $lastdumpmsg</li><li>&nbsp;&nbsp; fi</li><li><span class="br0">&#125;</span></li><li>&nbsp;</li><li>&nbsp;</li><li># Dump filesystems defined in 'FSNAMES'</li><li>#</li><li># Monday or Sunday <span class="br0">&#40;</span>as selected by 'WEEKSTARTS'<span class="br0">&#41;</span> starts with </li><li># the level <span style="">0</span> dump, with incrementals created through the rest of </li><li># the week <span class="br0">&#40;</span>autoincremented<span class="br0">&#41;</span>. If the level <span style="">0</span> dump is missing in </li><li># the current week's folder for filesystem currently being backed </li><li># up, it is created automatically instead of an incremental dump, </li><li># no matter what day of the week it is.</li><li>for f in $FSNAMES</li><li>do</li><li>&nbsp;&nbsp; mk_auto_dump $f</li><li>done</li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
]]></content:encoded>
			<wfw:commentRss>http://my.galagzee.com/2009/07/17/freebsd-dump-filesystem-shell-script/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
