How to exclude job event data in backup-restore process in Ansible Automation Platform 2.1 and later?
Environment
- Ansible Automation Platform 2.1 and later
Issue
- How to Exclude Job Events in the Ansible Automation Platform 2.1 and later Backup/Restore?
Resolution
For AAP 2.1 or AAP 2.2
To exclude the job events, make the following edit to the installer files located at roles/backup/tasks/postgres.yml:
# clean drops the database
# create adds instructions to create the database
# Note: user needs access to postgres template when restoring
- name: Perform a PostgreSQL dump.
shell: |
pg_dump \
--clean --create \
--host='{{ controller_db_settings.default.HOST }}' \
--port={{ controller_db_settings.default.PORT }} \
--username='{{ controller_db_settings.default.USER }}' \
--dbname='{{ controller_db_settings.default.NAME }}' \
--exclude-table-data=main_jobevent* \ <<<<<<<<< ADD THIS LINE <<<<<<<<<
--exclude-table-data=_unpartitioned_main_jobevent \ <<<<<<<<< ADD THIS LINE <<<<<<<<<
--exclude-table=main_instance \
--exclude-table=main_instancegroup \
--exclude-table=main_instancegroup_instances > tower.db
args:
chdir: '{{ backup_dir.rstrip("/") }}/common/'
environment: "{{ {'PGPASSWORD':
controller_db_settings.default.PASSWORD} | combine( extra_env | default({}) ) }}"
register: psql_command
failed_when: "'ERROR' in psql_command.stderr"
no_log: True
NOTE There is no need to modify the restore task like Ansible Tower
For AAP 2.3+
To exclude the job events, make the following edit to the installer files located at roles/backup/tasks/postgres.yml:
# clean drops the database
# create adds instructions to create the database
# Note: user needs access to postgres template when restoring
- name: Perform a PostgreSQL dump.
community.postgresql.postgresql_db:
name: '{{ controller_db_settings.default.NAME }}'
login_host: '{{ controller_db_settings.default.HOST }}'
login_port: '{{ controller_db_settings.default.PORT }}'
login_user: '{{ controller_db_settings.default.USER }}'
login_password: '{{ controller_db_settings.default.PASSWORD }}'
target: '{{ backup_dir.rstrip("/") }}/postgres/{{ db_filename }}'
#target_opts: '--clean --create --exclude-table=main_instance --exclude-table=main_instancegroup --exclude-table=main_instancegroup_instances'
target_opts: '--clean --create --exclude-table=main_instance --exclude-table=main_instancegroup --exclude-table=main_instancegroup_instances --exclude-table-data=main_jobevent* --exclude-table-data=_unpartitioned_main_jobevent'
state: dump
environment: '{{ extra_env | default(omit) }}'
NOTE There is no need to modify the restore task like Ansible Tower
Root Cause
-
Unlike
Ansible Tower,main_jobeventis a partitioned table inAnsible Automation Platform. In order to exclude old Job Events inAAP 2.1+, you need to modify the followingfilesfrombackup roles. -
Sometimes it could be necessary due to problems related to the size of the tables and storage problems.
-
This procedure is useful when backing up data in order to be
restoredin a differentdatabase.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments