snapshot mtime updated

Steve Roome steve at lonres.com
Thu May 26 01:58:30 PDT 2005


I asked this yesterday, but the attachment had been stripped out,
stuck it on the end of the email this time.

Should I be asking this on some other mailing list ?

-- original message:
Hi all, I've got a problem where I'm taking a snapshot
of a filesystem, mdcofigging (readonly) and then mounting it ro,noatime.

Somehow the mtime on the snapshot file is being updated whenever I read
from the newly mounted md device (pointing at the snapshot).

This doesn't seem right, and I've included the script I'm using to
do this.  I'm not really interested in ways to fix this script,
though there are probably many better ways to do this, right now I'm
just unsure if this is the correct behavious for snapshots.

Thanks in advance if anyone knows what's going on here,

	Steve Roome

P.S. I'm not subscribed to the mailing list, please cc responses to me.

dodgy snapshot/remount/tar up script.
------------------------------------------------------------------------
#!/bin/sh
# Copyright Steve Roome. You can do what you like with this code, I'd
# suggest that you delete it. If you want to run it use:
# ./whateverthisis.sh <Mounted_UFS2_Partition>

SNAPMOUNT="/backup_mnt"

die() {
    echo $*
    exit 1
}

MOUNT=$1
MYUID=`id -u`
[ $MYUID -eq "0" ] || die "You are not root, you will need to be root to mount the snapshot"

# Check that this is a UFS2 mount point
/sbin/mount -p -t ufs | /usr/bin/awk '{print $2}' | grep -cx ${MOUNT} 2>&1 >/dev/null || die "$MOUNT is not a mounted ufs filesystem"

BACKUP_DIR=${MOUNT}/hourly_snaps
# Check that BACKUP_DIR exists and is writable

SNAPDIR=$MOUNT/.snap
[ -d $SNAPDIR ] || mkdir $SNAPDIR || die "Can't create $SNAPDIR"

SNAPBASE=${SNAPDIR}/`/bin/date "+%Y.%m.%d.%H:%M"`
SNAPFILE=${SNAPBASE}.snap
SNAPMOUNT="/backup_mnt"
SNAPTGZ=${SNAPBASE}.tgz
TEMPTGZ=${SNAPBASE}.temp

START_PWD=`pwd`

#echo "Snapshots will be saved in ${SNAPDIR}"
#echo "The next snapshot will be named ${SNAPFILE}"
#echo "The snapshot will be mounted on ${SNAPMOUNT}"
#echo "${SNAPMOUNT} will be tgz'ed to ${SNAPTGZ}"

touch ${SNAPFILE} > /dev/null 2>&1 && rm ${SNAPFILE} || die "Can't save snapshot in $SNAPFILE"
touch ${TEMPTGZ} > /dev/null 2>&1 && rm ${TEMPTGZ} || die "Can't save snapshot in $SNAPFILE"
[ -d $SNAPMOUNT ] || mkdir $SNAPMOUNT || die "Can't create mount point $SNAPMOUNT"

# Check that SNAPFILE can be created/deleted

mksnap_ffs $MOUNT $SNAPFILE && MD_DEV=`mdconfig -a -t vnode -f $SNAPFILE` && mount -o ro,noatime /dev/$MD_DEV /${SNAPMOUNT}

cd ${SNAPMOUNT} && tar -czp --exclude .snap/ -f ${TEMPTGZ} . 2>/dev/null || die "Failed to create tarfile: ${TEMPTGZ} PLEASE INVESTIGATE"
cd ${START_PWD}
umount ${SNAPMOUNT}
MD_UNIT=`echo $MD_DEV | sed -e 's/^md//g'`

mdconfig -d -u ${MD_UNIT} && rm -f ${SNAPFILE} && rmdir ${SNAPMOUNT} && mv ${TEMPTGZ} ${SNAPTGZ} && echo "${SNAPTGZ} ceated successfully from snapshot of ${MOUNT}" || die "Did not manage to clear up after backing up ${MOUNT}\nIntervention recommended"

# finished okay!
exit 0


More information about the freebsd-questions mailing list