-
Notifications
You must be signed in to change notification settings - Fork 4
/
99-db-restore.yml
34 lines (28 loc) · 1 KB
/
99-db-restore.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Playbook to do restore
- name: Restore DB from Backup
hosts:
user:
sudo: True
gather_facts: False
vars:
timestamp: "{{ lookup('file', 'timestamp.txt') }}"
restore_dir: /tmp/restore
restore_dest: "{{ restore_dir }}/{{ timestamp }}"
restore_tar: "{{ timestamp }}.tar.gz"
local_dir: files/backup
local_path: "{{ local_dir }}/{{ restore_tar }}"
# Tasks for restore
tasks:
- name: restore folder
file: path={{ restore_dir }} state=directory
- name: upload backup
synchronize: src="{{ local_path }}" dest="{{ restore_dir }}"
- name: unpack backup
unarchive: src="{{ restore_dir }}/{{ restore_tar }}" dest="{{ restore_dir }}" copy=no
- name: clean stale mongo edxapp
shell: mongo edxapp --eval "db.dropDatabase()"
- name: restore db
shell: chdir="{{ restore_dest }}/{{ item.dir }}" {{ item.com }}
with_items:
- { com: 'mysql -u root edxapp < backup.sql', dir: 'mysql' }
- { com: 'mongorestore dump/', dir: 'mongo' }