-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update run-iptables.yml * add playbook for backup maria_db * add playbook for creation postgres replica * add description --------- Co-authored-by: Andew Bogdanov <[email protected]>
- Loading branch information
1 parent
5cfedbc
commit 9b8839f
Showing
3 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env -S ansible-playbook -e @vars/extra.yaml | ||
# | ||
# Playbook to make cron job to create bakcup for mariadb | ||
# executable script: | ||
# | ||
# > ./run-mariadb-backup.yml.yml | ||
# | ||
--- | ||
- name: Configure target servers | ||
hosts: mariadb_servers | ||
become: yes | ||
become_user: root | ||
|
||
tasks: | ||
- name: Ensure backup db | ||
cron: | ||
name: "Backup mariadb" | ||
user: "root" | ||
minute: "0" | ||
hour: "2" | ||
job: "/usr/bin/docker exec -i {{ mariadb_backup_container_name }} oom-mariabackup create -i {{ number_of_inc_backups }} -r {{ number_of_retain_backups }} >> {{ mariadb_backup_logfile }} 2>&1" | ||
state: present | ||
tags: | ||
- backup | ||
- crontab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env -S ansible-playbook -e @vars/extra.yaml | ||
# | ||
# | ||
# Playbook for creation postgres replica. Warning!!! Playbook is not idempotent! Use only for first creation! | ||
# executable script: | ||
# | ||
# > ./run-postgres-replica.yml | ||
# | ||
--- | ||
- name: Install postgres-replica container | ||
hosts: postgresql_servers | ||
become: yes | ||
become_user: root | ||
vars: | ||
replica_backup_command: "docker exec -i {{ replica_container_name }} pg_basebackup --host={{ replica_origin_ip }} --port={{ replica_origin_port }} --username={{ vault_replica_username }} --pgdata=/tmp/ --wal-method=stream --write-recovery-conf" | ||
tasks: | ||
- name: Run postgres-replica container | ||
docker_compose: | ||
state: present | ||
project_name: "{{ replica_project_name }}" | ||
definition: | ||
version: '2' | ||
services: | ||
cadvisor: | ||
image: "{{ replica_image }}" | ||
container_name: "{{ replica_container_name }}" | ||
volumes: | ||
- "{{ replica_host_pgdata }}:/tmp" | ||
restart: always | ||
environment: | ||
POSTGRES_USER: "{{ replica_postgres_user }}" | ||
POSTGRES_PASSWORD: "{{ REPLICA_POSTGRES_PASSWORD }}" | ||
POSTGRES_DB: "{{ replica_postgres_db }}" | ||
PGDATA: "/patroni_db/postgresql/data/" | ||
ARCHIVE_MODE: 'OFF' | ||
PGUSER: "{{ replica_pguser }}" | ||
PGPASSWORD: "{{ vault_replica_password }}" | ||
PGHOST: '/var/run/postgresql' | ||
PGDATABASE: "{{ replica_pgdatabase }}" | ||
RECOVERY_WALG: 'false' | ||
|
||
- name: Create backup for replication | ||
ansible.builtin.shell: | ||
cmd: "{{ replica_backup_command }}" | ||
|
||
- name: Remove container | ||
community.docker.docker_container: | ||
name: "{{ replica_container_name }}" | ||
state: absent | ||
|
||
- name: Creating a file for adding to conf | ||
copy: | ||
dest: "{{ replica_host_pgdata }}/00server.conf" | ||
content: | | ||
primary_slot_name = '' | ||
archive_mode = always | ||
archive_command = 'archive.sh wal-push %p' | ||
archive_timeout = 30 | ||
- name: Create backup for replication | ||
ansible.builtin.shell: | ||
cmd: echo "include '00server.conf'" >> {{ replica_host_pgdata }}/postgresql.conf | ||
|
||
- name: Run postgres-replica container | ||
docker_compose: | ||
state: present | ||
project_name: "{{ replica_project_name }}" | ||
definition: | ||
version: '2' | ||
services: | ||
cadvisor: | ||
image: "registry.nalitek.com/library/postgres_with_walg_replica:14.1" | ||
container_name: "{{ replica_container_name }}" | ||
volumes: | ||
- "{{ replica_host_pgdata }}:/patroni_db/postgresql/data/" | ||
restart: always | ||
environment: | ||
POSTGRES_USER: "{{ replica_postgres_user }}" | ||
POSTGRES_PASSWORD: "{{ REPLICA_POSTGRES_PASSWORD }}" | ||
POSTGRES_DB: "{{ replica_postgres_db }}" | ||
PGDATA: "/patroni_db/postgresql/data/" | ||
ARCHIVE_MODE: 'ON' | ||
ARCHIVE_TIMEOUT: 30 | ||
AWS_ACCESS_KEY_ID: "{{ REPLICA_AWS_ACCESS_KEY_ID }}" | ||
AWS_REGION: "{{ replica_aws_region }}" | ||
AWS_SECRET_ACCESS_KEY: "{{ REPLICA_AWS_SECRET_ACCESS_KEY }}" | ||
PGUSER: "{{ replica_pguser }}" | ||
PGPASSWORD: "{{ REPLICA_POSTGRES_PASSWORD }}" | ||
WALG_S3_PREFIX: "{{ replica_walg_s3_prefix }}" | ||
PGHOST: "{{ replica_pg_host }}" | ||
PGDATABASE: "{{ replica_pgdatabase }}" | ||
AWS_ENDPOINT: "{{ replica_aws_endpoint }}" | ||
TRIGGER_FILE: '/trigger' | ||
RECOVERY_WALG: 'false' | ||
APPRISE_TARGET: "{{ REPLICA_APPRISE_TARGET }}" |