Monday, January 16, 2017

sonarqube postgresql db backup and recovery

postgresql is one of the DB supported by sonarqube. In this blog I'll list out the steps involved in taking back-up of postgresql DB used by sonarqube.

As described in the official postgresql 'Backup and Restore' documentation, there are 3 different approaches to back-up postgresql Databases. This blog uses the 'SQL Dump' approach.

In case if you are trying to install sonarqube on CentOS 7 with postgresql as DB, refer this http://frederic-wou.net/sonarqube-installation-on-centos-7-2/ url. It explains the steps in detail.

Creating Database Dump

The sonarqube server stores it's data on a database named 'sonar' under postgresql. So create dump of this database using one of these commands
  • pg_dump -U postgres -F t sonar > sonar_db_dump.tar
    • -U postges : Specifying the username to connect to DB and in this case it is 'postgres'
    • -F t: the format of dump created and in this case it is created in 'tar' format.
    • 'sonar' is the database name to create dump
or
  • pg_dump -U postgres sonar > sonar_db_dump.tar
    • This creates dump in the plain text format

Restoring database dump

You can use either 'psql' or 'pg_restore' utility to restore the database dump. I have used 'pg_restore' for the advantages described in this http://www.postgresqltutorial.com/postgresql-restore-database/ link
  • First install a plain sonarqube server. You can refer http://frederic-wou.net/sonarqube-installation-on-centos-7-2/ for centos based installation instructions
    • Don't start sonarqube server
  • Restore the Database dump
    • su - postgres 
    • pg_restore -U postgres --dbname=sonar --verbose /tmp/sonar_db_dump.tar
  • Start the sonarqube server
    • /opt/sonarqube-5.4/bin/linux-x86-64/sonar.sh start
    • /opt/sonarqube-5.4/bin/linux-x86-64/sonar.sh status
    • tail -f /opt/sonarqube-5.4/logs/sonar.log
    • Ensure sonarqube started successfully by referring the sonar.log
  • Browse to the new sonarqube server http://<ip>:9000 and there you can see the restored projects

Reference






7 comments:

PostgreSQL Backup Database said...

Backup database is really important and PostgreSQL backup database provide best solution. Thanks for sharing valuable information.

Unknown said...

Thanks. I was drowning in postgres documentation ... this saved me a heap of time. Thanks for sharing.

Anjali Siva said...

Fabulous post admin, it was too good and helpful. Waiting for more updates.
DevOps course in Chennai
AWS Training in Chennai
AWS Training in Velachery
Cloud Computing Courses in Chennai
Cloud Training in Chennai
DevOps Training in OMR
DevOps Training in Chennai

rajani kota said...

Really nice post.provided a helpful information.
DevOps Online Training institute
DevOps Online Training in Hyderabad
DevOps Course in Hyderabad

Pathway for German Language said...
This comment has been removed by the author.
EMMANUEL said...

so informative.thank you for this blog

Python Training in chennai | Python Classes in Chennai

Chaitanya said...

Thanks for this useful information. But I wanted to know that how many backlinks you can make from one blog or a site?
AWS Solutions Architect Training from Hyderabadg
Exchange Server Training from Hyderabadg