Virtkick Docs

Documentation and information to Virtkick your business

How to Perform an Offline/Incremental Backup on your KVM Virtual Machines

Offline backups are advantageous in that they are incremental - each backup depends on previous backups so the overall footprint of sucha backup is smaller than a full backup. There are drawbacks however, your machines must be powered down for such a backup to work. This guide will walk you through the process of creating an incremental offline backup on your KVM virtual machines.

1. Create the backup

First you will want to make sure you are using the virtkick user to maintain the permissions on your disk images. You can do this by running the following command as the root user:

su -u virtkick

Now that you are using the virtkick user, you can begin the process of creating a backup. First, run the following command to power down your machine:

virsh -c qemu:///system shutdown NAME_OF_YOUR_MACHINE

Substitute NAME_OF_YOUR_MACHINE with the name of the machine you wish to backup.

Next, create a snapshot using the following command:

virsh -c qemu:///system snapshot-create-as NAME_OF_YOUR_MACHINE BACKUP_NAME "BACKUP_DESCRIPTION" --disk-only --atomic

Substitute NAME_OF_YOUR_MACHINE with the name of this machine, BACKUP_NAME with any name that is meaningful to you and BACKUP_DESCRIPTION with a decription that will help you remember what this backup is for.

You may find that the permissions on your disk are improper, to correct this run the following command as the root user:

chown virtkick:kvm /home/virtkick/hdd/NAME_OF_YOUR_MACHINE.*

Now that the permissions are in order you can start your machine once again using the following command:

virsh -c qemu:///system start NAME_OF_YOUR_MACHINE

You have successfully created an incremental backup of your virtual machine!

2. Storing backups

Incremental backups depend on eachother, that being said you must store all backups in the backing chain for any subsequent backup to function. For example, if you have the following backups:

backup1.qcow2
backup2.qcow2
backup3.qcow2

For backup3.qcow2 to work, you must retain both backup1 and backup2. However, backup2 will work without backup3.

That said, if you choose to move your backups to another machine (this is recommended), be sure to bring all the incremental backups along!

You can view the full backing chain by executing the following command:

# qemu-img info --backing-chain /home/virtkick/hdd/1_testbackup2_fb7715a2-1607-40c8-bc33-d31b3cd20489.backup3
image: /home/virtkick/hdd/1_testbackup2_fb7715a2-1607-40c8-bc33-d31b3cd20489.backup3
file format: qcow2
virtual size: 21G (22548578304 bytes)
disk size: 422M
cluster_size: 65536
backing file: /home/virtkick/hdd/1_testbackup2_fb7715a2-1607-40c8-bc33-d31b3cd20489.backup2
backing file format: qcow2
Format specific information:
    compat: 1.1
    lazy refcounts: false

image: /home/virtkick/hdd/1_testbackup2_fb7715a2-1607-40c8-bc33-d31b3cd20489.backup2
file format: qcow2
virtual size: 21G (22548578304 bytes)
disk size: 3.3M
cluster_size: 65536
backing file: /home/virtkick/hdd/1_testbackup2_fb7715a2-1607-40c8-bc33-d31b3cd20489.backup1
backing file format: qcow2
Format specific information:
    compat: 1.1
    lazy refcounts: false

image: /home/virtkick/hdd/1_testbackup2_fb7715a2-1607-40c8-bc33-d31b3cd20489.backup1
file format: qcow2
virtual size: 21G (22548578304 bytes)
disk size: 196K
cluster_size: 65536
backing file: /home/virtkick/hdd/1_testbackup2_fb7715a2-1607-40c8-bc33-d31b3cd20489.qcow2
backing file format: qcow2
Format specific information:
    compat: 1.1
    lazy refcounts: false

image: /home/virtkick/hdd/1_testbackup2_fb7715a2-1607-40c8-bc33-d31b3cd20489.qcow2
file format: qcow2
virtual size: 21G (22548578304 bytes)
disk size: 1.1G
cluster_size: 65536
backing file: /home/virtkick/template/ubuntu-1604-lts_template_27042016-2.qcow2
Format specific information:
    compat: 1.1
    lazy refcounts: false

image: /home/virtkick/template/ubuntu-1604-lts_template_27042016-2.qcow2
file format: qcow2
virtual size: 100T (109951162777600 bytes)
disk size: 1.7G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false

If you have many incremental backups that are not named in an incrementing fashion this command can help you identify how each backup depends on other backups.

Need to know how to restore an incremental backup? Take a look at our guide

Have any problems? Let us know - we are happy to help!

Back to the list ยป

avatar
Joe Pettit
Developer @ Virtkick
comments powered by Disqus