Backups
Backing Up and Restoring oVirt
Backing up oVirt - Overview
While taking complete backups of the machine on which oVirt is installed is recommended whenever changing the configuration of that machine, a utility is provided for backing up only the key files related to oVirt. This utility - the engine-backup
command - can be used to rapidly back up the engine database and configuration files into a single file that can be easily stored.
Syntax for the engine-backup Command
The engine-backup
command works in one of two basic modes:
# engine-backup --mode=backup
# engine-backup --mode=restore
These two modes are further extended by a set of parameters that allow you to specify the scope of the backup and different credentials for the engine database. A full list of parameters and their function is as follows:
Basic Options
-
Specifies whether the command will perform a backup operation or a restore operation. Two options are available -
backup
, andrestore
. This is a required parameter. - Specifies the path and name of a file into which backups are to be taken in backup mode, and the path and name of a file from which to read backup data in restore mode. This is a required parameter in both backup mode and restore mode.
- Specifies the path and name of a file into which logs of the backup or restore operation are to be written. This parameter is required in both backup mode and restore mode.
-
Specifies the scope of the backup or restore operation. There are two options -
all
, which backs up both the engine database and configuration data, anddb
, which backs up only the engine database.
--mode
--file
--log
--scope
Database Options
The following options are only available when using the engine-backup
command in restore
mode.
- Allows you to specify alternate credentials for restoring the engine database using credentials other than those stored in the backup itself. Specifying this parameter allows you to add the following parameters.
- Specifies the IP address or fully qualified domain name of the host on which the database resides. This is a required parameter.
- Specifies the port by which a connection to the database will be made.
- Specifies the name of the user by which a connection to the database will be made. This is a required parameter.
-
Specifies a file containing the password by which a connection to the database will be made. Either this parameter or the
--db-password
parameter must be specified. -
Specifies the plain text password by which a connection to the database will be made. Either this parameter or the
--db-passfile
parameter must be specified. - Specifies the name of the database to which the database will be restored. This is a required parameter.
- Specifies that the connection with the database is to be secured.
- Specifies that the connection with the host is to be validated.
--change-db-credentials
--db-host
--db-port
--db-user
--db-passfile
--db-password
--db-name
--db-secured
--db-secured-validation
Help
- Provides an overview of the available modes, parameters, sample usage, how to create a new database and configure the firewall in conjunction with backing up and restoring oVirt.
--help
Creating a Backup with the engine-backup Command
Summary
The process for creating a backup of the engine database and the configuration data for oVirt using the engine-backup
command is straightforward and can be performed while oVirt is active.
Procedure 12.1. Backing up oVirt
- Log on to the machine running oVirt.
- Run the following command to create a full backup:
Example 12.1. Creating a Full Backup
# engine-backup --scope=all --mode=backup --log=[file name] --file=[file name]
Alternatively, run the following command to back up only the engine database:
Example 12.2. Creating an engine database Backup
# engine-backup --scope=db --mode=backup --log=[file name] --file=[file name]
Result
A tar
file containing a backup of the engine database, or the engine database and the configuration data for oVirt, is created using the path and file name provided.
Restoring a Backup with the engine-backup Command
While the process for restoring a backup using the engine-backup
command is straightforward, it involves several additional steps in comparison to that for creating a backup depending on the destination to which the backup is to be restored. For example, the engine-backup
command can be used to restore backups to fresh installations of oVirt, on top of existing installations of oVirt, and using local or remote databases.
version
file located in the root directory of the unpacked files.
Restoring a Backup to a Fresh Installation
Summary
The engine-backup
command can be used to restore a backup to a fresh installation of oVirt. The following procedure must be performed on a machine on which the base operating system has been installed and the required packages for oVirt have been installed, but the engine-setup
command has not yet been run. This procedure assumes that the backup file can be accessed from the machine on which the backup is to be restored.
engine-backup
command does not handle the actual creation of the engine database or the initial configuration of the
postgresql
service. Therefore, these tasks must be performed manually as outlined below when restoring a backup to a fresh installation.
Procedure 12.2. Restoring a Backup to a Fresh Installation
- Log on to the machine on which oVirt is installed.
- Manually create an empty database to which the database in the backup can be restored and configure the
postgresql
service:- Run the following commands to initialize the
postgresql
database, start thepostgresql
service and ensure this service starts on boot:
# service postgresql initdb # service postgresql start # chkconfig postgresql on
- Run the following commands to enter the postgresql command line:
# su postgres $ psql
- Run the following command to create a new user:
postgres=# create role [user name] with login encrypted password '[password]';
- Run the following command to create the new database:
postgres=# create database [database name] owner [user name] template template0 encoding 'UTF8' lc_collate 'en_US.UTF-8' lc_ctype 'en_US.UTF-8';
- Edit the
/var/lib/pgsql/data/pg_hba.conf
file as follows:- For local databases, replace the existing directives in the section starting with
Local
at the bottom of the file with the following directives:
host [database name] [user name] 0.0.0.0/0 md5 host [database name] [user name] ::0/0 md5
- For remote databases, add the following line immediately underneath the line starting with
Local
at the bottom of the file, replacingX.X.X.X with the IP address of oVirt:
host [database name] [user name] X.X.X.X/32 md5
- For local databases, replace the existing directives in the section starting with
- Run the following command to restart the
postgresql
service:
# service postgresql restart
- Run the following commands to initialize the
- Restore the backup using the
engine-backup
command with the--change-db-credentials
parameter to pass the credentials of the new database:
# engine-backup --mode=restore --file=[file name] --log=[file name] --change-db-credentials --db-host=[database location] --db-name=[database name] --db-user=[user name] --db-password=[password]
If successful, the following output displays:
You should now run engine-setup. Done.
- Run the following command and follow the prompts to configure oVirt:
# engine-setup
Result
The engine database and configuration files for oVirt have been restored to the version in the backup.
Restoring a Backup to Overwrite an Existing Installation
Summary
The engine-backup
command can restore a backup to a machine on which oVirt has already been installed and set up. This is useful when you have taken a backup up of an installation, performed changes on that installation and then want to restore the installation from the backup.
engine-cleanup
command to clean up the existing installation before using the
engine-backup
command. Because the
engine-backup
command only cleans the engine database, and does not drop the database or delete the user that owns that database, you do not need to create a new database or specify the database credentials because the user and database already exist.
Procedure 12.3. Restoring a Backup to Overwrite an Existing Installation
- Log on to the machine on which oVirt is installed.
- Run the following command and follow the prompts to remove the configuration files for and clean the database associated with oVirt:
# engine-cleanup
- Restore the backup using the
engine-backup
command:
# engine-backup --mode=restore --file=[file name] --log=[file name]
If successful, the following output displays:
You should now run engine-setup. Done.
- Run the following command and follow the prompts to re-configure the firewall and ensure the
ovirt-engine
service is correctly configured:
# engine-setup
Result
The engine database and configuration files for oVirt have been restored to the version in the backup.
Restoring a Backup with Different Credentials
Summary
The engine-backup
command can restore a backup to a machine on which oVirt has already been installed and set up, but the credentials of the database in the backup are different to those of the database on the machine on which the backup is to be restored. This is useful when you have taken a backup of an installation and want to restore the installation from the backup to a different system.
engine-cleanup
command to clean up the existing installation before using the
engine-backup
command. Because the
engine-backup
command only cleans the engine database, and does not drop the database or delete the user that owns that database, you do not need to create a new database or specify the database credentials because the user and database already exist. However, if the credentials for the owner of the engine database are not known, you must change them before you can restore the backup.
Procedure 12.4. Restoring a Backup with Different Credentials
- Log on to the machine on which oVirt is installed.
- Run the following command and follow the prompts to remove the configuration files for and clean the database associated with oVirt:
# engine-cleanup
- Change the password for the owner of the engine database if the credentials of that user are not known:
- Run the following commands to enter the postgresql command line:
# su postgres $ psql
- Run the following command to change the password of the user that owns the engine database:
postgres=# alter role [user name] encrypted password '[new password]';
- Run the following commands to enter the postgresql command line:
- Restore the backup using the
engine-backup
command with the--change-db-credentials
parameter:
# engine-backup --mode=restore --file=[file name] --log=[file name] --change-db-credentials --db-host=[database location] --db-name=[database name] --db-user=[user name] --db-password=[password]
If successful, the following output displays:
You should now run engine-setup. Done.
- Run the following command and follow the prompts to re-configure the firewall and ensure the
ovirt-engine
service is correctly configured:
# engine-setup
Result
The engine database and configuration files for oVirt have been restored to the version in the backup using the supplied credentials, and oVirt has been configured to use the new database.
Manually Backing Up and Restoring oVirt
Backing Up the Engine Database Using the backup.sh Script
Summary
oVirt includes a script to automate database backups. Using this script on your Manager server, you can protect yourself against potential data loss.
Procedure 12.5. Backing up the engine database using the backup.sh script
- Change into the
/usr/share/ovirt-engine/dbscripts/
directory. - Invoke
backup.sh
with the-h
parameter to see the available options.
Usage: backup.sh [-h] [-s SERVERNAME] [-p PORT] [-d DATABASE] [-l DIR] -u USERNAME [-v] -s SERVERNAME - The database servername for the database (def. localhost) -p PORT - The database port for the database (def. 5432) -d DATABASE - The database name (def. engine) -u USERNAME - The username for the database. -v - Turn on verbosity (WARNING: lots of output) -l DIR - Backup file directory. -h - This help text. for more options please run pg_dump --help
- Invoke the
backup.sh
command again with parameters appropriate for your environment. If you are backing up the localengine
database, the-s, -p,
and-d
parameters are not necessary. Use the-l
to specify the backup directory. This will cause a.sql
file to be created in the directory you give. - Copy the
.sql
you just created from the directory you specified to a safe remote location.
Result
You have used the backup.sh script to backup your engine
database.
Backing Up Manager Configuration Files
oVirt stores customized configurations as configuration files. These configuration files contain specific configuration details regarding a given environment, and must be backed up.
Table 12.1. Files and directories that must be backed up
Location | Overview |
---|---|
/etc/ovirt-engine/ | A directory containing oVirt configuration files such as engine-config.conf . |
/etc/yum/pluginconf.d/versionlock.list | A file containing version information about currently installed oVirt components. |
/etc/pki/ovirt-engine/ | Security certificates provided by oVirt to clients. |
/usr/share/jasperreports-server-pro/buildomatic/ | A directory containing files required to build the oVirt reports server. |
/var/lib/ovirt-engine/backups/ | A directory containing backup files. |
/var/tmp/ovirt-engine/deployments/ | A directory containing information on deployments. |
/usr/share/ovirt-engine-reports/ | A directory containing configuration files related to reports. In particular, this directory contains sub-directories in which the credentials of the reports user are stored in a plain text, human-readable format. |
/root/.rnd | A random seed file used to generate secure certificates. |
/var/log/ovirt-engine/setup/ | A directory containing logs that contain the answers you gave to the setup configuration questions. You must use these files when restoring oVirt because they supply the same information that was used to initially configure oVirt. |
When you have backed up all the above files and directories, you can recover oVirt to a working state after an unforeseen event.
Restoring the Engine Database Using the restore.sh Script
Summary
oVirt includes a script to automate database restoration. Using this script on your Manager server, you can recover from database corruption.
Procedure 12.6. Restoring the Engine Database Using the restore.sh Script
- Change into the
/usr/share/ovirt-engine/dbscripts/
directory. - Invoke
restore.sh
with the-h
parameter to see the available options.
Usage: restore.sh [-h] [-s SERVERNAME] [-p PORT] -u USERNAME -d DATABASE -f FILE [-r] -s SERVERNAME - The database servername for the database (def. localhost) -p PORT - The database port for the database (def. 5432) -u USERNAME - The username for the database. -d DATABASE - The database name -f File - Backup file name to restore from. -r - Remove existing database with same name -h - This help text. for more options please run pg_restore --help
- Invoke the
restore.sh
command again with parameters appropriate for your environment. If you are restoring the localengine
database, the-s
and-p
parameters are not necessary. Use the-d
to specify name of the database you are creating. oVirt expects a primary database namedengine
. Use the-f
to specify the.sql
file you are restoring from.
Result
You have used the restore.sh script to restore your engine
database.
Restoring oVirt Configuration Files
Summary
Restore a backed up copy of configuration files to oVirt.
Procedure 12.7. Restoring oVirt Configuration Files
-
Stop the engine service:
# service ovirt-engine stop
- Completely remove all previous installations of oVirt:
# yum remove ovirt-engine
- Remove
/etc/pki/ovirt-engine
:
# rm -rf /etc/pki/ovirt-engine
- Remove the main
ovirt-engine
directory:
# rm -rf /etc/ovirt-engine
- Install oVirt:
# yum install -y ovirt-engine
- Run
engine-setup
, giving the same answers as when you originally installedovirt-engine
:
# engine-setup
Your answers can be found in/var/log/engine-setup-SETUP-DATE.log
, which you backed up. - Stop the engine service, which was restarted as a part of the previous command:
# service ovirt-engine stop
- Restore the backed up configuration files to their original locations.
- Make sure the ownership of the
.truststore
file is correct:
# chown ovirt:ovirt /etc/pki/ovirt-engine/.truststore
- Make sure the permissions of the
ovirt-engine-notifier.conf
file is correct:
# chmod 640 /usr/share/ovirt-engine/services/ovirt-engine-notifier/ovirt-engine-notifier.conf
- Start the engine service:
# service ovirt-engine start
Result
You have restored a backed up copy of configuration files to oVirt.