Archive for January, 2013

NetApp – Copy LUN between filers using NDMP

Saturday, January 19th, 2013

ndmpcopy is a wonderful command. It allows a fine-grained copy of files or directories between NetApp devices, across network, even if they do not use (or unlicensed) SnapMirror, SnapVault and the rest of the Snap* products NetApp offer.
In this example I will show how to copy a LUN from one filer to the other.

First, set the LUN to offline on the source filer. Make sure that it is not mounted, disconnected, etc – whatever prevents any major data loss. As you can deduce – setting a LUN to offline state will prevent write access to it. Also – take its parameters. For example:

lun show -v /vol/server1/data/mydb.lun

Second, create the required qtree structure. Make sure that the LUN is created at the root of either a volume or a qtree, or else.

Third, use ndmpcopy:

ndmpcopy -da root:password /vol/server1/data/mydb.lun remotefiler:/vol/server1/data/

This operation will take time.

When it completes, on the target NetApp, set priv to diag, and do the following:

  • Rename the LUN:
    mv /vol/server1/data/mydb.lun /vol/server1/data/mydb.not.lun
  • Create a hard-link LUN from a file (requires priv diag!)
    lun create -f /vol/server1/data/mydb.not.lun -t linux -o noreserve /vol/server1/data/mydb.lun
    (Command syntax: lun create -f <file_path> -t <ostype> [ -o noreserve ] [ -e space_alloc ] <lun_path>)
  • Remove the original file (it is hard-linked, so the data will not be affected)
    rm /vol/server1/data/mydb.not.lun
  • Resize, if required, the LUN to the original full size (relevant if the LUN was thin-privisioned)
    lun resize /vol/server1/data/mydb.lun 400g

You can now map the LUN to any relevant host, and obtain full access to its data.

XenServer – Setting virtual disks names based on the VM names

Wednesday, January 2nd, 2013

One of the worst things you can have in XenServer, is some wize-guy performing a ‘forget storage’ on a storage device still holding virtual disks related to VMs. As XenServer database is internal (for the whole pool) and not per-VM, all references to this virtual disks disappear, and you remain with bunch of VMs without disks, and later on, when the recovered from the shock and restored the SR, with a bunch of virtual disks you have no clue as to where they belong. Why? Because we are lazy, and we tend to skip the part where you can (or is it – should?) define a custom name for your virtual disks so you would know later on (for example – in the case specified above) where they belong(ed).

To solve this annoying issue, and to save time for Citrix XenServer admins, I have created a script which resets the VDI (virtual disk object) names to the name of the VM+ the logical position of the virtual disk (example: xvda, hdb, etc), related to the VM. That way, it will become very easy to identify the disks in case of such annoying micro-catastrophy (micro because no data is lost, just where it belongs…).

The script can be called manually, and since we’re lazy people, and we will forget to handle it manually every said interval, and will accumulate virtual machines with “Template of XYZ” virtual disks, it can be called from cron. When called manually, it asks the user to proceed by pressing ‘Enter’. If called from cron, it just runs.


# This script will reset the names of the virtual disks used for each VM to a standard name, based on the VM name
# and the disk position
# It is meant to solve problems where due to 'forget storage' operations or the likes
# virtual disk associations disappear, and you face many disks having the same name
# Written by Ez-Aton:

if [ -t 1 ]
        echo "This script will reset *all* VM disks to a name constructed of the VM and the disk name (xvda, hdb, etc)"
        echo "This operation is not reversible, however, it can be called repeatedly"
        echo "If you want this script to skip a said virtual disk, make sure its name includes the name of the VM"
        echo "For example 'vm1 the real important data disk' for a disk used by vm1."
        echo "Note that the name is case sensitive, and it is very important that to match the name using upper/lower case letters as needed"
        echo "To abort, press Ctrl+C"
        echo "To proceed, press Enter"
        read abc

VM_LIST=`xe vm-list is-control-domain=false --minimal | tr , ' '`

for i in $VM_LIST
        # Resetting several parameters, so we have a clean start
        # We iterate through all existing VMs, to get both their names, and their disks
        VM_NAME="`xe vm-param-get uuid=$i param-name=name-label`"
        if [ -z "$VM_NAME" ]
                # We have a problem with empty VM names, so we will use the VMs uuid
        VBD_LIST=`xe vbd-list vm-uuid=$i --minimal | tr , ' '`
        for j in $VBD_LIST
                # Resetting several parameters, so we have a clean start
                # We iterate through all existing VBDs to reset the VDI nane
                VDI_UUID=`xe vbd-param-get uuid=$j param-name=vdi-uuid`
                if [ "$VDI_UUID" == "" ]
                        # This is a virtual CDROM
                DEV_NAME=`xe vbd-param-get uuid=$j param-name=device`
                VDI_NAME=`xe vbd-param-get uuid=$j param-name=vdi-name-label`

                # Test if the name was reset in the past or manually
                TGT_NAME="$VM_NAME $DEV_NAME"
                if [[ "$TGT_NAME" = "$VDI_NAME" ]]
                        # There is nothing to do
                        echo "Name already includes VM name, so nothing to do"
                        # Here we reset the VDI name
                        echo xe vdi-param-set uuid=$VDI_UUID name-label="$TGT_NAME"
                        xe vdi-param-set uuid=$VDI_UUID name-label="$TGT_NAME"