rsync snapshot problem deleting files
Mark L. Chang
marklchang at acmelab.org
Sun Dec 15 05:50:01 EST 2002
Mike Rubel wrote:
> Has anyone else seen Mark's problem, which sounds like a weird interaction
> issue between samba and rsync?
>
> Mark, I will add a note about your experience here to the web page; so
> far it's the only report I've seen though, and I'd really like to get
> more data. Is anyone else running the rsync-snapshot trick from windows
> machines via Samba? Can we get more debugging information to determine
> the source of the problem?
All I can offer is the source to the script I'm using. Here it is -- it
is very much your script, Mike, but with me-specific changes :). Please
don't laugh at my bad /bin/bash-isms :). All variables that look
external are sources from another host-specific config file not shown.
-- BEGIN 'snapshot' --
#!/bin/bash
# ----------------------------------------------------------------------
# mikes handy rotating-filesystem-snapshot utility
# ----------------------------------------------------------------------
# RCS info: $Id: make_snapshot.sh,v 1.6 2002/04/06 04:20:00 mrubel Exp $
# ----------------------------------------------------------------------
# this needs to be a lot more general, but the basic idea is it makes
# rotating backup-snapshots of /home whenever called
# ----------------------------------------------------------------------
# ------------- system commands used by this script --------------------
ID=/usr/bin/id;
ECHO=/bin/echo;
MOUNT=/bin/mount;
UMOUNT=/bin/umount
RM=/bin/rm;
MV=/bin/mv;
CP=/bin/cp;
TOUCH=/bin/touch;
RSYNC=/usr/bin/rsync;
# ------------- file locations -----------------------------------------
SCRIPTDIR=/files/backup/scripts
BACKUPMOUNT=/mnt/backup
# ------------- the script itself --------------------------------------
# make sure we're running as root
if (( `$ID -u` != 0 )); then { $ECHO "Sorry, must be root. Exiting...";
exit; } fi
# attempt to load the config
if [ ! $1 ] ; then
$ECHO "Usage: snapshot hostname"
exit 65
fi
BACKUPHOST=$1
if [ -x $SCRIPTDIR/$BACKUPHOST ] ; then
. $SCRIPTDIR/$BACKUPHOST
else
$ECHO "Sorry, that host is not configured."
exit 666
fi
# attempt to mount the smb share
$MOUNT -o ro -t smbfs //$BACKUPHOST/$SHARE $BACKUPMOUNT -o
username=$USERPASS ;
if (( $? )); then
{
$ECHO "snapshot: could not mount share $BACKUPHOST/$SHARE";
$ECHO "snapshot: failed to mount $BACKUPHOST/$SHARE" >> $BACKUPLOG
exit;
}
fi;
$ECHO "[`date`] snapshot started for $BACKUPHOST/$SHARE" >> $BACKUPLOG
# step 1: delete the oldest snapshot, if it exists:
if [ -d $SNAPSHOTDIR/$SHARE/snap.3 ] ; then
$RM -rf $SNAPSHOTDIR/$SHARE/snap.3 ;
$ECHO "[`date`] Deleted $SNAPSHOTDIR/$SHARE/snap.3" >> $BACKUPLOG
fi ;
# step 2: shift the middle snapshots(s) back by one, if they exist
if [ -d $SNAPSHOTDIR/$SHARE/snap.2 ] ; then
$MV $SNAPSHOTDIR/$SHARE/snap.2 $SNAPSHOTDIR/$SHARE/snap.3 ;
$ECHO "[`date`] Shifted $SNAPSHOTDIR/$SHARE/snap.2" >> $BACKUPLOG
fi;
if [ -d $SNAPSHOTDIR/$SHARE/snap.1 ] ; then
$MV $SNAPSHOTDIR/$SHARE/snap.1 $SNAPSHOTDIR/$SHARE/snap.2 ;
$ECHO "[`date`] Shifted $SNAPSHOTDIR/$SHARE/snap.1" >> $BACKUPLOG
fi;
# step 3: make a hard-link-only (except for dirs) copy of the latest
snapshot,
# if that exists
if [ -d $SNAPSHOTDIR/$SHARE/snap.0 ] ; then
$CP -al $SNAPSHOTDIR/$SHARE/snap.0 $SNAPSHOTDIR/$SHARE/snap.1 ;
$ECHO "[`date`] Shifted $SNAPSHOTDIR/$SHARE/snap.0" >> $BACKUPLOG
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!
$ECHO "[`date`] Snapshot started: $SNAPSHOTDIR/$SHARE/snap.0" >> $BACKUPLOG
$RSYNC -va --delete --delete-excluded
--exclude-from="$EXCLUDES" --stats $BACKUPMOUNT/ \
$SNAPSHOTDIR/$SHARE/snap.0 > $BACKUPDIR/${BACKUPHOST}.output 2>&1 ;
# step 4.5: write logs
cat $BACKUPDIR/${BACKUPHOST}.output >> $BACKUPLOG
$ECHO "[`date`] Snapshot finished: $SNAPSHOTDIR/$SHARE/snap.0" >> $BACKUPLOG
# step 5: update the mtime of hourly.0 to reflect the snapshot time
$TOUCH $SNAPSHOTDIR/$SHARE/snap.0 ;
# and thats it for home.
# now remount the RW snapshot mountpoint as readonly
$UMOUNT $BACKUPMOUNT ;
if (( $? )); then
{
$ECHO "snapshot: could not umount backupdir";
exit;
} fi;
-- END 'snapshot' --
More information about the rsync
mailing list