rsync cron
Asheville Joe
josephj at main.nc.us
Fri Sep 26 13:54:56 EDT 2003
Here's the script I am running now. It is saved in the /etc/cron.daily
directory (so cron runs it for me every day without my doing anything
else) and owned by root. I'm adding more comments here in the form of
lines starting with // . They should all be stripped out if you copy
this for your use.
The main thing to note is that since this version is run by cron in the
background, it doesn't echo anything to the console.
If you make a version for youself or write your own, it would be a good
idea to run it first with -n and -vv. That will show you all the files
it is copying.
The onl;y problem I have now is that rsync tells me it looked at about
1500 more files than it copied, but I don't know which ones. Probably a
bunch of them are the . and .. entries in each directory.
Hope this helps.
Joe
#!/bin/bash
# Dailyback1 - (C) 09/24/03 - JPmicrosystems - GNU GPL applies
# Backup /home to big portable drive using rsync
#This version is for cron to run in background
name="dailyback1"
// I created a directory called maint under /var/log to hold any logs
from system maintenance tasks I create
//I keep a short log of what this script did so when I need to restore
something, I'll know at a glance what the situation is.
echo "`date` - $name: Started backup /home" >> /var/log/maint/backup.log
// My second drive is a removeable drive and it is not set (in
/etc/fstab) to automount
# First, make sure the portable drive is mounted
df | grep 'hdb1' > /tmp/backuptmp
if [ ! -s /tmp/backuptmp ]
then
mount /dev/hdb1 /mnt/portable
status=$?
if [ $status != 0 ]
then
echo "`date` - $name: Couldn't mount hdb1 = status was $status" >>
/var/log/maint/backup.log
exit $status
fi
fi
// This does the actual backup. -z, -P, and --no-whole-file probably
aren't necessary. --delete helps with the extremely annoying problem of
having
// stuff you've deleted come back when you restore from a backup.
--stats gioves me something to look at in my log so I know the backup
actually did
// something.
echo "Backup of /home - `date`" > /mnt/portable/rsync.log
/usr/bin/rsync -a -H -z -P --delete --no-whole-file --stats /home
/mnt/portable/homersync >> /mnt/portable/rsync.log
status=$?
echo "Backup Ended /home - `date`" >> /mnt/portable/rsync.log
if [ $status -gt 0 ]
then
echo "`date` - $name: Backup of /home FAILED with status $status" >>
/var/log/maint/backup.log
exit $status
fi
// make sure I don't get a huge log entry (even if I add a -vv parameter
later, etc)
tail -20 /mnt/portable/rsync.log >> /var/log/maint/backup.log
echo "`date` - $name: Finished backup /home" >> /var/log/maint/backup.log
exit $status
JB wrote:
>I found this on the web along with tons of other info
>about rsync.
>http://networking.earthweb.com/netos/article.php/10951_1573881_1
>It indicates the command I would need to rsync is
>$ rsync -a sourcedir destinationdir
>I want to rsync
>hda1 /home to a spare partition on hdb2 /jeb
>The problem is everything I have tried comes up with
>an error and I didn't even get to the cron part yet. I
>would like to have it run at 3 am daily and also
>delete files that were deleted on hda1 /home during
>the day. It says to use the delete command with
>caution, do a dry run first. If anyone has a
>recommendation, other ways, or can point me in the
>right direction, I'm all ears...
>Thanks in advance,
>
>
>
--
----------------------------------
"It is well enough that people of the nation do not understand our banking and monetary system, for if they did, I believe there would be a revolution before tomorrow morning." -- Henry Ford
More information about the nflug
mailing list