Copy DB between different MIQ


#1

Hi,
Is it possible to take a DB backup from MIQ version x and make a restore to a MIQ version x+1 and so on … ?

Thanks in advance


#2

Yes - I’ve done this before

Depending on the version difference though you may need to perform a rake db:migrate and/or reset the automate domains to grab the latest code


#3

I’m trying to setup a copy of our current MIQ node on a new server.
I’ve tried different ways but every time I got “MiqPassword::MiqPasswordError: can not decrypt v2_key encrypted string”

This is the procedure I follow:
On old appliance:
pg_dump --format custom --file ~/db_backup.cpgd vmdb_production

On new appliance:
systemctl stop evmserverd
dropdb vmdb_production
scp root@$OLDAPPLIANCEIPaddress:~/db_backup.cpgd ~/
scp root@OLDAPPLIANCEIPaddress:/var/www/miq/vmdb/GUID /var/www/miq/vmdb/
createdb vmdb_production
pg_restore --dbname=vmdb_production ~/db_backup.cpgd
rake db:migrate
rake evm:automate:reset
systemctl start evmserverd

At this point the server will not come up due to decription problem with v2_key.


#4

ManageIQ stores passwords, by first encrypting the password and storing the encrypted String in the database. When you do a pg_dump and pg_restore, you are also copying those encrypted strings, therefore you have to copy the encryption key from the old appliance to the new one.

The key should be somewhere in the application directory (/var/www/miq/vmdb) in a file called v2_key. Alternatively you can use the appliance_console command to copy the key


#5

I’ve already done that, but still get the error.

rake db:migrate

rake aborted!
MiqPassword::MiqPasswordError: can not decrypt v2_key encrypted string
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:56:in block in decrypt_passwords!' /var/www/miq/vmdb/lib/vmdb/settings_walker.rb:41:inblock in walk_passwords’
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:22:in block in walk' /var/www/miq/vmdb/lib/vmdb/settings_walker.rb:19:ineach’
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:19:in walk' /var/www/miq/vmdb/lib/vmdb/settings.rb:33:inwalk’
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:26:in block in walk' /var/www/miq/vmdb/lib/vmdb/settings_walker.rb:19:ineach’
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:19:in walk' /var/www/miq/vmdb/lib/vmdb/settings.rb:33:inwalk’
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:40:in walk_passwords' /var/www/miq/vmdb/lib/vmdb/settings_walker.rb:56:indecrypt_passwords!’
/var/www/miq/vmdb/lib/patches/database_configuration_patch.rb:30:in database_configuration' /var/www/miq/vmdb/config/environment.rb:5:in<top (required)>’

Caused by:
OpenSSL::Cipher::CipherError: bad decrypt
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:56:in block in decrypt_passwords!' /var/www/miq/vmdb/lib/vmdb/settings_walker.rb:41:inblock in walk_passwords’
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:22:in block in walk' /var/www/miq/vmdb/lib/vmdb/settings_walker.rb:19:ineach’
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:19:in walk' /var/www/miq/vmdb/lib/vmdb/settings.rb:33:inwalk’
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:26:in block in walk' /var/www/miq/vmdb/lib/vmdb/settings_walker.rb:19:ineach’
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:19:in walk' /var/www/miq/vmdb/lib/vmdb/settings.rb:33:inwalk’
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:40:in walk_passwords' /var/www/miq/vmdb/lib/vmdb/settings_walker.rb:56:indecrypt_passwords!’
/var/www/miq/vmdb/lib/patches/database_configuration_patch.rb:30:in database_configuration' /var/www/miq/vmdb/config/environment.rb:5:in<top (required)>’
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)


#6

Problem is fixed now:
Had to fix the ecrypted key in database.yml before migrating the db:

  1. bundle exec ruby tools/fix_auth.rb -y -v -p smartvm -P smartvm -i smartvm
  2. rake db:migrate