main.yml 2.64 KB
Newer Older
1
2
---

3
4
- name: install borg and tools
  pacman: name=borg,perl-app-borgrestore state=present
5

6
7
8
- name: install borg-restore config
  template: src=borg-restore.cfg.j2 dest=/etc/borg-restore.cfg owner=root group=root mode=0644

9
- name: check if borg repository already exists
10
11
12
  command: borg list {{ item['host'] }}/{{ item['dir'] }}
  environment:
    BORG_RELOCATED_REPO_ACCESS_IS_OK: "yes"
13
14
  register: borg_list
  ignore_errors: True
15
  loop: "{{ backup_hosts }}"
16
  changed_when: borg_list.stdout | length > 0
17
18

- name: init borg repository
19
  command: borg init -e keyfile {{ item['host'] }}/{{ item['dir'] }}
20
  when: borg_list is failed
21
22
  environment:
    BORG_PASSPHRASE: ""
23
  ignore_errors: True # This can sometimes fail if a backup is in progress :/
24
  loop: "{{ backup_hosts }}"
25

26
27
28
29
30
31
32
- name: install convenience scripts
  template: src=borg.j2 dest=/usr/local/bin/borg{{ item['suffix'] }} owner=root group=root mode=0755
  loop: "{{ backup_hosts }}"

- name: install borg backup scripts
  template: src=borg-backup.sh.j2 dest=/usr/local/bin/borg-backup{{ item['suffix'] }}.sh owner=root group=root mode=0755
  loop: "{{ backup_hosts }}"
33

34
- name: install postgres backup script
35
  template: src=backup-postgres.sh.j2 dest=/usr/local/bin/backup-postgres.sh owner=root group=root mode=0755
36
  when: postgres_backup_dir is defined
37
38
39
40
41

- name: check whether postgres user exists
  command: getent passwd postgres
  register: check_postgres_user
  ignore_errors: True
42
  changed_when: check_postgres_user.stdout | length > 0
43
44

- name: make postgres backup directory
45
  file: path={{ postgres_backup_dir }} owner=root group=root state=directory
46
  when: check_postgres_user is succeeded and postgres_backup_dir is defined
47

Florian Pritz's avatar
Florian Pritz committed
48
49
- name: install mysql backup script
  template: src=backup-mysql.sh.j2 dest=/usr/local/bin/backup-mysql.sh owner=root group=root mode=0755
50
  when: mysql_backup_dir is defined
Florian Pritz's avatar
Florian Pritz committed
51
52

- name: install mysql backup config
53
  template: src=backup-my.cnf.j2 dest={{ mysql_backup_defaults }}
54
  when: mysql_backup_defaults is defined
Florian Pritz's avatar
Florian Pritz committed
55
56

- name: create mysql backup directory
57
  file: path={{ mysql_backup_dir }} state=directory owner=root group=root
58
  when: mysql_backup_dir is defined
Florian Pritz's avatar
Florian Pritz committed
59

60
61
62
63
- name: install gitlab backup script
  template: src=backup-gitlab.sh.j2 dest=/usr/local/bin/backup-gitlab.sh owner=root group=root mode=0755
  when: inventory_hostname == "gitlab.archlinux.org"

64
65
- name: install systemd timer and service for backup
  template: src={{ item }}.j2 dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
66
67
68
69
70
  with_items:
    - borg-backup.timer
    - borg-backup.service

- name: activate systemd timers for backup
71
  systemd: name=borg-backup.timer enabled=yes state=started daemon-reload=yes