View Single Post
Old 29-Nov-2007, 03:29 AM   #1 (permalink)
Anilrgowda
Administrator
 
Anilrgowda's Avatar

Posts: 18,715
Join Date: Jan 2006
Rep Power: 10 Anilrgowda is on a distinguished road

IM:
Default Need help with a small batch file

I'm using rsync on linux to sync files from another server.

Sometimes rsync fails and it produces instead of a folder named hourly.0 an empty file hourly.0
that file blocks any further processing, thus effectively stopping the sync process.

this is the program part in question

#!/bin/bash
# ------------- system commands used by this script --------------------
ID=/usr/bin/id;
ECHO=/bin/echo;

MOUNT=/bin/mount;
RM=/bin/rm;
MV=/bin/mv;
CP=/bin/cp;
TOUCH=/usr/bin/touch;
RSYNC=/usr/bin/rsync;

# ------------- file locations -----------------------------------------

SNAPSHOT_RW=/backup/handling/snapshot/server1;
SOURCE_DIR=/backup/smb/server1;
EXCLUDES=/usr/local/etc/backup_exclude;

...
# step 3: shift the first snapshots(s) back by one, if they exist,
# if that exists
if [ -d $SNAPSHOT_RW/hourly.0 ] ; then \
$MV $SNAPSHOT_RW/hourly.0 $SNAPSHOT_RW/hourly.1 ; \
fi;

# step 4: rsync from the system into the latest snapshot (notice that
# rsync behaves like cp --remove-destination by default, so the destination
# is unlinked first. If it were not so, this would copy over the other
# snapshot(s) too!
$RSYNC \
-a --delete --delete-excluded \
--progress \
--exclude-from="$EXCLUDES" \
--modify-window=5 \
--link-dest=$SNAPSHOT_RW/hourly.1 \
$SOURCE_DIR $SNAPSHOT_RW/hourly.0 ;



I could need some help to change it this way:

* In step 3 - check if instead of a folder hourly.0 a file hourly.0 exists.
* If yes delete that file and procede to step 4 (+ send me a mail about the incident)
* if no continue with step 3

That's all.


------------------


Anilrgowda is offline   Reply With Quote