ManageIQ Database Backup and Restore: Complete Guide

ManageIQ Database Backup and Restore: Complete Guide

Learn how to backup and restore ManageIQ PostgreSQL databases for disaster recovery and data migration. Step-by-step guide with best practices and troubleshooting.

Saurabh
August 30, 2018
8 min read

Hybrid-Cloud-Automation-Using-Ansible-ManageIQ

Nowadays, Automation is the mother of all the inventions, that give rise to all the new technologies. Most of the latest technologies are the reason for automation. This project is one of our tries to automate hybrid cloud using ManageIQ and Ansible.

A hybrid cloud is the one with the combination of both i.e. private as well as public cloud with the specified specifications.

ManageIQ is an open-source cloud management platform by Red Hat. It is written in Ruby with RoR (Ruby on Rails) as the platform.

Ansible is software that automates software provisioning, configuration management, and application deployment. Playbooks are Ansible’s configuration, deployment, and orchestration language.

Introduction to ManageIQ

  • ManageIQ is an Open Source Cloud management platform. The ManageIQ project founded by Red Hat In 2014 as a community project. It is written in Ruby with RoR (Ruby on Rails) as the platform.
  • For getting started get a ManageIQ instances from here

Installation

  • Using KVM/Qemu image

    • Download ManageIQ Image from manageiq/downloads choose QEmu/KVM

    • Install KVM and necessary packages

yum install qemu-kvm libvirt libvirt-python virt-install
  • Create ManageIQ VM using an existing image

    • Create VM using virt-install command
sudo virt-install --virt-type kvm  --import --name ManageIQ  --memory 12288 --vcpus 4 --cpu host  --disk manageiq-openstack-gaprindashvili-5.qc2,format=qcow2,bus=virtio  --network default,model=virtio   --os-type=linux --os-variant=centos7.0   --graphics spice
  • Launch VM using virsh
  • Login using ssh
ssh root@<ip_of_server>
    - user: _root_
    - password: _smartvm_

ManageIQ Appliance Console

Access the ManageIQ Virtual Appliance console to manage your system:

# Run appliance console
appliance_console
# or use shorthand
ap

System Information Display

The console shows important system details:

  • Network Configuration: IP addresses, gateways, DNS settings
  • System Information: Hostname, MAC address, timezone
  • Database Status: Local database server and region information
  • Service Status: ManageIQ server and database status
  • Authentication: External auth configuration
  • Version Information: Current ManageIQ version

Advanced Configuration Options

Press Enter to access advanced settings:

  • Configure Network Settings
  • Set Timezone and Date/Time
  • Restore Database From Backup
  • Configure Database and Replication
  • Manage Authentication (LDAP/SAML)
  • Generate Custom Encryption Keys
  • Control EVM Server Processes
  • System Management (restart/shutdown)

Database Backup and Restore Overview

ManageIQ uses PostgreSQL as its database engine. All backup and restore operations follow PostgreSQL standards and procedures.

Key Database Information

  • Database Name: vmdb_production
  • Default User: postgres
  • Service Name: evmserverd (ManageIQ application service)
  • Location: /var/lib/postgresql/data/

Important: Always stop the ManageIQ service before performing database operations to ensure data consistency.

Database Backup Procedure

Follow these steps to create a comprehensive database backup:

Step 1: Stop ManageIQ Services

# Stop the ManageIQ application service
sudo systemctl stop evmserverd

# Verify service is stopped
sudo systemctl status evmserverd

Note: Stopping services ensures data consistency during backup, though it's not strictly required for read-only backup operations.

Step 2: Create Database Dump

Use PostgreSQL's pg_dump utility to create a compressed backup:

# Create compressed dump (recommended)
pg_dump -Fc vmdb_production > production.dump

# Alternative: Create plain SQL dump
pg_dump vmdb_production > production.sql

# Create dump with specific options
pg_dump -Fc -v --host=localhost --username=postgres vmdb_production > production_$(date +%Y%m%d_%H%M%S).dump

Backup Options Explained

  • -Fc: Creates custom-format dump (compressed and flexible)
  • -v: Verbose output for monitoring progress
  • --host: Specify database host (default: localhost)
  • --username: Specify database user (default: postgres)

Step 3: Verify Backup Integrity

# Check backup file size and permissions
ls -lh production.dump

# Verify backup can be read
pg_restore --list production.dump | head -10

Step 4: Transfer Backup (if needed)

Copy the backup to another ManageIQ instance:

# Using SCP for secure transfer
scp production.dump root@target-server-ip:/root/

# Using rsync for large files
rsync -avz production.dump root@target-server-ip:/root/

# Verify transfer
ssh root@target-server-ip "ls -lh /root/production.dump"

Database Restore Procedure

Follow these steps to restore a ManageIQ database from backup:

Step 1: Prepare Target System

Ensure the backup file is available on the target system:

# Verify backup file exists
ls -lh /root/production.dump

# Check available disk space
df -h /var/lib/postgresql/

Step 2: Stop ManageIQ Services

# Stop ManageIQ application service
sudo systemctl stop evmserverd

# Verify service is stopped
sudo systemctl status evmserverd

Step 3: Database Recreation

Drop and recreate the target database:

# Drop existing database (⚠️ This deletes all current data)
dropdb vmdb_production

# Create new empty database
createdb vmdb_production

# Verify database creation
psql -l | grep vmdb_production

Step 4: Restore from Backup

# Restore from custom format dump
pg_restore -d vmdb_production /root/production.dump

# Alternative: Restore with verbose output
pg_restore -v -d vmdb_production /root/production.dump

# For SQL format backups
psql vmdb_production < /root/production.sql

Step 5: Fix Authentication Keys

