Difference between revisions of "stoney conductor: VM Backup"

From stoney cloud
Jump to: navigation, search
[unchecked revision][unchecked revision]
(Retain)
(Snapshot)
Line 11: Line 11:
 
== Snapshot ==
 
== Snapshot ==
 
# Create a snapshot with state:
 
# Create a snapshot with state:
#* Save the state of VM <code>vm-001</code> to the file <code>vm-001.state</code>: <syntaxhighlight lang="bash">virsh save vm-001 vm-001.stat</syntaxhighlight>
+
#* Save the state of VM <code>vm-001</code> to the file <code>vm-001.state</code> (This file can either be created on a RAM-Disk or directly in the retain location. This example however saves the file to a RAM-Disk): <syntaxhighlight lang="bash">virsh save vm-001 /path/to/ram-disk/vm-001.stat</syntaxhighlight>
#* After this command, the VMs CPU and memory state is represented by the file <code>vm-001.state</code> and the VM <code>vm-001</code> is shut down.
+
#* After this command, the VMs CPU and memory state is represented by the file <code>/path/to/ram-disk/vm-001.state</code> and the VM <code>vm-001</code> is shut down.
 
# Move the disk image <code>/path/to/images/vm-001.qcow2</code> to the retain location: <syntaxhighlight lang="bash">mv /path/to/images/vm-001.qcow2 /path/to/retain/vm-001.qcow2</syntaxhighlight>
 
# Move the disk image <code>/path/to/images/vm-001.qcow2</code> to the retain location: <syntaxhighlight lang="bash">mv /path/to/images/vm-001.qcow2 /path/to/retain/vm-001.qcow2</syntaxhighlight>
 
#* '''Please note:''' The retain directory (<code>/path/to/retain/</code>) '''has to be''' on the same partition as the images directory (<code>/path/to/images/</code>). This will make the <code>mv</code> operation very fast (only renaming the inode). So the downtime (remember the VM <code>vm-001</code> is shut down) is as short as possible.  
 
#* '''Please note:''' The retain directory (<code>/path/to/retain/</code>) '''has to be''' on the same partition as the images directory (<code>/path/to/images/</code>). This will make the <code>mv</code> operation very fast (only renaming the inode). So the downtime (remember the VM <code>vm-001</code> is shut down) is as short as possible.  
# Create the new (empty) disk image with the old as backing store file: <code>qemu-img create -f qcow2 -b my-vm-backup.qcow2 my-vm.qcow2</code>
+
# Create the new (empty) disk image with the old as backing store file: <syntaxhighlight lang="bash">qemu-img create -f qcow2 -b /path/to/retain/vm-001.qcow2 /path/to/images/vm-001.qcow2</syntaxhighlight>
#* Set correct ownership and permission to the newly created image:
+
# Set correct ownership and permission to the newly created image:
#** <code>chown root:vm-storage my-vm.qcow2</code>.
+
#* <syntaxhighlight lang="bash">chown root:vm-storage /path/to/images/vm-001.qcow2</syntaxhighlight>
#** <code>chmod 660 my-vm.qcow2</code>.
+
#* <syntaxhighlight lang="bash">chmod 660 /path/to/images/vm-001.qcow2</syntaxhighlight>
#* Restore the VMs state: <code>virsh restore my-vm.state</code>.
+
# Restore the VMs <code>vm-001</code> from its saved state: <syntaxhighlight lang="bash">virsh restore /path/to/ram-disk/vm-001.state</syntaxhighlight>
 +
#* '''Please note:''' After this operation we have a consistent backup for the VM <code>vm-001</code>:
 +
#** The file <code>/path/to/ram-disk/vm-001.state</code> contains the CPU and memory state of VM <code>vm-001</code> at time T<sub>1</sub>
 +
#** The file <code>/path/to/retain/vm-001.qcow2</code> contains the disk state of VM <code>vm-001</code> at time T<sub>1</sub>
  
 
== Merge ==
 
== Merge ==

Revision as of 14:59, 22 October 2013

Overview

This page describes how the VMs and VM-Templates are backed-up inside the stoney cloud.

Basic idea

The main idea to backup a VM or a VM-Template is, to divide the task into three subtasks:

  • Snapshot: Save the machines state (CPU, Memory and Disk)
  • Merge: Merge the Disk-Snapshot with the live-image
  • Retain: Export the snapshot files

A more detailed and technical description for these three sub-processes can be found in the following sub-chapters.

Snapshot

  1. Create a snapshot with state:
    • Save the state of VM vm-001 to the file vm-001.state (This file can either be created on a RAM-Disk or directly in the retain location. This example however saves the file to a RAM-Disk):
      virsh save vm-001 /path/to/ram-disk/vm-001.stat
    • After this command, the VMs CPU and memory state is represented by the file /path/to/ram-disk/vm-001.state and the VM vm-001 is shut down.
  2. Move the disk image /path/to/images/vm-001.qcow2 to the retain location:
    mv /path/to/images/vm-001.qcow2 /path/to/retain/vm-001.qcow2
    • Please note: The retain directory (/path/to/retain/) has to be on the same partition as the images directory (/path/to/images/). This will make the mv operation very fast (only renaming the inode). So the downtime (remember the VM vm-001 is shut down) is as short as possible.
  3. Create the new (empty) disk image with the old as backing store file:
    qemu-img create -f qcow2 -b /path/to/retain/vm-001.qcow2 /path/to/images/vm-001.qcow2
  4. Set correct ownership and permission to the newly created image:
    • chown root:vm-storage /path/to/images/vm-001.qcow2
    • chmod 660 /path/to/images/vm-001.qcow2
  5. Restore the VMs vm-001 from its saved state:
    virsh restore /path/to/ram-disk/vm-001.state
    • Please note: After this operation we have a consistent backup for the VM vm-001:
      • The file /path/to/ram-disk/vm-001.state contains the CPU and memory state of VM vm-001 at time T1
      • The file /path/to/retain/vm-001.qcow2 contains the disk state of VM vm-001 at time T1

Merge

  1. Merge the disk images my-vm.qcow2 and my-vm-snap.qcow2 to a single image: virsh qemu-monitor-command my-vm --hmp "block_stream drive-virtio-disk0".

Retain

  1. Move the files to the backup location:
    • Move the old disk image to the backup location and add the date as suffix to not overwrite older backups: mv my-vm-backup.qcow2 /path/to/backup/my-vm-backup.qcow2.date
    • Move the state file to the backup location and add the date as suffix to not overwrite older backups: mv my-vm.state /path/to/backup/my-vm.state.date

State of the art

Next steps