├── .gitignore ├── tasks ├── main.yml ├── install.yml └── configure.yml ├── README.md ├── meta └── main.yml ├── defaults └── main.yml ├── templates └── barman.conf.j2 └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - include: install.yml 4 | tags: [barman2, barman-install] 5 | 6 | - include: configure.yml 7 | tags: [barman, barman-configure] 8 | -------------------------------------------------------------------------------- /tasks/install.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: install required barman packages 4 | apt: 5 | pkg: "{{ item }}" 6 | state: "{{ barman_package_state }}" 7 | with_items: "{{ barman_packages }}" 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | barman 2 | ====== 3 | 4 | This role configures Barman PostgreSQL backup utility. 5 | 6 | TODO 7 | ------- 8 | 9 | * Examples, variables, explanation 10 | 11 | License 12 | ------- 13 | 14 | LGPL 15 | 16 | Author Information 17 | ------------------ 18 | 19 | - Alexey Medvedchikov, 2GIS, LLC 20 | 21 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: 2GIS IT 4 | description: Role for PostgreSQL Backup and Restore manager -- barman 5 | min_ansible_version: 2.0.0 6 | license: LGPL 7 | platforms: 8 | - name: Ubuntu 9 | versions: 10 | - all 11 | categories: 12 | - database 13 | - postgresql 14 | 15 | dependencies: [] 16 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | barman_package_state: present 4 | 5 | barman_packages: 6 | - barman 7 | - bzip2 8 | - gzip 9 | - xz-utils 10 | 11 | # barman_ssh_private_key must be set 12 | # barman_ssh_public_key must be set 13 | 14 | barman_user: barman 15 | barman_home: /var/lib/barman 16 | barman_lock_directory: "{{ barman_home }}" 17 | barman_log_file: /var/log/barman/barman.log 18 | barman_compression: gzip 19 | barman_custom_compression_filter: "" 20 | barman_custom_decompression_filter: "" 21 | barman_reuse_backup: "off" 22 | barman_pre_backup_script: /bin/true 23 | barman_pre_backup_retry_script: /bin/true 24 | barman_post_backup_retry_script: /bin/true 25 | barman_post_backup_script: /bin/true 26 | barman_pre_archive_script: /bin/true 27 | barman_pre_archive_retry_script: /bin/true 28 | barman_post_archive_retry_script: /bin/true 29 | barman_post_archive_script: /bin/true 30 | barman_configuration_files_directory: /etc/barman.d 31 | barman_minimum_redundancy: 1 32 | barman_retention_policy: "" 33 | barman_wal_retention_policy: "main" 34 | barman_retention_policy_mode: "auto" 35 | barman_bandwidth_limit: 0 36 | barman_immediate_checkpoint: false 37 | barman_network_compression: false 38 | barman_backup_options: exclusive_backup 39 | barman_basebackup_retry_times: 0 40 | barman_basebackup_retry_sleep: 30 41 | barman_last_backup_maximum_age: "" 42 | 43 | # barman_servers: 44 | # - name: main 45 | # description: Main PostgreSQL Database 46 | # ssh_command: ssh postgres@pg 47 | # conn_host: pg 48 | # conn_port: 5432 49 | # conn_user: postgres 50 | # conn_password: 1qa2ws3ed 51 | # minimum_redundancy: "{{ barman_minimum_redundancy }}" 52 | # retention_policy: "" 53 | 54 | barman_servers: [] 55 | 56 | barman_backups_cron: [] 57 | 58 | # barman_backups_cron: 59 | # - name: main # It's a barman backup server which we should backuping 60 | # minute: 0 # Only this param is mandatory, other can be omitted 61 | # hour: 2 62 | # day: * 63 | # month: * 64 | # weekday: * 65 | # disabled: false 66 | # 67 | ## More information about cron: http://docs.ansible.com/ansible/cron_module.html 68 | -------------------------------------------------------------------------------- /tasks/configure.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: add password to .pgpass file 4 | lineinfile: 5 | dest: "~{{ barman_user }}/.pgpass" 6 | line: "{{ item.conn_host }}:{{ item.conn_port }}:*:{{ item.conn_user }}:{{ item.conn_password }}" 7 | owner: "{{ barman_user }}" 8 | create: yes 9 | mode: 0600 10 | with_items: "{{ barman_servers }}" 11 | 12 | - name: Create configuration files directory 13 | file: 14 | path: "{{ barman_configuration_files_directory }}" 15 | state: directory 16 | 17 | - name: Divert barman main configuration file /etc/barman.conf 18 | command: dpkg-divert --quiet --local --divert /etc/barman.conf.dpkg-divert --rename /etc/barman.conf 19 | args: 20 | creates: "/etc/barman.conf.dpkg-divert" 21 | 22 | - name: barman main configuration file /etc/barman.conf 23 | template: 24 | src: barman.conf.j2 25 | dest: /etc/barman.conf 26 | owner: "{{ barman_user }}" 27 | mode: 0640 28 | 29 | - name: create ssh directory 30 | file: 31 | path: ~{{ barman_user }}/.ssh 32 | owner: "{{ barman_user }}" 33 | mode: 0755 34 | state: directory 35 | 36 | - name: private ssh rsa key 37 | copy: 38 | dest: ~{{ barman_user }}/.ssh/id_rsa 39 | owner: "{{ barman_user }}" 40 | mode: 0600 41 | content: "{{ barman_ssh_private_key | mandatory }}" 42 | 43 | - name: public ssh rsa key 44 | copy: 45 | dest: ~{{ barman_user }}/.ssh/id_rsa.pub 46 | owner: "{{ barman_user }}" 47 | mode: 0600 48 | content: "{{ barman_ssh_public_key | mandatory }}" 49 | 50 | - name: ssh authorized keys 51 | lineinfile: 52 | dest: ~{{ barman_user }}/.ssh/authorized_keys 53 | create: yes 54 | owner: "{{ barman_user }}" 55 | mode: 0600 56 | line: "{{ barman_ssh_public_key | mandatory }}" 57 | 58 | - name: FIXME -- create incoming directory for wals 59 | file: 60 | path: "{{ barman_home }}/{{ item.name }}/incoming" 61 | state: directory 62 | owner: "{{ barman_user }}" 63 | mode: 0700 64 | with_items: "{{ barman_servers }}" 65 | 66 | - name: create cron job for backups 67 | cron: 68 | user: "{{ barman_user }}" 69 | name: "barman backup server {{ item.name }}" 70 | cron_file: barman_backup 71 | job: "[ -x /usr/bin/barman ] && /usr/bin/barman -q backup {{ item.name }}" 72 | state: present 73 | disabled: "{{ item.disabled | default(false) }}" 74 | minute: "{{ item.minute | mandatory }}" 75 | hour: "{{ item.hour | default(omit) }}" 76 | day: "{{ item.day | default(omit) }}" 77 | month: "{{ item.month | default(omit) }}" 78 | weekday: "{{ item.weekday | default(omit) }}" 79 | with_items: "{{ barman_backups_cron }}" 80 | -------------------------------------------------------------------------------- /templates/barman.conf.j2: -------------------------------------------------------------------------------- 1 | ; Barman, Backup and Recovery Manager for PostgreSQL 2 | ; http://www.pgbarman.org/ - http://www.2ndQuadrant.com/ 3 | ; 4 | ; Main configuration file 5 | 6 | [barman] 7 | ; Main directory 8 | barman_home = {{ barman_home }} 9 | 10 | ; Locks directory - default: %(barman_home)s 11 | barman_lock_directory = {{ barman_lock_directory }} 12 | 13 | ; System user 14 | barman_user = {{ barman_user }} 15 | 16 | ; Log location 17 | log_file = {{ barman_log_file }} 18 | 19 | ; Default compression level: possible values are None (default), bzip2, gzip or custom 20 | compression = {{ barman_compression }} 21 | custom_compression_filter = {{ barman_custom_compression_filter }} 22 | custom_decompression_filter = {{ barman_custom_decompression_filter }} 23 | 24 | ; Incremental backup support: possible values are None (default), link or copy 25 | reuse_backup = {{ barman_reuse_backup }} 26 | 27 | ; Pre/post backup hook scripts 28 | pre_backup_script = {{ barman_pre_backup_script }} 29 | pre_backup_retry_script = {{ barman_pre_backup_retry_script }} 30 | post_backup_retry_script = {{ barman_post_backup_retry_script }} 31 | post_backup_script = {{ barman_post_backup_script }} 32 | 33 | ; Pre/post archive hook scripts 34 | pre_archive_script = {{ barman_pre_archive_script }} 35 | pre_archive_retry_script = {{ barman_pre_archive_retry_script }} 36 | post_archive_retry_script = {{ barman_post_archive_retry_script }} 37 | post_archive_script = {{ barman_post_archive_script }} 38 | 39 | ; Directory of configuration files. Place your sections in separate files with .conf extension 40 | ; For example place the 'main' server section in /etc/barman.d/main.conf 41 | configuration_files_directory = {{ barman_configuration_files_directory }} 42 | 43 | ; Minimum number of required backups (redundancy) - default 0 44 | minimum_redundancy = {{ barman_minimum_redundancy }} 45 | 46 | ; Global retention policy (REDUNDANCY or RECOVERY WINDOW) - default empty 47 | retention_policy = {{ barman_retention_policy }} 48 | wal_retention_policy = {{ barman_wal_retention_policy }} 49 | retention_policy_mode = {{ barman_retention_policy_mode }} 50 | 51 | ; Global bandwidth limit in KBPS - default 0 (meaning no limit) 52 | bandwidth_limit = {{ barman_bandwidth_limit }} 53 | 54 | ; Immediate checkpoint for backup command - default false 55 | immediate_checkpoint = {{ barman_immediate_checkpoint }} 56 | 57 | ; Enable network compression for data transfers - default false 58 | network_compression = {{ barman_network_compression }} 59 | 60 | ; Identify the standard behavior for backup operations: possible values are 61 | ; exclusive_backup (default), concurrent_backup 62 | backup_options = {{ barman_backup_options }} 63 | 64 | ; Number of retries of data copy during base backup after an error - default 0 65 | basebackup_retry_times = {{ barman_basebackup_retry_times }} 66 | 67 | ; Number of seconds of wait after a failed copy, before retrying - default 30 68 | basebackup_retry_sleep = {{ barman_basebackup_retry_sleep }} 69 | 70 | ; Time frame that must contain the latest backup date. 71 | ; If the latest backup is older than the time frame, barman check 72 | ; command will report an error to the user. 73 | ; If empty, the latest backup is always considered valid. 74 | ; Syntax for this option is: "i (DAYS | WEEKS | MONTHS)" where i is an 75 | ; integer > 0 which identifies the number of days | weeks | months of 76 | ; validity of the latest backup for this check. Also known as 'smelly backup'. 77 | last_backup_maximum_age = {{ barman_last_backup_maximum_age }} 78 | 79 | ;; ; 'main' PostgreSQL Server configuration 80 | ;; [main] 81 | ;; ; Human readable description 82 | ;; description = "Main PostgreSQL Database" 83 | ;; 84 | ;; ; SSH options 85 | ;; ssh_command = ssh postgres@pg 86 | ;; 87 | ;; ; PostgreSQL connection string 88 | ;; conninfo = host=pg user=postgres 89 | ;; 90 | ;; ; Minimum number of required backups (redundancy) 91 | ;; ; minimum_redundancy = 1 92 | ;; 93 | ;; ; Examples of retention policies 94 | ;; 95 | ;; ; Retention policy (disabled) 96 | ;; ; retention_policy = 97 | ;; ; Retention policy (based on redundancy) 98 | ;; ; retention_policy = REDUNDANCY 2 99 | ;; ; Retention policy (based on recovery window) 100 | ;; ; retention_policy = RECOVERY WINDOW OF 4 WEEKS 101 | 102 | {% for server in barman_servers %} 103 | [{{ server.name }}] 104 | description = "{{ server.description }}" 105 | ssh_command = {{ server.ssh_command }} 106 | conninfo = host={{ server.conn_host }} port={{ server.conn_port }} user={{ server.conn_user }} 107 | minimum_redundancy = {{ server.minimum_redundancy }} 108 | retention_policy = {{ server.retention_policy }} 109 | 110 | {% endfor %} 111 | 112 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | --------------------------------------------------------------------------------