[Hampshire] Automating rsync to run as root

Top Page

Reply to this message
Author: Russell Gadd
Date:  
To: hampshire
Subject: [Hampshire] Automating rsync to run as root
I'd like to ask for advice re a backup system I'm trying to set up for
Linux. I have given some background which please excuse if it seems a bit
long.

I have used Windows for many years and have recently decided to try to
convert to Linux as I don't want to go down the Vista route, so I am a Linux
greenhorn (apologies in advance for my ignorance). I have a boot manager
(BootitNG) which allows me to run Windows XP (actually 3 different instances
- home, work and internet banking) and I have installed Debian and Ubuntu
alongside these. My goal at present is to get beyond the "playing with it"
stage to do some real work and so I want to first set up a backup system and
then address some basic security issues (which I need to do more research
on).

My "daily" backup system will copy my personal files to a folder on a
separate FAT-32 (VFAT) partition (shared with Windows) and then mirror this
partition to a second hard drive. Also copy the files to a USB stick
(permanently connected in a port in the back of the PC) - "belt and braces".
A "weekly" routine will copy backup files to a CD (then stored in my garage
separate from the house). I have this automated in Windows via an icon on
the desktop (running a batch command file) which is what I want to achieve
in Linux also.

I separate personal files from files which can be recovered if necessary
from a new install of the OS and software. I backup the latter via imaging
the OS partitions and mirroring them to the second hard drive and
occasionally to DVD.

I currently have a simple bash script (my first!) which uses tar and rsync.
In order to backup onto a VFAT partition I have had to use tar to preserve
permissions, which seems ok. Although it necessitates rewriting all the data
not just the changed data, this doesn't amount to a lot of stuff.

My problem is with rsync, which I use so that it only needs to mirror the
files which have changed, since the partitions to mirror contain a lot more
than just the personal data (e.g. Linux .iso images, things stored on DVD,
etc). To get it to run from an icon on the desktop (Gnome) I have initially
resorted to the setuid bit to allow rsync to run as root otherwise it
refuses to clone the partition. However I understand this is not good from a
security standpoint and I need to find a better solution. It also breaks
when rsync is updated (via Synaptic) which I found out recently, as I
presume the executable has been replaced by a newer version so the setuid
bit would need tweaking again.

Most discussions of backup I have seen talk about using cron, but my PC is
not on 24/7 and I want to continue my practice of invoking the backup
routine at the end of a session of work shortly before I pull the plug, so
either I want to be able to start if from an icon on the desktop. Or maybe a
script which can be set up to run on logoff - I haven't checked into whether
this is possible or how to do this yet - maybe this could be a root script?.
But somehow I prefer the manual invocation via an icon.

My current rough idea to solve this is to set up a sort of handshake which
is maybe a bit clumsy. The desktop icon would run a script which sets a flag
- just a date/time saved in a text file, and there would be a cron script
owned by root which runs say once per minute to check this file for the
latest date/time and perform a backup when it sees the date/time is later
than the last backup. I haven't looked at cron in any detail yet so there
may be gotchas here. I don't know whether there would be problems with a
collision if the user script was writing the file when cron is trying to
read it. Also how would I know when the job has been done and if it suceeded
? - maybe the user bash script would need to run continuously looking for an
end of job handshake from the backup script?

I would appreciate comments on this idea or any alternative ideas- thanks in
advance. Also if I should instead be asking this in some other mailing list,
please tell me where to go (politely I hope:)

Russell