When we find ourselves in a situation of servers in production, it is advisable from time to time to perform a complete backup of the machine on certain specific servers, or we simply want to move said machine to another system but we cannot do it in a traditional way. Next we are going to see a technique in which it is not necessary to turn off the virtual machine, and continue providing service without noticing excessive deterioration of the service, or its crash.

First, we generate a volume in the LVM within the

# lvcreate -n lvBackup --size 245g VolGroup00 # mkfs.ext3 -m0 /dev/VolGroup00/lvBackup # mount /dev/VolGroup00/lvBackup /mnt/vm/

We assume that our virtual machine has a main disk (MachineName), on which the system is installed (MachineNameData), and an additional one on which, for example, the data is. Now within each virtual machine from which we want to obtain the copy we will execute the following actions

We create a SnapShot of the machine to be copied, in this way we will get a snapshot of the current state.

# lvcreate -L 10G -s -n SnapNombreDeLaMaquina /dev/VolGroup00/lvNombreDeLaMaquina # lvcreate -L 10G -s -n SnapNombreDeLaMaquinaData /dev/VolGroup00/lvNombreDeLaMaquinaData

We copy the snapshot to an image file.

# dd if=/dev/VolGroup00/SnapNombreDeLaMaquina of=/mnt/vm/NombreDeLaMaquina.img # dd if=/dev/VolGroup00/SnapNombreDeLaMaquinaData of=/mnt/vm/NombreDeLaMaquinaData.img

We delete the snapshot, since from this moment on it will not be necessary, and it is better to leave the systems as clean as possible # lvremove /dev/VolGroup00/SnapNombreDeLaMaquina # lvremove /dev/VolGroup00/SnapNombreDeLaMaquinaData

We copy the configuration of the virtual machine, in case we intend to take it to other servers, remember to modify it if you are going to clone this machine, since, for example, the virtual machine identifiers and the MACs of the network cards must be unique.

# cp /etc/xen/NombreDeLaMaquina /mnt/vm/

We pack to send to another machine, and we have everything ready.

# tar czfv NombreDeLaMaquina.tar.gz /mnt/vm/NombreDeLaMaquina*

We only have to carry out the task for which we have destined this new copy.