<?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>Michael Schuerig &#187; Administration</title>
	<atom:link href="http://www.schuerig.de/michael/blog/index.php/category/administration/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.schuerig.de/michael/blog</link>
	<description>Sentenced to making sense</description>
	<lastBuildDate>Tue, 06 Sep 2011 07:21:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>RSnapshotting on your own schedule</title>
		<link>http://www.schuerig.de/michael/blog/index.php/2006/11/26/rsnapshotting-on-your-own-schedule/</link>
		<comments>http://www.schuerig.de/michael/blog/index.php/2006/11/26/rsnapshotting-on-your-own-schedule/#comments</comments>
		<pubDate>Sun, 26 Nov 2006 01:36:48 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://schuerig.de/michael/blog/?p=4</guid>
		<description><![CDATA[I&#8217;m using rsnapshot for making regular backups of my Linux box. Neither the computer, nor the external backup disk is running all the time, therefore it would not work to simply have cron run rsnapshot at fixed times. I want a little more flexibility than that. When the computer is off, there&#8217;s no point in [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using <a href="http://www.rsnapshot.org/">rsnapshot</a> for making regular backups of my Linux box. Neither the computer, nor the external backup disk is running all the time, therefore it would not work to simply have <tt>cron</tt> run <tt>rsnapshot</tt> at fixed times.</p>
<p>I want a little more flexibility than that. When the computer is off, there&#8217;s no point in making a snapshot. Fine, there&#8217;s no work left to handle that case. But in cases where the computer is running, but the backup disk is not, I want it to be recorded that something should have been done&#8211;if only the disk had been on. Then, next time the disk is running again, the recorded (queued) tasks are executed in order.</p>
<p>As there are multiple processes involved, for enqueueing tasks and for dequeueing them, and as the later can take some time, there&#8217;s a bit of mutual exclusing involved. Luckily, Debian GNU/Linux provides very useful helper programs in the <tt>lockfile-progs</tt> package.</p>
<p><strong>/usr/local/lib/snapshot/dequeue</strong><br />
<code></p>
<pre>
#! /bin/sh

QUEUEFILE=/var/lib/snapshot/queue
LOCKFILE=/var/lib/snapshot/LCK..queue

lockfile-create $LOCKFILE
if ! test -f $QUEUEFILE || ! grep -Fqs -- "$*" $QUEUEFILE ; then
  echo $* >> $QUEUEFILE
fi
lockfile-remove $LOCKFILE
</pre>
<p></code></p>
<p><strong>/usr/local/lib/snapshot/dequeue</strong><br />
<code></p>
<pre>
#! /bin/sh

SNAPDIR=/var/cache/rsnapshot
QUEUEFILE=/var/lib/snapshot/queue
LOCKFILE=/var/lib/snapshot/LCK..queue
PIDFILE=/var/run/snapshot.pid

test -f $PIDFILE &#038;&#038; exit 0
test -s $QUEUEFILE || exit 0

echo $$ > $PIDFILE

was_mounted=0
if egrep -qs "\\B$SNAPDIR\\b" /etc/mtab; then
  was_mounted=1
  mount -o remount,rw $SNAPDIR 2> /dev/null
else
  mount -o rw $SNAPDIR 2> /dev/null
fi

if [ $? != 0 ]; then
  rm -f $PIDFILE
  exit 0
fi

cleanup ()
{
  if [ $was_mounted == 1 ]; then
    mount -o remount,ro $SNAPDIR
  else
    umount $SNAPDIR
  fi
  rm -f $PIDFILE
}

trap "cleanup" EXIT TERM INT

while true; do
  lockfile-create $LOCKFILE
  if [ -f $QUEUEFILE ] ; then
    ARGS=`head -n1 $QUEUEFILE`
    sed -i '1d' $QUEUEFILE
  fi
  lockfile-remove $LOCKFILE

  if [ -n "$ARGS" ]; then
    nice rsnapshot $ARGS
  else
    break
  fi

done

exit 0
</pre>
<p></code></p>
<p>Things are tied together by several <tt>cron</tt> jobs that define when things should, if possible, happen. Of course, this is highly dependent on the individual <tt>rsnapshot</tt> configuration.</p>
<p><strong>/etc/cron.d/snapshot</strong><br />
<code></p>
<pre>
7   12,20       * * *   root    /usr/local/lib/snapshot/enqueue hourly
11  20          * * *   root    /usr/local/lib/snapshot/enqueue daily
13  20          * * 1   root    /usr/local/lib/snapshot/enqueue weekly
17  20          1 * *   root    /usr/local/lib/snapshot/enqueue monthly
*/5  *          * * *   root    /usr/local/lib/snapshot/dequeue
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.schuerig.de/michael/blog/index.php/2006/11/26/rsnapshotting-on-your-own-schedule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

