You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.3 KiB
YAML

7 years ago
- name: install borg and tools
pacman: name=borg,perl-app-borgrestore state=present
- name: install borg-restore config
template: src=borg-restore.cfg.j2 dest=/etc/borg-restore.cfg owner=root group=root mode=0644
- name: check if borg repository already exists
command: borg list {{ backup_host }}:{{ backup_dir }}
register: borg_list
ignore_errors: True
- name: init borg repository
command: borg init -e keyfile {{ backup_host }}:{{ backup_dir }}
when: borg_list | failed
environment:
BORG_PASSPHRASE: ""
ignore_errors: True # This can sometimes fail if a backup is in progress :/
- name: install scripts
template: src={{item}}.j2 dest=/usr/local/bin/{{item}} owner=root group=root mode=0755
with_items:
- borg-backup.sh
- borg
- name: install postgres backup script
template: src=backup-postgres.sh.j2 dest=/usr/local/bin/backup-postgres.sh owner=root group=root mode=0755
when: postgres_backup_dir is defined
- name: check whether postgres user exists
command: getent passwd postgres
register: check_postgres_user
ignore_errors: True
- name: make postgres backup directory
file: path=/var/lib/postgres/backup owner=postgres group=postgres state=directory
when: check_postgres_user|succeeded and postgres_backup_dir is defined
- name: install mysql backup script
template: src=backup-mysql.sh.j2 dest=/usr/local/bin/backup-mysql.sh owner=root group=root mode=0755
when: mysql_backup_dir is defined
- name: install mysql backup config
template: src=backup-my.cnf.j2 dest={{mysql_backup_defaults}}
when: mysql_backup_defaults is defined
- name: create mysql backup directory
file: path={{mysql_backup_dir}} state=directory owner=root group=root
when: mysql_backup_dir is defined
- name: install xtrabackup for mysql backup
pacman: name=xtrabackup state=installed
when: mysql_backup_dir is defined
- name: install systemd timers for backup
copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
with_items:
- borg-backup.timer
- borg-backup.service
- name: activate systemd timers for backup
service: name=borg-backup.timer enabled=yes state=started
- name: enable systemd ressource accounting
command: systemctl set-property borg-backup CPUAccounting=yes MemoryAccounting=yes