giner.barman

Uruchom testy

Rożek Ansible: Barman

Instaluje i konfiguruje Barmana na systemie Linux z opcjonalnymi funkcjami:

  • regularne kopie zapasowe (uruchamiane przez cron)
  • przesyłanie wals i migawków do S3 (uruchamiane przez cron)
  • zbieranie metryk (przez telegraf)

Ten rożek ma być jak najbardziej neutralny, tj. wszystkie parametry konfiguracyjne są bezpośrednio przekazywane do konfiguracji Barmana.

Wymagania

  • Ubuntu

Instalacja

Zainstaluj za pomocą Ansible Galaxy:

ansible-galaxy collection install giner.barman

Lub dodaj ten rożek do pliku requirements.yml:

roles:
  - name: giner.barman

Zmienne rożka

Dostępne zmienne są wymienione poniżej, wraz z wartościami domyślnymi (patrz defaults/main.yml):

Stan Barmana. Możesz ustawić na absent, aby odinstalować Barmana. Dane nie zostaną usunięte.

barman_state: started

Stan pakietu Barmana. Możesz ustawić na latest, aby zaktualizować Barmana.

barman_package_state: present

Ogólne nadpisania konfiguracji Barmana (klucz/wartość).

barman_config: {}

Serwery PostgreSQL do wykonania kopii zapasowych.

barman_pg_servers: []    # Klucze to: name, params, pgpass i cron. Zobacz przykład poniżej.

Skonfiguruj telegraf do zbierania metryk Barmana.

barman_telegraf_enabled: false

Interwał zbierania metryk.

barman_telegraf_interval: 1m

Zależności

Brak.

Przykładowy Playbook

# Konfiguracja użytkowników i ich uprawnień na serwerze bazy danych PostgreSQL
# http://docs.pgbarman.org/release/2.12/#postgresql-connection
- hosts: postgresqls
  vars:
    barman_user: barman
    barman_pass: BARMANPASS_CHANGEME
    barman_streaming_user: streaming_barman
    barman_streaming_pass: STREAMINGPASS_CHANGEME
  tasks:
  - name: Dodaj użytkownika PostgreSQL barman_user
    community.postgresql.postgresql_user:
      user: "{{ barman_user }}"
      password: "{{ barman_pass }}"
      role_attr_flags: replication
      groups: [pg_read_all_settings, pg_read_all_stats]
  - name: Dodaj użytkownika PostgreSQL barman_streaming_user
    community.postgresql.postgresql_user:
      user: "{{ barman_streaming_user }}"
      password: "{{ barman_streaming_pass }}"
      role_attr_flags: replication
  - name: PRZYZNANIE UPRAWNIEŃ DO WYKONANIA NA FUNKCJI pg_XXX DLA barman_user
    community.postgresql.postgresql_privs:
      db: postgres
      privs: EXECUTE
      type: function
      obj: pg_start_backup(text:boolean:boolean),pg_stop_backup(),pg_stop_backup(boolean:boolean),pg_switch_wal(),pg_create_restore_point(text)
      schema: pg_catalog
      roles: "{{ barman_user }}"

# Ustawienie i konfiguracja Barmana
- hosts: barmans
  vars:
    barman_name: mypgserver
    barman_pg_hosts: 10.10.10.10
    barman_pg_ports: 5432
    barman_user: barman
    barman_pass: BARMANPASS_CHANGEME
    barman_streaming_user: streaming_barman
    barman_streaming_pass: STREAMINGPASS_CHANGEME
    barman_pg_servers:
    - name: "{{ barman_name }}"
      params:
      - description: "Baza danych PostgreSQL (Tylko Streaming)"
      - conninfo: 'host={{ barman_pg_hosts }} port={{ barman_pg_ports }} user={{ barman_user }} dbname=postgres'
      - streaming_conninfo: 'host={{ barman_pg_hosts }} port={{ barman_pg_ports }} user={{ barman_streaming_user }}'
      - backup_method: "postgres"
      - streaming_archiver: "on"
      - slot_name: "barman"
      - create_slot: "auto"
      - retention_policy: "okno odzyskiwania do 31 dni"
      pgpass:
      - "*:*:postgres:{{ barman_user }}:{{ barman_pass }}"
      - "*:*:replication:{{ barman_streaming_user }}:{{ barman_streaming_pass }}"
      backup_schedule:
        cron:
          hour: 21
          minute: 5
        s3_sync:
          src: "{{ barman_config['barman_home'] | default('/var/lib/barman') }}/{{ barman_name }}"
          dst: "s3://db-backup"
          base_cron:
            hour: 22
            minute: 5
          wals_cron:
            minute: 10
        custom:
          job: "barman delete '{{ barman_name }}' oldest"
          cron:
            hour: 23
            minute: 15
  roles:
  - giner.barman

Rozwój

Zainstaluj zależności do testów:

python3 -m pip install ansible -Ur requirements-molecule.txt

Uruchom wszystkie testy (wymaga zainstalowanego dockera):

molecule test --all

Licencja

Apache 2.0

Autorzy

Ten rożek został stworzony w 2021 roku przez Stanislav German-Evtushenko

O projekcie

Install and configure Barman on Linux with optional: metrics collection (telegraf), regular snapshots (cron) and uploading to S3 (cron)

Zainstaluj
ansible-galaxy install giner.barman
Licencja
apache-2.0
Pobrania
14.6k