-
Notifications
You must be signed in to change notification settings - Fork 2
/
database.yml
56 lines (49 loc) · 1.71 KB
/
database.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
- name: Manage databases
hosts: '{{ target }}'
tasks:
- name: Copy database to host system
when: restore_backup is defined and restore_backup
copy:
src: "{{ db_file }}"
dest: /home/ubuntu/{{ db_name }}/{{ db_name }}.db
owner: "{{ default_user }}"
group: "{{ gunicorn_group }}"
mode: 0644
- name: Drop database
become_user: "{{ db_user }}"
when: restore_backup is defined and restore_backup
postgresql_db:
db: "{{ db_name }}"
encoding: 'UTF-8'
lc_collate: 'en_US.UTF-8'
lc_ctype: 'en_US.UTF-8'
template: 'template0'
state: absent
- name: Create database
become_user: "{{ db_user }}"
when: restore_backup is defined and restore_backup
postgresql_db:
db: "{{ db_name }}"
encoding: 'UTF-8'
lc_collate: 'en_US.UTF-8'
lc_ctype: 'en_US.UTF-8'
template: 'template0'
state: present
- name: Restore file to database
when: restore_backup is defined and restore_backup
command: pg_restore -U {{ db_user }} -Fc -d {{ db_name }} /home/ubuntu/{{ db_name }}/{{ db_name }}.db
- name: Current UTC time
command: date +"%Y%m%d-%H%M" --universal
register: current_time
when: fetch_backup is defined and fetch_backup
delegate_to: localhost
- name: Create a database backup
command: pg_dump -U {{ db_user }} -W {{ db_name }} -Fc -f {{ db_name }}-{{ current_time }}.db
when: fetch_backup is defined and fetch_backup
- name: Fetch database backup
when: fetch_backup is defined and fetch_backup
fetch:
src: /home/ubuntu/{{ db_name }}-{{ current_time }}.db
dest: "{{ db_name }}/"
flat: yes