Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 May 2005 15:41:15 +0100
From:      "Steve Roome" <steve@lonres.com>
To:        freebsd-hackers@freebsd.org
Subject:   Snapshots mtime seems to be getting updated
Message-ID:  <20050531144115.GA1317@bibipentium.lonres.com>

next in thread | raw e-mail | index | archive | help
Hi posted this to -questions, but I'm not getting any takers.

This is on a few variants on -stable up to and around 5.4. I've not
tested this on any FreeBSD box yet and found things to be working as
expected.

------------------------------------------------------------------------
I'm taking a snapshot of a filesystem, mdconfigging and then mounting
it read only,noatime.

Somehow the mtime on the snapshot file is being updated (I think it's
when I read) from the newly mounted md device of 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050531144115.GA1317>