Re: [Hampshire] Automating rsync to run as root

Top Page

Reply to this message
Author: James Courtier-Dutton
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Automating rsync to run as root
On 12/09/2007, Russell Gadd <rustleg@???> wrote:
>
> 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.
>


You could create a disk image on the VFAT partition and format it as
ext3. Then mount the image as a loopback and rsync to that. Then you
would not have to do tar.

> 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.


Use sudo
You might need to edit the /etc/sudoers file
sudo rsync .....

>
> 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.


You might want to look at LVM. It has snapshot features that might
save some steps.

>
> 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?


Just use sudo instead. That is what sudo is for.

>
> 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
>


Cheers

James