Backing up Xen DomUs - NFS vs. LVM Snapshots

Discussion in 'Installation/Configuration' started by atjensen11, Aug 12, 2009.

  1. atjensen11

    atjensen11 New Member

    I am looking for input regarding how to backup DomU machine filesystems.

    My system is a Debian Lenny Dom0. All DomUs to date are Debian Lenny as well. All DomUs are backed by LVM.

    Initially, because of the use of LVM, I had planned to conduct backups from the Dom0 to an externally attached eSATA drive using LVM snapshots. However, recent discussion on the Xen mailing lists have caused me to question this approach. The discussion focussed mainly on the inability of snapshots to backup data that is in cache at the time the snapshot is created.

    This has led me to consider making an NFS server DomU. I would plan on backing the "disks" in the DomU with either LVM partitions or by passing the physical disk of the eSATA external drive. Then I would modify the DomU Xen config files to mount the NFS shares to accomplish the backup. The backups would be done at the DomU level in this configuration over the virtualized network to the NFS server.

    I would like to get some input on which approach may be better. Not of my systems are highly mission critical. They are however, highly utilized and would cause a great deal of stress on my behalf if they weren't easily brought back online.

    Are there backup configurations that I haven't considered to date that may be better than the two approaches above?
     
  2. matey

    matey New Member

    we also use lvm and rsnapshot (uses rsync) along with cron to do our xen (domu) backups.
    if you need to I can post our scripts.
     
  3. atjensen11

    atjensen11 New Member

    I just ran across some rsync snapshot articles yesterday and thought it would suit my needs.

    If you are willing, I would be very interested in seeing your scripts.
     
  4. matey

    matey New Member

    Cool, I have to post a couple bcs in one script it refers to another ;
    This is a Daily script;

    #!/bin/bash

    DIR=/root/backup
    BACKUP_CMD=backup-lv.sh

    VG=/dev/vg1 #whichever folder your xen files located at)
    LV[0]=xen-1 # (name of diff, xen machines/guests)
    LV[1]=xen-2
    LV[2]=xen2-data #xen2 is a web server with large amount of data
    LV[3]=xen-3

    cd $DIR
    COUNT=0
    CAT_STR=""
    while [ $COUNT -lt ${#LV[@]} ]
    do
    ./$BACKUP_CMD $VG/${LV[$COUNT]} &> last-backup-${LV[$COUNT]}
    CAT_STR="${CAT_STR} last-backup-${LV[$COUNT]}"
    MOO=$((COUNT++))
    done

    ls -lh /mnt/system_backups/ &> last-backup-ls
    cat $CAT_STR last-backup-ls > last-backup.txt
    echo "daily backup report attached" | mutt -s "$HOSTNAME daily backup report" -a last-backup.txt [email protected]
    ______________________________________________________________________________________

    This is backup-lv.sh

    #!/bin/bash

    LV=$1

    export PATH=$PATH:/sbin

    echo Backing up $LV...
    if ! [ -e $LV ]; then
    echo ' ...No such device exists!'
    exit 1
    fi

    NAME=`expr "$LV" : ".*\/\(.*\)$"`
    NAME_SNAP=${NAME}_snap
    LV_SNAP=${LV}_snap

    /etc/init.d/udev restart
    sleep 120
    echo ' ...Creating snapshot'
    lvcreate -s -n${NAME_SNAP} -L1024 $LV
    RV=$?
    while [ $RV -gt 0 ]
    do
    lvremove -f ${LV_SNAP}
    sleep 120
    lvcreate -s -n${NAME_SNAP} -L1024 $LV
    RV=$?
    done
    mkdir -p /mnt/${NAME_SNAP}
    echo ' ...Mounting snapshot'
    mount ${LV_SNAP} /mnt/${NAME_SNAP}
    cd /mnt/${NAME_SNAP}/
    echo ' ...Creating archive'
    tar czf /mnt/system_backups/${NAME}.tgz *
    cd /
    echo ' ...Unmounting and removing snapshot'
    umount /mnt/${NAME_SNAP}
    lvremove -f ${LV_SNAP}
    echo ' All done!'
    echo
    sleep 120

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

    This is lv-rsync.sh

    #!/bin/bash

    LV=$1

    export PATH=$PATH:/sbin

    echo Backing up $LV...
    if ! [ -e $LV ]; then
    echo ' ...No such device exists!'
    exit 1
    fi

    NAME=`expr "$LV" : ".*\/\(.*\)$"`
    NAME_SNAP=${NAME}_snap
    LV_SNAP=${LV}_snap

    /etc/init.d/udev restart
    sleep 121
    echo ' ...Creating snapshot'
    lvcreate -s -n${NAME_SNAP} -L1024 $LV
    RV=$?
    while [ $RV -gt 0 ]
    do
    lvremove -f ${LV_SNAP}
    sleep 121
    lvcreate -s -n${NAME_SNAP} -L1024 $LV
    RV=$?
    done
    mkdir -p /mnt/${NAME_SNAP}
    echo ' ...Mounting snapshot'
    mount ${LV_SNAP} /mnt/${NAME_SNAP}
    echo ' ...rsyncing'
    rsync -avz --delete -e "ssh" /mnt/${NAME_SNAP}/* 192.168.1.10:/mnt/${NAME}/ #Or whatever IP ?DNS Name??
    #cd /mnt/${NAME_SNAP}/
    #echo ' ...Creating archive'
    #tar czf /mnt/system_backups/${NAME}.tgz *
    #cd /
    echo ' ...Unmounting and removing snapshot'
    umount /mnt/${NAME_SNAP}
    lvremove -f ${LV_SNAP}
    echo ' All done!'
    echo
    sleep 120

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

    This one is a general backup script

    #!/bin/sh
    tar czvf $1.$(date +%Y%m%d-%H%M%S).tgz $1
    exit $?

    I call it backit and do like
    ./backit /directory_name
    it will create a .year.month.day-hour.minute.sec.tgz file
    but since it starts with a dot . it may be hidden in some systems
    ls -a or take out the dot
     
    Last edited: Aug 20, 2009
  5. matey

    matey New Member

    I found some interesting articles on mirroring servers;
    They use apt-mirror in Debian/Ubuntu by apt-get install in here;
    http://www.packtpub.com/article/create-local-ubuntu-repository-using-apt-mirror-apt-cacher

    This link shows how to create quick virtual machines?
    If anyone has any experience with these (juice-vm/debmirror) please share:

    https://help.ubuntu.com/community/JeOSVMBuilder

    https://help.ubuntu.com/community/Debmirror

    In any case I am told to make a backup copy of our main server which is off site and cannot be reached physically, so I have another machine here which is not similar (less ram diff. hard drive config, etc, etc,) and it is running Hardy whereas our off site server is running Feisty so I am not so sure how I could make an exact copy of the off site server (in case it went down this one will take over)? Plus pulling all the data/the OS would slow our already slow network down to halt!

    Any ideas, info would be appreciated!
    PS right now I am using those scripts do to the backups but if the main server goes out the backup files go with it cuz they are getting stored in there. Plus we have 4 Xen machines running off that 1 off-site server and our web site is in one of those xen machines...


    BTW I forgot to post a weekly backup script:

    #######################################################################################
    #!/bin/bash

    keychain id_rsa
    . ~/.keychain/$HOSTNAME-sh

    DIR=/root/backup
    BACKUP_CMD=backup-lv-rsync.sh

    VG=/dev/vg1 ###(This is where the xen files/volumes/machines reside)
    LV[0]=xen-1 ###(These are the names of different xen guest machines)
    LV[1]=xen-2
    LV[2]=xen-2_data ###(split this one xen-2 machine into 2 since has a large data stored)
    LV[3]=xen-3

    cd $DIR
    COUNT=0
    CAT_STR=""
    while [ $COUNT -lt ${#LV[@]} ]
    do
    ./$BACKUP_CMD $VG/${LV[$COUNT]} &> last-backup-${LV[$COUNT]}
    CAT_STR="${CAT_STR} last-backup-${LV[$COUNT]}"
    MOO=$((COUNT++))
    done

    ls -lh /mnt/system_backups/ &> last-backup-ls
    cat $CAT_STR last-backup-ls > last-backup.txt
    echo "weekly backup report attached" | mutt -s "$HOSTNAME weekly backup report" -a last-backup.txt [email protected]
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------

    crontab -e

    # m h dom mon dow command
    01 05 * * 1,2,3,4,5,6 /root/backup/backup-daily.sh
    01 05 * * 7 /root/backup/backup-weekly.sh
     
    Last edited: Aug 20, 2009

Share This Page