Skip to content

Commit

Permalink
fix: mise à jour de la query et mise en place de la bonne extension d…
Browse files Browse the repository at this point in the history
…'archive permettant de la décompresser (#195) (#196)
  • Loading branch information
jenovateurs authored Aug 19, 2024
1 parent 265565f commit 25a285d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ It is possible to dump mongodb collections from a server and restore them on ano
In order do dump data, you will need to had specific configuration lines in your inventory application to specify which mongodb collection to target and with which query :
```yaml
mongodb_collections_migration:
simulations: '{"created_at": {"$gte": { "$date": "2023-01-01T00:00:00.000Z" }}}'
followups: '{"created_at": {"$gte": { "$date": "2023-01-01T00:00:00.000Z" }}}'
simulations: '{"createdAt": {"$gte": { "$date": "2023-01-01T00:00:00.000Z" }}}'
followups: '{"createdAt": {"$gte": { "$date": "2023-01-01T00:00:00.000Z" }}}'
```
Then run the following command to download the selected collections locally in a `./.tmp` folder :
```bash
Expand Down
4 changes: 2 additions & 2 deletions inventories/localhost.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ virtualmachines:
openfisca_server_port: 2001
openfisca_worker_number: 4
mongodb_collections_migration:
simulations: '{"created_at": {"$gte": { "$date": "2023-01-01T00:00:00.000Z" }}}'
followups: '{"created_at": {"$gte": { "$date": "2023-01-01T00:00:00.000Z" }}}'
simulations: '{"createdAt": {"$gte": { "$date": "2023-01-01T00:00:00.000Z" }}}'
followups: '{"createdAt": {"$gte": { "$date": "2023-01-01T00:00:00.000Z" }}}'
- name: aides_jeunes_preprod
repository: https://github.com/betagouv/aides-jeunes.git
branch: dev
Expand Down
6 changes: 3 additions & 3 deletions roles/mongodb_migration/tasks/mongodb-dump.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
--db db_{{ application.name }} \
--collection {{ item.key }} \
--query '{{ item.value }}' \
--archive=/tmp/mongodump/{{ application.name }}_{{ item.key }}.tar.gz \
--archive=/tmp/mongodump/{{ application.name }}_{{ item.key }}.gz \
--gzip
register: dump_result
changed_when: dump_result.rc == 0
with_dict: "{{ application.mongodb_collections_migration }}"
- name: Fetch MongoDB dump to local machine
ansible.builtin.fetch:
src: /tmp/mongodump/{{ application.name }}_{{ item.key }}.tar.gz
src: /tmp/mongodump/{{ application.name }}_{{ item.key }}.gz
dest: ./.tmp/
flat: true
with_dict: "{{ application.mongodb_collections_migration }}"
- name: Remove MongoDB dump archives from server
ansible.builtin.file:
path: /tmp/mongodump/{{ application.name }}_{{ item.key }}.tar.gz
path: /tmp/mongodump/{{ application.name }}_{{ item.key }}.gz
state: absent
with_dict: "{{ application.mongodb_collections_migration }}"
6 changes: 3 additions & 3 deletions roles/mongodb_migration/tasks/mongodb-restore.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
- name: Restore MongoDB collections to Server
ansible.builtin.copy:
src: ./.tmp/{{ application.name }}_{{ item.key }}.tar.gz
src: ./.tmp/{{ application.name }}_{{ item.key }}.gz
dest: /tmp/mongodump/
mode: "0644"
with_dict: "{{ application.mongodb_collections_migration }}"
- name: Restore MongoDB database from dump
ansible.builtin.shell: |
mongorestore \
--gzip \
--archive=/tmp/mongodump/{{ application.name }}_{{ item.key }}.tar.gz
--archive=/tmp/mongodump/{{ application.name }}_{{ item.key }}.gz
register: restore_result
changed_when: restore_result.rc == 0
with_dict: "{{ application.mongodb_collections_migration }}"
- name: Remove MongoDB dumps and archive from remote server
ansible.builtin.file:
path: /tmp/mongodump/{{ application.name }}_{{ item.key }}.tar.gz
path: /tmp/mongodump/{{ application.name }}_{{ item.key }}.gz
state: absent
with_dict: "{{ application.mongodb_collections_migration }}"

0 comments on commit 25a285d

Please sign in to comment.