all demo
This commit is contained in:
39
ansible/playbook/pg_dump/README.md
Normal file
39
ansible/playbook/pg_dump/README.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Ansible Database Backup
|
||||
|
||||
[](https://docs.ansible.com/ansible/latest/collections/community/postgresql/postgresql_db_module.html#ansible-collections-community-postgresql-postgresql-db-module)
|
||||
|
||||
Backup database from remote postgresql for {{store}} days.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
ansible-galaxy collection install community.postgresql
|
||||
```
|
||||
## How to dump
|
||||
```
|
||||
ansible-playbook sd_pro_dump.yml -l sd-pgsql9 --extra-vars "dbname=sd4_itsmcorp_devel store=7 arg=--format=custom"
|
||||
```
|
||||
```
|
||||
Avalable env:
|
||||
store: default('1') - how long do you need to store current backup
|
||||
target: default('/opt/back/internal/postgres/') - where place put the archive
|
||||
arg: default('--exclude-table=tbl_event --format=custom') - pg_dump argument
|
||||
```
|
||||
|
||||
#### PostgreSQL
|
||||
|
||||
[Official documentaiton.](https://www.postgresql.org/docs/current/static/app-pgdump.html)
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
pg_dump --format "custom" --file "/opt/back/internal/postgres/{{ dbname }}.bak" {{ dbname }}
|
||||
```
|
||||
|
||||
## Supported Databases
|
||||
|
||||
For now supports:
|
||||
* PostgreSQL
|
||||
|
||||
## Supported OS
|
||||
Linux
|
||||
28
ansible/playbook/pg_dump/pg_dump.yml
Normal file
28
ansible/playbook/pg_dump/pg_dump.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
- hosts: all
|
||||
remote_user: ansible
|
||||
vars:
|
||||
store_env: "{{ store|default('1') }}"
|
||||
target_env: "{{ target|default('/opt/back/internal/postgres/') }}"
|
||||
extra_args: "{{ arg|default('--exclude-table=tbl_event --format=custom') }}"
|
||||
|
||||
tasks:
|
||||
- debug:
|
||||
var: store_env
|
||||
- debug:
|
||||
var: target_env
|
||||
|
||||
- name: Add num_of_days days to start_date
|
||||
command: date +'%Y-%m-%d' -d "+{{store_env}} days"
|
||||
register: end_date
|
||||
- debug:
|
||||
var: end_date.stdout
|
||||
|
||||
- name: Dump the "{{ dbname }}" database to a file
|
||||
become: yes
|
||||
become_method: sudo
|
||||
become_user: postgres
|
||||
community.postgresql.postgresql_db:
|
||||
name: "{{ dbname }}"
|
||||
state: dump
|
||||
target: "{{ target_env }}{{ dbname }}_{{ ansible_date_time.date }}_{{ end_date.stdout }}.bak"
|
||||
dump_extra_args: "{{ extra_args }}"
|
||||
Reference in New Issue
Block a user