vacosta94 / VirtBKP

Tool to create oVirt VM' disk backups
http://blog.infratic.com
GNU General Public License v3.0
24 stars 10 forks source link

Create backup of oVirt / RHEV’s VMs

[TOC]

Introduction

I've been working with oVirt since version 3.5 as main virtualization platform, from day one i were looking for a tool to create VM backups based on snapshot as many solutions does with VMWARE, after some research i didn't find a tool that fulfilled my requirements so i decided to create one using oVirt python API.

Requirements

How does it work?

This script should run on bkpvm and it connect to oVirt API to do:

After finish it creates a qcow2 file for each VM's disk

Instalation

Prerequisites

Install required repositories on bkpvm:

yum install -y epel-release
yum install -y http://resources.ovirt.org/pub/yum-repo/ovirt-release43.rpm 

Install required packages from repositories configured:

yum install -y qemu-img python-ovirt-engine-sdk4 python-requests git ovirt-guest-agent

Download

cd /opt
git clone https://github.com/vacosta94/VirtBKP.git

We need to get our oVirt's CA in order to establish secure connections to oVirt API

cd /opt/VirtBKP
curl --insecure "https://ovirt.infratic.com/ovirt-engine/services/pki-resource?resource=ca-certificate&format=X509-PEM-CA" -o ca.crt

Usage

Configure

There is a configuration file default.conf inside VirtBKP folder, that file have all the parameters required by the tool. Should modify this file according your environment as follow:

vim /opt/VirtBKP/default.conf
[bkp]
url     = https://ovirt.example.com/ovirt-engine/api
user        = admin@internal
password    = password
ca_file     = ca.crt
bkpvm       = bkpvm
bckdir      = /mnt/

[restore]
url     = https://ovirt.example.com/ovirt-engine/api
user        = admin@internal
password    = password
ca_file     = ca.crt
storage     = gfs_pool0
proxy       = ovirt.example.com
proxyport   = 54323

Create backup

In order to create backups of virtual machines you should use the syntax bellow:

/opt/VirtBKP/backup_vm.py <configuration_file> <vm_name>

Example:

/opt/VirtBKP/backup_vm.py /opt/VirtBKP/default.conf webserver

Restore backup

In order to restore an existing backup you should use the syntax bellow:

/opt/VirtBKP/upload_disk.py <configuration_file> <qcow2_file>

Example

/opt/VirtBKP/upload_disk.py /mnt/webserver_2017-04-28-00h.qcow2