SearchFAQMemberlist Log in
Reply to topic Page 1 of 1
My solution to delay shutdown when rsnapshot is running
Author Message
Post My solution to delay shutdown when rsnapshot is running 
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
RANDOM_DELAY=0
# the jobs will be started during the following hours only
START_HOURS_RANGE=6-22
#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 :
#!/bin/bash

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

gprintf "Starting wait_for_end_anacron_or_rsnapshot: "
echo_success
echo
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)
done
pidof anacron > /dev/null
if [ `echo $?` = 1 ]; then
gprintf "anacron process has stopped or was not running"
fi

[ -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)
done
if [ ! -e /var/run/rsnapshot.pid ]; then
gprintf "rsnapshot process has stopped or was not running"
fi
# 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/.gvfs
/home/vatbier/.adobe/Flash_Player/AssetCache/*
/home/vatbier/.cache/chromium/Cache/*
/home/vatbier/.cache/chromium/Default/Cache/*
/home/vatbier/.cache/chromium/Default/Media Cache/*
/home/vatbier/.cache/chromium/Media Cache/*
/home/vatbier/.gftp/cache/*
/home/vatbier/.java/deployment/cache/*
/home/vatbier/.macromedia/Flash_Player/*
/home/vatbier/.mozilla/firefox/6gu7oe0k.default/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

View user's profile Send private message
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