main.yml 2.57 KB
Newer Older
1
---
2
- name: install borg and tools
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
3
  pacman: name=borg state=present
4

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

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

22
23
24
25
26
27
28
- 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 }}"
29

30
- name: install postgres backup script
31
  template: src=backup-postgres.sh.j2 dest=/usr/local/bin/backup-postgres.sh owner=root group=root mode=0755
32
  when: postgres_backup_dir is defined
33
34
35
36
37

- name: check whether postgres user exists
  command: getent passwd postgres
  register: check_postgres_user
  ignore_errors: True
38
  changed_when: check_postgres_user.stdout | length > 0
39
40

- name: make postgres backup directory
41
  file: path={{ postgres_backup_dir }} owner=root group=root mode=0755 state=directory
42
  when: check_postgres_user is succeeded and postgres_backup_dir is defined
43

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

- name: install mysql backup config
49
  template: src=backup-my.cnf.j2 dest={{ mysql_backup_defaults }} owner=root group=root mode=0644
50
  when: mysql_backup_defaults is defined
Florian Pritz's avatar
Florian Pritz committed
51
52

- name: create mysql backup directory
53
  file: path={{ mysql_backup_dir }} state=directory owner=root group=root mode=0755
54
  when: mysql_backup_dir is defined
Florian Pritz's avatar
Florian Pritz committed
55

56
57
58
59
- 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"

60
- name: install systemd timer and service for backup
61
  copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
62
63
64
  with_items:
    - borg-backup.timer
    - borg-backup.service
65
    - borg-backup-offsite.service
66
67

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