{"id":10046,"date":"2022-05-23T08:08:33","date_gmt":"2022-05-23T08:08:33","guid":{"rendered":"https:\/\/www.insentragroup.com\/nz\/?p=10046"},"modified":"2024-12-13T01:57:25","modified_gmt":"2024-12-13T01:57:25","slug":"how-to-guide-on-ansible-tower-backup-and-restore-on-azure","status":"publish","type":"post","link":"https:\/\/www.insentragroup.com\/nz\/insights\/geek-speak\/modern-workplace\/how-to-guide-on-ansible-tower-backup-and-restore-on-azure\/","title":{"rendered":"How-to guide on Ansible Tower Backup and Restore on Azure"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"ansible-tower-backup-and-restore-on-azure\"><strong>Ansible Tower Backup and Restore on Azure<\/strong><\/h2>\n\n\n\n<p>The following blog is a step-by-step guide which has been developed to assist with an Ansible Tower DB recovery in Azure.<\/p>\n\n\n\n<p>This document applies to the configuration with Ansible Tower DB on the external Azure PaaS PostgreSQL.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"database-recovery-in-azure\">DATABASE RECOVERY IN AZURE<\/h3>\n\n\n\n<p>1. To recover PostgreSQL Database in Azure, navigate to the Database in the Azure Portal and click Restore:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.insentragroup.com\/au\/wp-content\/uploads\/sites\/6\/2022\/06\/image-1024x295.png\" alt=\"\" class=\"wp-image-12149\"\/><\/figure>\n\n\n\n<p>2. Select the Restore Point and specify the name. For simplicity, use the current name of the server and add at the end the number. For example: azpsg-asttaae01-r01<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.insentragroup.com\/au\/wp-content\/uploads\/sites\/6\/2022\/06\/image-2-1024x711.png\" alt=\"\" class=\"wp-image-12151\"\/><\/figure>\n\n\n\n<p>3. Initiate the Restore.<\/p>\n\n\n\n<p>4. Once the restore is finished, navigate to the restored database and click on \u2018Connection Security\u2019. Under VNET Rules, click Adding existing virtual network and configure it to allow communication between the AT servers and the database.<\/p>\n\n\n\n<p>5. Open SSH session to ALL Ansible Tower Nodes and stop all ansible tower services using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># ansible-tower-service stop<\/code><\/pre>\n\n\n\n<p>6. Execute the following set of commands ON EACH node:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># cd \/etc\/tower\/conf.d\n# cp postgres.py postgres.py.orig<\/code><\/pre>\n\n\n\n<p>Once the postgres database restore is finished, the Azure will append a suffix to the end of the server name and username. For example, if \u2018*-r01\u2019 was added to the hostname, the new name of the db will read: &#8216;<code>azpsg-asttaee01-r01.postgres.database.azure.com<\/code>&#8216; and the user will be: <code>'azpsgasttaae01admin@azpsg-asttaee01-r01'<\/code><\/p>\n\n\n\n<p>7. Edit postgres.py file and update lines 8 and 10.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Ansible Tower database settings.\n\nDATABASES = {\n   'default': {\n       'ATOMIC_REQUESTS': True,\n       'ENGINE': 'awx.main.db.profiled_pg',\n       'NAME': 'awx',\n       'USER': 'azpsgasttaae01admin@azpsg-asttaee01',\n       'PASSWORD': \"\"\"password\"\"\",\n       'HOST': 'azpsg-asttaee01.postgres.database.azure.com',\n       'PORT': '5432',\n       'OPTIONS': { 'sslmode': 'prefer',\n                    'sslrootcert': '\/etc\/pki\/tls\/certs\/ca-bundle.crt',\n       },\n   }\n}\n<\/code><\/pre>\n\n\n\n<p>TO:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Ansible Tower database settings.\n\nDATABASES = {\n   'default': {\n       'ATOMIC_REQUESTS': True,\n       'ENGINE': 'awx.main.db.profiled_pg',\n       'NAME': 'awx',\n       'USER': 'azpsgasttaae01admin@azpsg-asttaee01-r01',\n       'PASSWORD': \"\"\"password\"\"\",\n       'HOST': 'azpsg-asttaee01-r01.postgres.database.azure.com',\n       'PORT': '5432',\n       'OPTIONS': { 'sslmode': 'prefer',\n                    'sslrootcert': '\/etc\/pki\/tls\/certs\/ca-bundle.crt',\n       },\n   }\n}\n<\/code><\/pre>\n\n\n\n<p>8. Once the configuration file has been updated on all the hosts, start the ansible daemons:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># ansible-tower-service start<\/code><\/pre>\n\n\n\n<p>9. Confirm that all the nodes are visible:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@node00002 conf.d]#  awx-manage list_instances\n&#91;tower capacity=411]\n        node00001 capacity=137 version=3.8.4 heartbeat=\"2021-11-04 03:33:16\"\n        node00002 capacity=137 version=3.8.4 heartbeat=\"2021-11-04 03:33:26\"\n        node00003 capacity=137 version=3.8.4 heartbeat=\"2021-11-04 03:33:16\"\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">RESTORE POSTGRES DB USING PG_DUMP<\/h3>\n\n\n\n<p>The following process can be used to recover the Database:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Restore the Postgres DB as indicated in the section above<\/li><li>Connect to the Ansible Node<\/li><li>Ensure ansbile-tower-services are stopped (ansible-tower-services stop)<\/li><li>Use the following command to dump the awx database from the RECOVERED DB:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>pg_dump -Fc -v --host=azpsg-asttaae01-r01.postgres.database.azure.com --port=5432 --dbname=awx --user='azpsgasttaae01admin@azpsg-asttaae01-r01' -f \/ansiblebkp\/awx-db-backup.dump<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"5\"><li>Connect to the original database:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>psql \"host=azpsg-asttaae01.postgres.database.azure.com port=5432 dbname=postgres user=azpsgasttaae01admin@azpsg-asttaae01 password=&lt;your_password&gt; sslmode=require\"<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"6\"><li>Rename existing DB:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>alter database awx rename to awx_04112021;<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"7\"><li>Recreate the awx database:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE awx WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en-US' LC_CTYPE = 'en-US';<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"8\"><li>Exit the database:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>postgres=&gt; q<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"9\"><li>Restore the database:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>pg_restore -v --no-owner --host=azpsg-asttaee01-restored.postgres.database.azure.com --port=5432 --user=azpsgasttaae01admin@azpsg-asttaee01 --dbname=awx \/ansiblebkp\/awx-db-backup.dump<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"10\"><li>Remove old database once AT is operable:<\/li><\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"11\"><li>Connect to the database using the following command:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code> psql \"host=azpsg-asttaee01-restored.postgres.database.azure.com port=5432 dbname=postgres user=azpsgasttaae01admin@azpsg-asttaee01 password=&lt;your_password&gt; sslmode=require\"<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"12\"><li>List available databases:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>postgres=&gt; l\n                                                                   List of databases\n         Name          |        Owner        | Encoding |          Collate           |           Ctype            |          Access privileges\n-----------------------+---------------------+----------+----------------------------+----------------------------+-------------------------------------\n awx                   | azpsgasttaae01admin | UTF8     | en-US                      | en-US                      |\n awx_04112021          | azpsgasttaae01admin | UTF8     | en-us                      | en-us                      |\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"13\"><li>Drop the database:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>postgres=&gt; drop database awx_04112021;\nDROP DATABASE\n<\/code><\/pre>\n\n\n\n<p>For more Ansible and Open Source how-to guides check out <a href=\"https:\/\/www.insentragroup.com\/nz\/insights\/geek-speak\/modern-workplace\/how-to-configure-ansible-automation-saml-sso-with-red-hat-sso\/\">How to configure Ansible Automation SAML SSO with Red Hat SSO<\/a>.<\/p>\n\n\n\n<style>\nbody .wp-block-code>code {\n    background: #ccc !important;\n    color: #000 !important;\n}\n<\/style>\n","protected":false},"excerpt":{"rendered":"<p>Need help with an Ansible Tower DB recovery? We have developed a step-by-step guide on how to recover your Ansible Tower Postgresgl Database in Azure.<\/p>\n","protected":false},"author":67,"featured_media":10050,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[19],"tags":[],"class_list":["post-10046","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-modern-workplace","entry"],"_links":{"self":[{"href":"https:\/\/www.insentragroup.com\/nz\/wp-json\/wp\/v2\/posts\/10046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.insentragroup.com\/nz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.insentragroup.com\/nz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.insentragroup.com\/nz\/wp-json\/wp\/v2\/users\/67"}],"replies":[{"embeddable":true,"href":"https:\/\/www.insentragroup.com\/nz\/wp-json\/wp\/v2\/comments?post=10046"}],"version-history":[{"count":7,"href":"https:\/\/www.insentragroup.com\/nz\/wp-json\/wp\/v2\/posts\/10046\/revisions"}],"predecessor-version":[{"id":10470,"href":"https:\/\/www.insentragroup.com\/nz\/wp-json\/wp\/v2\/posts\/10046\/revisions\/10470"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.insentragroup.com\/nz\/wp-json\/wp\/v2\/media\/10050"}],"wp:attachment":[{"href":"https:\/\/www.insentragroup.com\/nz\/wp-json\/wp\/v2\/media?parent=10046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.insentragroup.com\/nz\/wp-json\/wp\/v2\/categories?post=10046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.insentragroup.com\/nz\/wp-json\/wp\/v2\/tags?post=10046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}