On Mon, 15 May 2006, Alan Brown wrote:
Has anyone used LVM/EVMS snapshots to get a stable image to backup?
If so, how do you do it?

I do it under CentOS-4 with xfs and ext3 filesystems using the ClientRunBefore and ClientRunAfter directives in the job file. I mount the snapshots under /mnt and have those mountpoints in the fileset. It would be nice to be able to strip a path-prefix and and I believe that this is on the list of features to be implimented.

For creating and deleting the snapshots I use a script that I install in /usr/local/sbin on the clients. It could certainly be improved and may have some things specific to RedHat-deerived distros. I am appending my script. Comments are welcome.

In job directive:

# Create a snapshot with a 4G for COW space
ClientRunBeforeJob = \
  "/usr/local/sbin/snapshot -L 4G /export/home /mnt/home"

FileSet = "mnt_home"

# Delete the snapshot
ClientRunAfterJob  = \
   "/usr/local/sbin/snapshot -d /mnt/home"


On the client as /usr/local/sbin/snapshot:

#!/bin/bash
# Create or delete a snapshot using LVM
# The logical-volume name has SS_ prependend to the target.
# e.g. A snapshot of /dev/vg0/home is created as /dev/vg0/SS_home

set -o errexit

PATH="/sbin:/bin:/usr/sbin:/usr/bin"

function GetLogVol()
{
    local LOGVOL

    # Determine the logical-volume path from the mount point
    LOGVOL=$(mount | awk -v p=$1 '$3 == p {print $1}')
    if [[ -z "$LOGVOL" ]]; then
        echo "${0}: $1 not a mount point" 1>&2
        exit 1
    fi

    if [[ $(dirname $LOGVOL) == "/dev/mapper" ]]; then
        LOGVOL=$( find /dev -lname $LOGVOL )
    fi

    # Check that this is a LV
    if ! lvs $LOGVOL > /dev/null 2>&1; then
        echo "${0}: $LOGVOL is not a logical volume" 1>&2
        exit 1
    fi

    echo "$LOGVOL"
}

# Default snapshot size of 2GB
SSSZ="2G"

CREATE_SNAP=true

if getopts L:d option
then
    case $option in
        L)  SSSZ="$OPTARG"
            shift 2
            ;;
        d)  CREATE_SNAP=false
            ;;
        ?)  exit 1
            ;;
    esac
fi

if (( $# != 2 )); then
    echo "Usage: $0 [-L size] FileSystemPath SnapshotPath" 1>&2
    echo "___or: $0 -d SnapshotPath" 1>&2
    exit 1
fi

SSPATH="$2"

if $CREATE_SNAP ; then
    FSPATH="$1"

    FSLV=$(GetLogVol $FSPATH)
    FSTY=$(mount | awk -v p=$FSPATH '$3 == p {print $5}')

    [[ "$FSTY" == xfs ]] && FSTY="xfs -o nouuid"

    SSNM=SS_$(basename $FSLV)
    SSLV=$(dirname $FSLV)/$SSNM

    modprobe dm-snapshot

    lvcreate --size "$SSSZ" --snapshot --name $SSNM $FSLV
    mkdir -p $SSPATH
    mount -v -r -t $FSTY $SSLV $SSPATH
else
    SSLV=$(GetLogVol $SSPATH)

    # Check that this LV is a snapshot
    SSLV_ATTR=$(lvs --noheadings -o lv_attr $SSLV)
    if [[ "$SSLV_ATTR" != *s* ]]; then
        echo "${0}: $SSPATH is not a snapshot" 1>&2
        exit 1
    fi

    umount -v $SSPATH
    lvremove -f $SSLV
    rmdir --ignore-fail-on-non-empty $SSPATH
fi


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users

Reply via email to