Community Articles

Find and share helpful community-sourced technical articles.
Labels (1)
avatar
Contributor

Ambari Backup and Restore for Postgres

Summary:

Ambari server stores cluster configurations in a database. The default database for the Ambari install is Postgres. This document goes through a step by step process for backing up and restoring the Postgres database.

Background:

A backup copy of your Ambari database is good insurance to keep your Ambari server running. Anytime you make changes to Ambari you should create a backup of the Ambari database before you make the changes. You will want to do this if you need to restore your cluster to the original state. Examples of what you want to take backups are before cluster upgrasdes, changing service configurations, adding new servers, etc.

Backing up the server configuration:

  • 1.Login to the server running the Ambari Server process. You will need to have the privileges to start/stop the Ambari server and read the Postgres database.
  • 2.Stop the Ambari server using the following command:
ambari-server stop
  • 3.Create a directory to hold the database backups.
cd /tmpmkdir 
mkdir dbdumpscd 
cd dbdumps

4772-01-mkdir.jpg

  • 4.Create the database backups
pg_dump -U ambari  ambari > ambari.sql 

note: The password is “bigdata”

pg_dump -U mapred ambarirca > ambarirca.sql

note: The password is “mapred”

4773-02-dump-db.jpg

You will have two files when this is complete, ambari.sql and ambarirca.sql. These files need to be backed up to a server for a future restore.

Restoring the server configuration:

  • 1.Install Ambari Server as described in the Hortonworks “Using Ambari” doc Sections 2.1 and 2.2.
  • 2.Login to the system with enough priveledge to start/stop the Ambari server process and read/write data to the Postgres database.
  • 3.Stop the Ambari server and agent
ambari-server stop
ambari-agent stop
  • 4.Connect to PostgresSQL
su – postgres
psql

  • 5.In PostgresSQL drop the existing databases
drop database ambari;drop database ambarirca

4774-03-delete-db.jpg

  • 6.Verify the databases have been dropped

\list

You should not see ambari and ambarirca listed.

  • 7.Create new databases

create database ambari;

create database ambarirca;

4775-04-create-db.jpg

4776-05-dbs.jpg

  • 8.Exit PostgresSQL

^d (enter a control-d)

  • 9. Copy the ambari and ambarirca files to the new server from the back up server
  • 10.Restore the files(note: these commands need to be executed as user postgres.)

su - postgres

psql -d ambari -f ambari.sql 
psql -d ambarirca -f ambarirca.sql
  • 11.Start the Ambari server
ambari-server start

  • 12. Start the Ambari agent for all servers.
ambari-agent start

4777-06-start-ambari.jpg13.Connect to the Ambari web interface

http://<ambari server DNS name or IP address>:8080

  • 14.Verify your configuration
17,159 Views
Comments
avatar
Super Collaborator

@Ron Lee thank you for this article. Done restoring my ambari-server.

Now I just need to find how to reinstall hdp components/clients that are also installed on the same machine.

https://community.hortonworks.com/questions/72544/restoring-ambari-server-reinstalling-all-hdp-compo...

avatar

This article worked well for me except the following two commands:

  1. pg_dump -U ambari ambari > ambari.sql
  2. pg_dump -U mapred ambarirca > ambarirca.sql

To fix this, I used -f operator:

  1. pg_dump -U ambari ambari -f ambari.sql
  2. pg_dump -U mapred ambarirca -f ambarirca.sql
avatar
Explorer

Well documented... Worked well with Postgres 9.4.7... Would like to add that during restore I receieved error message 'Unknown role ambari'. I manually added the role as below after step 7 in the Restore section.

CREATE ROLE ambari WITH LOGIN PASSWORD 'bigdata';