diff --git a/tripleo_ansible/playbooks/cli-undercloud-db-backup.yaml b/tripleo_ansible/playbooks/cli-undercloud-db-backup.yaml new file mode 100644 index 000000000..2ee2d17ec --- /dev/null +++ b/tripleo_ansible/playbooks/cli-undercloud-db-backup.yaml @@ -0,0 +1,28 @@ +--- +# Copyright 2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +- name: TripleO Undercloud DB backup. + hosts: Undercloud + remote_user: "{{ tripleo_target_user | default(lookup('env', 'USER')) }}" + become: true + tasks: + - name: Create DB Backup for the undercloud + vars: + tripleo_backup_and_restore_service_manager: false + tripleo_backup_and_restore_mysql_backup_file: "/home/stack/openstack-backup-mysql-{{ lookup('pipe', 'date +%F_%H_%M_%S') }}.sql" + tripleo_backup_and_restore_mysql_grants_file: "/home/stack/openstack-backup-mysql-grants-{{ lookup('pipe', 'date +%F_%H_%M_%S') }}.sql" + include_role: + name: backup_and_restore + tasks_from: db_backup.yml diff --git a/tripleo_ansible/roles/backup_and_restore/defaults/main.yml b/tripleo_ansible/roles/backup_and_restore/defaults/main.yml index 4dd61f786..ef4f774fe 100644 --- a/tripleo_ansible/roles/backup_and_restore/defaults/main.yml +++ b/tripleo_ansible/roles/backup_and_restore/defaults/main.yml @@ -31,6 +31,12 @@ tripleo_backup_and_restore_enable_snapshots: true # Set the name of the mysql container tripleo_backup_and_restore_mysql_container: mysql +# Default name for the Undercloud mysql DB backup file +tripleo_backup_and_restore_mysql_backup_file: "openstack-backup-mysql.sql" + +# Default name for the Undercloud mysql DB grants file +tripleo_backup_and_restore_mysql_grants_file: "openstack-backup-mysql-grants.sql" + # All variables within this role should have a prefix of "tripleo_backup_and_restore" # By default this should be the Undercloud node tripleo_backup_and_restore_nfs_server: 192.168.24.1 diff --git a/tripleo_ansible/roles/backup_and_restore/tasks/db_backup.yml b/tripleo_ansible/roles/backup_and_restore/tasks/db_backup.yml index 4f914ecae..2ce0349f8 100644 --- a/tripleo_ansible/roles/backup_and_restore/tasks/db_backup.yml +++ b/tripleo_ansible/roles/backup_and_restore/tasks/db_backup.yml @@ -105,7 +105,7 @@ -p{{ mysql_password.stdout }} -s -N \ -e \"SELECT CONCAT('\\\"SHOW GRANTS FOR ''',user,'''@''',host,''';\\\"') \ FROM mysql.user where (length(user) > 0 and user NOT LIKE 'root')\" | xargs -n1 mysql \ - -uroot -p{{ mysql_password.stdout }} -s -N -e | sed 's/$/;/' " > openstack-backup-mysql-grants.sql + -uroot -p{{ mysql_password.stdout }} -s -N -e | sed 's/$/;/' " > {{ tripleo_backup_and_restore_mysql_grants_file }} when: mysql_password.stderr is defined tags: - bar_create_recover_image @@ -118,7 +118,7 @@ -p{{ mysql_password.stdout }} -s -N \ -e \"select distinct table_schema from information_schema.tables \ where engine='innodb' and table_schema != 'mysql';\" | xargs mysqldump -uroot \ - -p{{ mysql_password.stdout }} --single-transaction --databases" > openstack-backup-mysql.sql + -p{{ mysql_password.stdout }} --single-transaction --databases" > {{ tripleo_backup_and_restore_mysql_backup_file }} when: mysql_password.stderr is defined tags: - bar_create_recover_image