Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Réparation du script de backup et restoration de données de MongoDb #195

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}"
Loading