Navigate to ManageIQ tools directory and fix authentication:

# Change to ManageIQ directory
cd /var/www/miq/vmdb

# Alternative shortcut
vmdb  # This command takes you to /var/www/miq/vmdb/

# Navigate to tools directory
cd tools

# Fix authentication keys
bundle exec fix_auth.rb --v2 --invalid bogus

Step 6: Start Services

# Start ManageIQ service
sudo systemctl start evmserverd

# Monitor startup process
sudo systemctl status evmserverd

# Check service logs
sudo journalctl -u evmserverd -f

Step 7: Verify Restoration

# Check database connectivity
psql vmdb_production -c "SELECT count(*) FROM users;"

# Verify ManageIQ web interface
curl -k https://localhost/api/ping

# Check application logs
tail -f /var/www/miq/vmdb/log/evm.log

Automated Backup Scripts

Daily Backup Script

Create an automated backup script for regular maintenance:

#!/bin/bash
# File: /usr/local/bin/manageiq-backup.sh

# Configuration
BACKUP_DIR="/var/backups/manageiq"
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="manageiq_backup_${DATE}.dump"
RETENTION_DAYS=30

# Create backup directory
mkdir -p $BACKUP_DIR

# Create database backup
echo "Starting ManageIQ database backup..."
pg_dump -Fc vmdb_production > "${BACKUP_DIR}/${BACKUP_FILE}"

# Verify backup
if [ $? -eq 0 ]; then
    echo "Backup completed successfully: ${BACKUP_FILE}"

    # Compress backup (optional)
    gzip "${BACKUP_DIR}/${BACKUP_FILE}"

    # Remove old backups
    find $BACKUP_DIR -name "*.dump.gz" -mtime +$RETENTION_DAYS -delete

    echo "Backup process completed"
else
    echo "Backup failed!"
    exit 1
fi

Schedule with Cron

# Add to crontab
crontab -e

# Daily backup at 2 AM
0 2 * * * /usr/local/bin/manageiq-backup.sh >> /var/log/manageiq-backup.log 2>&1

# Weekly backup at 1 AM on Sunday
0 1 * * 0 /usr/local/bin/manageiq-backup.sh >> /var/log/manageiq-backup.log 2>&1

Best Practices

1. Backup Strategy

  • Frequency: Daily backups for production environments
  • Retention: Keep 30 days of daily backups, 12 weeks of weekly backups
  • Location: Store backups on separate storage systems
  • Testing: Regularly test restore procedures

2. Security Considerations

# Set proper permissions for backup files
chmod 600 /var/backups/manageiq/*.dump
chown postgres:postgres /var/backups/manageiq/

# Encrypt sensitive backups
gpg --symmetric --cipher-algo AES256 production.dump

3. Performance Optimization

# For large databases, use parallel backup
pg_dump -Fc -j 4 vmdb_production > production.dump

# Monitor backup progress
pg_dump -Fc -v --progress vmdb_production > production.dump

4. Disaster Recovery Planning

  • Documentation: Maintain updated recovery procedures
  • Testing: Regular disaster recovery drills
  • Monitoring: Set up alerts for backup failures
  • Offsite Storage: Replicate backups to remote locations

Troubleshooting Common Issues

Backup Issues

Problem: pg_dump: error: connection to database failed

# Check PostgreSQL service
sudo systemctl status postgresql

# Check database connectivity
psql -c "SELECT version();"

# Verify database exists
psql -l | grep vmdb_production

Problem: Insufficient disk space

# Check available space
df -h /var/lib/postgresql/

# Clean up old log files
find /var/www/miq/vmdb/log/ -name "*.log.*" -mtime +7 -delete

# Compress old backups
gzip /var/backups/manageiq/*.dump

Restore Issues

Problem: Authentication errors after restore

# Re-run authentication fix
cd /var/www/miq/vmdb/tools
bundle exec fix_auth.rb --v2 --invalid bogus

# Clear sessions
redis-cli FLUSHDB

Problem: Service fails to start

# Check detailed logs
journalctl -u evmserverd -n 50

# Verify database connectivity
sudo -u postgres psql vmdb_production -c "SELECT 1;"

# Check file permissions
ls -la /var/www/miq/vmdb/

Advanced Topics

Database Replication

For high availability, consider setting up database replication:

# On primary server
echo "wal_level = replica" >> /var/lib/postgresql/data/postgresql.conf
echo "max_wal_senders = 3" >> /var/lib/postgresql/data/postgresql.conf

# Restart PostgreSQL
sudo systemctl restart postgresql

Cross-Platform Migration

When migrating between different systems:

# Create platform-independent backup
pg_dump --no-owner --no-privileges vmdb_production > migration.sql

# On target system
psql vmdb_production < migration.sql

Conclusion

Proper database backup and restore procedures are essential for ManageIQ operations. This guide provides:

  • Comprehensive backup strategies for data protection
  • Step-by-step restore procedures for disaster recovery
  • Automation scripts for regular maintenance
  • Best practices for production environments
  • Troubleshooting guides for common issues

Regular testing of these procedures ensures your ManageIQ environment can quickly recover from any data loss scenario. Remember to always test restores in a non-production environment first and maintain proper documentation of your specific configuration.

Key Takeaways

  1. Stop services before major database operations
  2. Use compressed backups (-Fc) for efficiency
  3. Automate regular backups with cron jobs
  4. Test restore procedures regularly
  5. Monitor backup success and storage usage
  6. Maintain offsite copies for disaster recovery

With these procedures in place, your ManageIQ hybrid cloud automation platform will be well-protected against data loss and ready for rapid recovery when needed.

Written by

Saurabh

Related Articles

Enjoyed this article?

Check out more of my writing on frontend development and web technologies