giner.barman

Tests ausführen

Ansible-Rolle: Barman

Installiert und konfiguriert Barman auf Linux mit optionalen Funktionen:

  • Regelmäßige Backups (über Cron ausgeführt)
  • Hochladen von WALs und Snapshots zu S3 (über Cron ausgeführt)
  • Metrik-Sammlung (durch Telegraf)

Diese Rolle soll so unvoreingenommen wie möglich sein, d.h. alle Konfigurationsparameter werden direkt an die Barman-Konfigurationen weitergegeben.

Anforderungen

  • Ubuntu

Installation

Installiere über Ansible Galaxy:

ansible-galaxy collection install giner.barman

Oder füge diese Rolle in deine requirements.yml Datei ein:

roles:
  - name: giner.barman

Rollenvariablen

Verfügbare Variablen sind unten aufgeführt, zusammen mit den Standardwerten (siehe defaults/main.yml):

Der angeforderte Zustand von Barman. Überschreibe mit absent, um Barman zu deinstallieren. Daten werden nicht entfernt.

barman_state: started

Der angeforderte Zustand des Barman-Pakets. Überschreibe mit latest, um Barman zu aktualisieren.

barman_package_state: present

Globale Konfigurationsüberschreibungen für Barman (schlüssel/wert).

barman_config: {}

PostgreSQL-Server, die gesichert werden sollen.

barman_pg_servers: []    # Die Schlüssel sind: name, params, pgpass und cron. Siehe ein Beispiel unten.

Telegraf konfigurieren, um Barman-Metriken zu sammeln.

barman_telegraf_enabled: false

Intervall für die Metriksammlung.

barman_telegraf_interval: 1m

Abhängigkeiten

Keine.

Beispiel-Playbook

# Benutzer und ihre Berechtigungen auf dem PostgreSQL-Datenbankserver konfigurieren
# 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: PostgreSQL-Benutzer barman_user hinzufügen
    community.postgresql.postgresql_user:
      user: "{{ barman_user }}"
      password: "{{ barman_pass }}"
      role_attr_flags: replication
      groups: [pg_read_all_settings, pg_read_all_stats]
  - name: PostgreSQL-Benutzer barman_streaming_user hinzufügen
    community.postgresql.postgresql_user:
      user: "{{ barman_streaming_user }}"
      password: "{{ barman_streaming_pass }}"
      role_attr_flags: replication
  - name: Ausführungsberechtigungen für die Funktion pg_XXX an barman_user gewähren
    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 }}"

# Barman einrichten und konfigurieren
- 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: "PostgreSQL-Datenbank (nur 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: "Wiederherstellungszeitraum von 31 Tagen"
      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

Entwicklung

Teste Abhängigkeiten installieren:

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

Alle Tests ausführen (erfordert Docker):

molecule test --all

Lizenz

Apache 2.0

Autoren

Diese Rolle wurde 2021 von Stanislav German-Evtushenko erstellt.

Über das Projekt

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

Installieren
ansible-galaxy install giner.barman
GitHub Repository
Lizenz
apache-2.0
Downloads
14.6k