Welcome! » Log In » Create A New Profile

My solution to delay shutdown when rsnapshot is running

Posted by vatbier 
My solution to delay shutdown when rsnapshot is running
April 09, 2011 09:20AM
Mandriva Linux 2010.1 here with KDE.

My solution to prevent/delay shutdown when rsnapshot is running may be flawed. Please tell me if it is.

cron runs every hour /etc/cron.hourly/0anacron which starts "anacron -s" if anacron hasn't run before that day.
cron runs cron.daily, cron.weekly and cron.monthly during the night between 4:02 and 5:22.My computer usually doesn't run at night therefore anacron.
I've commented out the command "/usr/bin/rsnapshot hourly > /dev/null" in cron.hourly/rsnapshot as I only want rsnapshot run once a day.

My /etc/anacrontab:
# the maximal random delay added to the base delay of the jobs
# the jobs will be started during the following hours only
#period in days delay in minutes job-identifier command
1 5 cron.daily nice -n 19 run-parts /etc/cron.daily
7 6 cron.weekly nice -n 19 run-parts /etc/cron.weekly
@monthly 7 cron.monthly nice -n 19 run-parts /etc/cron.monthly
the first job starts 5 minutes after "anacron -s" has started. The second job( weekly) starts a minute ("6") later or later if the first job takes longer than one minute.

I made a script to be run at KDE shutdown which waits until anacron has stopped running. It also waits until rsnapshot has stopped running in case rsnapshot was started at night at 4:02 by cron.
First I made an init script which would be run at shutdown or reboot as/etc/rc.d/rc5.d/K16wait_for_end_anacron_or_rsnapshot. But when that script runs (which means rsnapshot is running) it is not possible to log in on another terminal (e.g. tty2 (ctrl-alt-f2)).
Therefore I put a script in KDE>systemsettings>Startup and Shutdown>Run On Shutdown: /home/vatbier/Documents/scripts/wait_for_end_anacron_or_rsnapshot.sh

/home/vatbier/Documents/scripts/wait_for_end_anacron_or_rsnapshot.sh :

# Source function library.
. /etc/rc.d/init.d/functions

gprintf "Starting wait_for_end_anacron_or_rsnapshot: "
pidof anacron > /dev/null
[ `echo $?` = 1 ] && ANACRON=0 || ANACRON=1
while [ $ANACRON = 1 ]; do
pidof anacron > /dev/null
[ `echo $?` = 1 ] && ANACRON=0 || (gprintf "anacron still runs";sleep 60)
pidof anacron > /dev/null
if [ `echo $?` = 1 ]; then
gprintf "anacron process has stopped or was not running"

[ -e /var/run/rsnapshot.pid ] && RSNAPSHOT=1 || RSNAPSHOT=0
while [ $RSNAPSHOT = 1 ]; do
[ ! -e /var/run/rsnapshot.pid ] && RSNAPSHOT=0 || (gprintf "rsnapshot still runs";sleep 60)
if [ ! -e /var/run/rsnapshot.pid ]; then
gprintf "rsnapshot process has stopped or was not running"
# whoami > /home/vatbier/Documents/scripts/whoami_at_wait_for_end_ana : this script is run by user vatbier
# play /home/vatbier/Documents/scripts/SmackMyBitchUp_begin.mp3

When this script is run at KDE shutdown tty8 changes from KDE desktop to blank until the script ends and the screen swithes to tt1 to display rest of shutdown output.
While the script runs and if "rsnapshot sync" takes a long time I am able to log in on another terminal and for instance see what rsnapshot is doing (tail -f /var/log/rsnapshot).

And to make "rsnapshot sync" work I had to add single quotes around exclude directories with spaces and parentheses in rsnapshot.conf:
exclude '/home/vatbier/Music/directory with spaces and (parentheses)'
exclude /home/vatbier/test/tmp/exclude_directory/

and I had to put in my rsnapshot_rsync_exclude_from.txt the directory /home/vatbier.gvfs because it is not accessible by root which runs rsnapshot:
/home/vatbier/.cache/chromium/Default/Media Cache/*
/home/vatbier/.cache/chromium/Media Cache/*

My first daily.0 was 1.1 GB big.

root@this efexor]# rsnapshot du
1.1G /media/ElementsA/backup/ML2010.2/daily.0/
166M /media/ElementsA/backup/ML2010.2/daily.1/
301M /media/ElementsA/backup/ML2010.2/daily.2/
1.6G total
Sorry, only registered users may post in this forum.

Click here to login