SearchFAQMemberlist Log in
Reply to topic Page 1 of 1
Proof of concept script changing interva
Author Message
Post Proof of concept script changing interva 
I have written a script which I use with a removable REV drive. It
allows me to manage the daily/weekly interval in a more direct fashion.

Let me give an example. I was used to saving 35 days of daily backups,
each Friday was a weekly, and the third or fourth working day following
the month end was monthly. In an accounting environment where backing up
data just prior or just after a monthly update is a much more important
interval to capture than the forth weekly.

And only keeping the last seven dailies is too restrictive.

OK, my home system isn't that exotic. I cycle my removable REV drive on
a weekly basis. I wanted to have 6 dailies and a weekly, with the weekly
being the daily backup on the last day the drive was cycled, not the
daily from six days ago.

I wrote this script as a proof of concept. this way I'm using an
unmodified rsnapshot 1.20 my way. If you think this would be a good
option to add to rsnapshot, I would be glad to test it.

Thanks, BobH

---<snip>---
#!/bin/bash
# /etc/cron.often/rsnapshot.script

arg1=${1:-0} # default to zero (daily) if undefined
# 0 -Daily
# 1 -Weekly
rootdir=/mnt/rev

#-- Test for mounted media ---------------------------------+
if [ ! -d /mnt/rev/lost+found ]; then
mount /mnt/rev
rc=$?
sleep 2
if [ $rc -ne 0 ];then
echo "Drive /mnt/rev NOT mounted!"
exit
fi
fi

#-- Invoke rsnapshot on a daily basis ----------------------+
# Change logic so that Weekly.0 is generated by:
# mv daily.0 weekly.0
# ln -s weekly.0 daily.0
echo "<----------------------------------------------------------->"
echo "Rsnapshot.script starting... $(date "+%F %T") "
echo ""

nice /usr/bin/rsnapshot daily

if [ ${arg1} -eq 1 ]; then
#-- Roll weeklies ------------------------------------------+
if [ -d ${rootdir}/weekly.2 ]; then
echo "rm -fr ${rootdir}/weekly.2 "
echo "$(date "+[%d/%a/%Y:%H:%M:%S]") \
rm -fr ${rootdir}/weekly.2 " >> \
${rootdir}/rsnapshot.log
rm -fr ${rootdir}/weekly.2
fi

if [ -d ${rootdir}/weekly.1 ]; then
echo "mv ${rootdir}/weekly.1 ${rootdir}/weekly.2 "
echo "$(date "+[%d/%a/%Y:%H:%M:%S]") \
mv ${rootdir}/weekly.1 ${rootdir}/weekly.2 " >> \
${rootdir}/rsnapshot.log
mv ${rootdir}/weekly.1 ${rootdir}/weekly.2
fi

if [ -d ${rootdir}/weekly.0 ]; then
echo "mv ${rootdir}/weekly.0 ${rootdir}/weekly.1 "
echo "$(date "+[%d/%a/%Y:%H:%M:%S]") \
mv ${rootdir}/weekly.0 ${rootdir}/weekly.1 " >> \
${rootdir}/rsnapshot.log
mv ${rootdir}/weekly.0 ${rootdir}/weekly.1
fi
#-- Create weekly.0 ----------------------------------------+
echo "mv ${rootdir}/daily.0 ${rootdir}/weekly.0 "
mv ${rootdir}/daily.0 ${rootdir}/weekly.0
echo "ln -s ${rootdir}/weekly.0 ${rootdir}/daily.0 "
ln -s ${rootdir}/weekly.0 ${rootdir}/daily.0
fi

#-- Move log file ------------------------------------------+
mv /mnt/rev/rsnapshot.log /mnt/rev/daily.0/
touch /mnt/rev/rsnapshot.log

echo "<----------------------------------------------------------->"
echo "Rsnapshot.script finished... $(date "+%F %T") "
echo ""
/bin/sync;/bin/sync
umount /mnt/rev 2>&1 > /dev/null

echo "<----------------------------------------------------------->"
echo "/mnt/rev Umounted... $(date "+%F %T") "
/usr/bin/logger -i -p user.notice -t rsnapshot "/mnt/rev/ unmounted"

#-- Add comment to log -------------------------------------+
mount /mnt/rev
/bin/df -h /mnt/rev
echo "$(date "+[%d/%a/%Y:%H:%M:%S]") /mnt/rev unmounted" >> \
/mnt/rev/daily.0/rsnapshot.log
umount /mnt/rev 2>&1 > /dev/null

#-- Test for Saturday --------------------------------------+
if [ `date +%w ` -eq 6 ]; then
mail -s "REMOVE Rev Disk $(date "+%F %T") " bobh
fi

# RLH Smile
--
Bob Hillegas <bobhillegas < at > houston.rr.com>


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
rsnapshot-discuss mailing list
rsnapshot-discuss < at > lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rsnapshot-discuss

Post Proof of concept script changing interva 
I have made one modification to the driver script I sent in earlier this
week. rsnapshot gets an error on rm -rf /rootdir/daily.x/ when the
daily.x is a symbolic link and not a directory. That's because rsnapshot
always appends a trailing slash.

I have added a test prior to calling rsnapshot that takes care of that.
Note: this script is a proof of concept, not a fully functional addendum
to rsnapshot. It's just a daily and weekly0 thru weekly.2 script.

What it does is allow you to do things like save up to daily.34 while
every Saturday creating a weekly.x. from the newly created daily.0.

This could easily be extended to monthly and quarterly. Since it only
takes
1) mv daily.0 monthly.0
2) ln -s daily.0 monthly.0
to create a monthly backup, it can easily be extended ad hoc after the
fact to accommodate backups that don't fall on even boundaries of
shorter intervals.

Thanks, BobH


---<snip>---
#!/bin/bash
# /etc/cron.often/rsnapshot.script

arg1=${1:-0} # default to zero (daily) if undefined
# 0 -Daily
# 1 -Weekly
rootdir=/mnt/rev

#-- Test for mounted media ---------------------------------+
if [ ! -d /mnt/rev/lost+found ]; then
mount /mnt/rev
rc=$?
sleep 2
if [ $rc -ne 0 ];then
echo "Drive /mnt/rev NOT mounted!"
exit
fi
fi

#-- Invoke rsnapshot on a daily basis ----------------------+
# Change logic so that Weekly.0 is generated by:
# mv daily.0 weekly.0
# ln -s weekly.0 daily.0

if [ -L ${rootdir}/daily.6 ]; then
echo "rm -f ${rootdir}/daily.6 "
echo "$(date "+[%d/%a/%Y:%H:%M:%S]") \
rm -f ${rootdir}/daily.6 " >> \
${rootdir}/rsnapshot.log
rm -f ${rootdir}/daily.6
fi

echo "<----------------------------------------------------------->"
echo "Rsnapshot.script starting... $(date "+%F %T") "
echo ""

nice /usr/bin/rsnapshot daily
rc=$?
if [ $rc -ne 0 ];then
echo "Rsnapshot error caused exit"
exit
fi

if [ ${arg1} -eq 1 ]; then
#-- Roll weeklies ------------------------------------------+
if [ -d ${rootdir}/weekly.2 ]; then
echo "rm -fr ${rootdir}/weekly.2 "
echo "$(date "+[%d/%a/%Y:%H:%M:%S]") \
rm -fr ${rootdir}/weekly.2 " >> \
${rootdir}/rsnapshot.log
rm -fr ${rootdir}/weekly.2
fi

if [ -d ${rootdir}/weekly.1 ]; then
echo "mv ${rootdir}/weekly.1 ${rootdir}/weekly.2 "
echo "$(date "+[%d/%a/%Y:%H:%M:%S]") \
mv ${rootdir}/weekly.1 ${rootdir}/weekly.2 " >> \
${rootdir}/rsnapshot.log
mv ${rootdir}/weekly.1 ${rootdir}/weekly.2
fi

if [ -d ${rootdir}/weekly.0 ]; then
echo "mv ${rootdir}/weekly.0 ${rootdir}/weekly.1 "
echo "$(date "+[%d/%a/%Y:%H:%M:%S]") \
mv ${rootdir}/weekly.0 ${rootdir}/weekly.1 " >> \
${rootdir}/rsnapshot.log
mv ${rootdir}/weekly.0 ${rootdir}/weekly.1
fi
#-- Create weekly.0 ----------------------------------------+
echo "mv ${rootdir}/daily.0 ${rootdir}/weekly.0 "
mv ${rootdir}/daily.0 ${rootdir}/weekly.0
echo "ln -s ${rootdir}/weekly.0 ${rootdir}/daily.0 "
ln -s ${rootdir}/weekly.0 ${rootdir}/daily.0
fi

#-- Move log file ------------------------------------------+
mv /mnt/rev/rsnapshot.log /mnt/rev/daily.0/
touch /mnt/rev/rsnapshot.log

echo "<----------------------------------------------------------->"
echo "Rsnapshot.script finished... $(date "+%F %T") "
echo ""
/bin/sync;/bin/sync
umount /mnt/rev 2>&1 > /dev/null

echo "<----------------------------------------------------------->"
echo "/mnt/rev Umounted... $(date "+%F %T") "
/usr/bin/logger -i -p user.notice -t rsnapshot "/mnt/rev/ unmounted"

#-- Add comment to log -------------------------------------+
mount /mnt/rev
/bin/df -h /mnt/rev
echo "$(date "+[%d/%a/%Y:%H:%M:%S]") /mnt/rev unmounted" >> \
/mnt/rev/daily.0/rsnapshot.log
umount /mnt/rev 2>&1 > /dev/null

#-- Test for Saturday --------------------------------------+
if [ `date +%w ` -eq 6 ]; then
mail -s "REMOVE Rev Disk $(date "+%F %T") " bobh
fi

# RLH Smile
--
------------------------------------------------
Bob Hillegas bhillegas < at > dalcon.com
Dalcon Business Systems cell: (281) 546-9311
off: (615) 843-9000 efax: (717) 326-3952


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
rsnapshot-discuss mailing list
rsnapshot-discuss < at > lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rsnapshot-discuss

Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
  


Magic SEO URL for phpBB