Skip to content
Paolo Cozzi edited this page Mar 9, 2016 · 6 revisions

Using kvmBackup

Install kvmBackup

In order to work correctly, kvmBackup need that the following requirements are satisfied:

Then fetch kvmBackup from github:

$ git clone https://github.com/bioinformatics-ptp/kvmBackup.git

Then test that all modules work properly. Enter inside kvmBackup directory and try to get the --help. Is better to run kvmBackup as a privileged user:

$ ./kvmBackup.py --help
usage: kvmBackup.py [-h] -c CONFIG [--force]

Backup of KVM-qcow2 domains

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        The config file
  --force               Force backup (with rotation)

Configure kvmBackup

kvmBackup read a yaml file in order to know which Guest need backup. The file is structured in the following way (values between <> need to be configured by the user):

<hostname_1>:
  domains:
    <domain_name_1>:
      day_of_week: [<day of week>]
      rotate: <rotations>
    <domain_name_2>:
      day_of_week: [<day of week>]
      rotate: <rotations>
  backupdir: </path/to/backup/dir>

<hostname_2>:
  domains:
    <domain_name_3>:
      day_of_week: [<day of week>]
      rotate: <rotations>
  backupdir: </path/to/backup/dir>
  • <hostname>: this is the name of the host, you can get it by typing hostname -s. You can configure a single config file in which there are more host to backup, kvmBackup.py need to be launched independently in each of these host. Only the configuration with the <hostname> identical with Host hostname will be read.
  • domains: Under this level we need to specify all the Guest domain name we want to backup.
  • <domain_name>: this is the domain name we want to backup. You can get a list of available domain names by typing virsh list --all as a privileged user.
  • <day of week>: this is the day when backup will be done. You can specify one or more than one of these [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
  • <rotations>: how many backup wil be stored by rotations.
  • </path/to/backup/dir>: the path on the Host in which backup will be stored. A directory for each domain name will be created.

For example, a configuration could be written like this:

cloud1 :
    domains:
        DockerNode1:
            day_of_week: [Sun]
            rotate: 4
        DockerNode2:
            day_of_week: [Sun]
            rotate: 4
    backupdir: /mnt/cloud/kvm_backup/cloud1

At this moment, since the only rule for doing or not a backup is the day of week, it is better to run kvmBackup once a day.

Setting a cron job

You can configure a cron job, or edit the /etc/crontab of the Host as follows. Remember to run kvmBackup.py as a privileged user:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
  0  2  *  *  * root /mnt/cloud/Utilities/kvmBackup/kvmBackup.py --config /mnt/cloud/Utilities/kvmBackup/config.yml >> /var/log/kvmBackup 2>&1

Setting logrotation

If you write your log in a file, using a cron job for instance, you can do a log rotation by editing a file, for example /etc/logrotate.d/kvmBackup:

/var/log/kvmBackup {
  rotate 7
  weekly
  compress
  size=1M
  missingok
  delaycompress
  copytruncate
}

Then test and do the first logrotation:

$ logrotate -fv /etc/logrotate.d/kvmBackup

Running kvmBackup

You can launch kvmBackup.py specifying the config file in which are defined the Guest domain name to backup. Only the domain name specified in the same hostname namespace according to Host hostname are used for doing backup. Simply type:

$ kvmBackup.py --config </path/to/config.yaml>

To force backup even if the day of week is different from the corrent day, you can force backup lik this:

$ kvmBackup.py --config </path/to/config.yaml> --force

References