File tree Expand file tree Collapse file tree 5 files changed +34
-3
lines changed
Expand file tree Collapse file tree 5 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 8888 pg_dump_suffix :
8989 description : Additional parameters for the pg_dump command
9090 type : string
91+ use_db_compression :
92+ description : Enable compression for database dumps. When true, pg_dump uses built-in compression. Default is false.
93+ type : boolean
94+ default : false
9195 postgres_label_selector :
9296 description : Label selector used to identify postgres pod for backing up data
9397 type : string
Original file line number Diff line number Diff line change @@ -175,6 +175,12 @@ spec:
175175 path : additional_labels
176176 x-descriptors :
177177 - urn:alm:descriptor:com.tectonic.ui:advanced
178+ - description : Enable compression for database dumps using pg_dump built-in compression
179+ displayName : Use DB Compression
180+ path : use_db_compression
181+ x-descriptors :
182+ - urn:alm:descriptor:com.tectonic.ui:advanced
183+ - urn:alm:descriptor:com.tectonic.ui:booleanSwitch
178184 - displayName : Node Selector for backup management pod
179185 path : db_management_pod_node_selector
180186 x-descriptors :
Original file line number Diff line number Diff line change @@ -42,6 +42,9 @@ backup_resource_requirements:
4242# Allow additional parameters to be added to the pg_dump backup command
4343pg_dump_suffix : ' '
4444
45+ # Enable compression for database dumps
46+ use_db_compression : false
47+
4548# Labels defined on the resource, which should be propagated to child resources
4649additional_labels : []
4750
Original file line number Diff line number Diff line change 6464 command : >-
6565 mkdir -p {{ backup_dir }}
6666
67+ - name : Set database filename
68+ set_fact :
69+ _db_filename : " {{ use_db_compression | bool | ternary('tower.db.gz', 'tower.db') }}"
70+
6771- name : Precreate file for database dump
6872 k8s_exec :
6973 namespace : " {{ backup_pvc_namespace }}"
7074 pod : " {{ ansible_operator_meta.name }}-db-management"
7175 container : " {{ ansible_operator_meta.name }}-db-management"
7276 command : >-
73- touch {{ backup_dir }}/tower.db
77+ touch {{ backup_dir }}/{{ _db_filename }}
7478
7579 - name : Set resolvable_db_host
7680 set_fact :
121125 -d {{ awx_postgres_database }}
122126 -p {{ awx_postgres_port }}
123127 -F custom
128+ {{ use_db_compression | bool | ternary('-Z 9', '') }}
124129 {{ pg_dump_suffix }}
125130 no_log : " {{ no_log }}"
126131
147152 trap 'end_keepalive \"$keepalive_file\" \"$keepalive_pid\"' EXIT SIGINT SIGTERM
148153 echo keepalive_pid: $keepalive_pid
149154 set -e -o pipefail
150- PGPASSWORD='{{ awx_postgres_pass }}' {{ pgdump }} > {{ backup_dir }}/tower.db
155+ PGPASSWORD='{{ awx_postgres_pass }}' {{ pgdump }} > {{ backup_dir }}/{{ _db_filename }}
151156 set +e +o pipefail
152157 echo 'Successful'
153158 "
Original file line number Diff line number Diff line change 8080 -p {{ awx_postgres_port }}
8181 no_log : " {{ no_log }}"
8282
83+ - name : Find database file
84+ kubernetes.core.k8s_exec :
85+ namespace : " {{ backup_pvc_namespace }}"
86+ pod : " {{ ansible_operator_meta.name }}-db-management"
87+ container : " {{ ansible_operator_meta.name }}-db-management"
88+ command : >-
89+ bash -c "ls {{ backup_dir }}/tower.db.gz 2>/dev/null || ls {{ backup_dir }}/tower.db 2>/dev/null"
90+ register : _db_file_result
91+
92+ - name : Set database filename for restore
93+ set_fact :
94+ _db_filename : " {{ _db_file_result.stdout | trim | basename }}"
95+
8396- name : Set pg_restore command
8497 set_fact :
8598 pg_restore : >-
159172 echo keepalive_pid: $keepalive_pid
160173 set -e -o pipefail
161174 {{ pg_drop_create }}
162- cat {{ backup_dir }}/tower.db | PGPASSWORD='{{ awx_postgres_pass }}' {{ pg_restore }}
175+ cat {{ backup_dir }}/{{ _db_filename }} | PGPASSWORD='{{ awx_postgres_pass }}' {{ pg_restore }}
163176 PG_RC=$?
164177 set +e +o pipefail
165178 exit $PG_RC
You can’t perform that action at this time.
0 commit comments