diff --git a/README.md b/README.md index a3381b4..e77396b 100644 --- a/README.md +++ b/README.md @@ -6,37 +6,15 @@ Sync local PostgreSQL or MySQL database with remote. Requirements ------------ -The local system need to have either `pg_dump` and `pg_reload` command or `mysql` and `mysqldump`. +The following CLI commands need to be installed on your system / Docker image : + +- PostgreSQL: `pg_dump` and `pg_restore` +- MySQL: `mysqldump` and `mysql` Role Variables -------------- -The `defaults` vars declared in this module: - -``` -db_pull_remote_backup_path: /tmp/db-pull -db_pull_local_backup_path: /tmp/db-pull -db_pull_keep_backup: 5 - -db_pull_remote_database_user: postgres -db_pull_remote_database_host: localhost -db_pull_remote_database_name: postgres -db_pull_remote_database_password: root -db_pull_remote_database_port: 5432 - -db_pull_local_database_user: postgres -db_pull_local_database_host: localhost -db_pull_local_database_name: postgres -db_pull_local_database_password: root -db_pull_local_database_port: 5432 - -db_pull_database_type: postgres - -db_pull_skip_restore: false - -db_pull_exclude_table: [] -db_pull_exclude_table_data: [] -``` +`defaults` vars declared in this module can be found here: [defaults/main.yml](defaults/main.yml) Example Playbook ---------------- @@ -55,4 +33,4 @@ MIT Author Information ------------------ - * ansible-db-pull, written by Erwan Richard +* ansible-db-pull, written by Erwan Richard diff --git a/defaults/main.yml b/defaults/main.yml index 1c5334a..e00862c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -23,3 +23,19 @@ db_pull_skip_restore: false db_pull_exclude_table: [] db_pull_exclude_table_data: [] + +db_pull_anonymization: false + +db_pull_anonymization_remote_database_user: postgres +db_pull_anonymization_remote_database_host: localhost +db_pull_anonymization_remote_database_name: postgres +db_pull_anonymization_remote_database_password: root +db_pull_anonymization_remote_database_port: 5432 + +db_pull_anonymization_remote_database_url: "postgresql://{{ db_pull_anonymization_remote_database_user }}:{{ db_pull_anonymization_remote_database_password }}@{{ db_pull_anonymization_remote_database_host }}:{{ db_pull_anonymization_remote_database_port }}/{{ db_pull_anonymization_remote_database_name }}?serverVersion=17" + +db_pull_anonymization_command: >- + chdir={{ ansistrano_deploy_to }}/current + DATABASE_URL="{{ db_pull_anonymization_remote_database_url }}" + APP_ENV={{ symfony_env }} + php bin/console db-tools:anonymize --local-database --no-restore -n {{ db_pull_remote_backup_path }}/{{ db_pull_remote_database_name }}-{{ ansible_date_time.iso8601 }}.dump diff --git a/meta/main.yml b/meta/main.yml index b8002ff..2ebddc7 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -2,11 +2,11 @@ galaxy_info: author: Erwan Richard description: One way sync between remote and local databases company: Le Phare - issue_tracker_url: https://github.com/erichard/ansible-database-sync + issue_tracker_url: https://github.com/le-phare/ansible-db-pull/issues license: MIT - min_ansible_version: 1.2 + min_ansible_version: "1.2" galaxy_tags: - database diff --git a/tasks/main.yml b/tasks/main.yml index 3caad01..195d72b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -15,6 +15,10 @@ - include_tasks: "{{ db_pull_database_type }}/dump.yml" when: local_dump.matched == 0 +- name: Anonymize using DbToolsBundle + shell: {{ db_pull_anonymization_command }} + when: db_pull_anonymization + - name: Ensure database dump folder exists delegate_to: localhost become: false diff --git a/tasks/mysql.yml b/tasks/mysql.yml deleted file mode 100644 index 74801c8..0000000 --- a/tasks/mysql.yml +++ /dev/null @@ -1,8 +0,0 @@ -- name: backup mysql db server - shell: > - mysqldump \ - -u {{ db_pull_remote_database_user }} \ - --password={{ db_pull_remote_database_password }} \ - -h {{ db_pull_remote_database_host }} \ - {{ db_pull_remote_database_name }} \ - > {{ db_pull_remote_backup_path }}/{{ db_pull_remote_database_name }}-{{ ansible_date_time.iso8601 }}.dump diff --git a/tasks/postgres.yml b/tasks/postgres.yml deleted file mode 100644 index f6e3a79..0000000 --- a/tasks/postgres.yml +++ /dev/null @@ -1,7 +0,0 @@ -- name: backup postgres db server - shell: > - PGPASSWORD="{{ db_pull_remote_database_password }}" pg_dump -Fc \ - -U {{ db_pull_remote_database_user }} \ - -h {{ db_pull_remote_database_host }} \ - -d {{ db_pull_remote_database_name }} \ - -f {{ db_pull_remote_backup_path }}/{{ db_pull_remote_database_name }}-{{ ansible_date_time.iso8601 }}.dump