Re: [Hampshire] Automating rsync to run as root

Top Page

Reply to this message
Author: Stuart Sears
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Automating rsync to run as root
Russell Gadd wrote:
> 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.


Nah, it doesn't. But being able to see your script might help with
suggestions. :)

[..snip..]
> 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.


or you could invoke it using ~/.bash_logout ?

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



If this really needs to be run as root then you'll probably want to use
sudo for that

BUT: why does it need to run as root? Do you routinely log in and
create/edit files as root? HJow many users' files do you include in this
backup?
You can mount a vfat filesystem with a specific UID if you need to, so
that backups can be made as ordinary users.

> [ cron job ]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.


find will do this for you.

on login (for example in ~/.bash_profile)

# touch /tmp/timestamp

then when you do your backup you can generate a list of new/changed
files like this:

# find /some/directory -newer /tmp/timestamp

you can automatically tar these files up a little like this....

# find /some/directory -newer /tmp/timestamp | \
xargs tar cjpf my-backup.tar.bz2 -

And at the end of the job, touch /tmp/timestamp again to update its
modification/access times

although you may wish to exclude some files from backups.



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?


the 'handshake' can just as easily be a simple file that is created when
you finish the job.

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


here is just fine :)

--
Stuart Sears RHCA RHCX
To err is human, to forgive is Not Company Policy.