|
@@ -0,0 +1,88 @@
|
|
1
|
+
|
|
2
|
+- name: Install Borg-Backup, NFS Tools and their dependencies
|
|
3
|
+ apt:
|
|
4
|
+ name: "{{ packages }}"
|
|
5
|
+ state: present
|
|
6
|
+ vars:
|
|
7
|
+ packages:
|
|
8
|
+ - borgbackup
|
|
9
|
+ - nfs-common
|
|
10
|
+ - python-pexpect
|
|
11
|
+ tags:
|
|
12
|
+ - dependencies
|
|
13
|
+
|
|
14
|
+- name: Remove static route over VPN on shutdown
|
|
15
|
+ lineinfile:
|
|
16
|
+ path: /etc/network/interfaces.d/50-cloud-init.cfg
|
|
17
|
+ insertafter: "iface eth0 inet dhcp"
|
|
18
|
+ line: "pre-down ip route del {{ backup_vpn_net }} via {{ backup_vpn_bridge }} || true"
|
|
19
|
+
|
|
20
|
+- name: Add static route over VPN on boot
|
|
21
|
+ lineinfile:
|
|
22
|
+ path: /etc/network/interfaces.d/50-cloud-init.cfg
|
|
23
|
+ insertafter: "iface eth0 inet dhcp"
|
|
24
|
+ line: "post-up ip route add {{ backup_vpn_net }} via {{ backup_vpn_bridge }} || true"
|
|
25
|
+
|
|
26
|
+- name: Apply static route for current session
|
|
27
|
+ command: "ip route add {{ backup_vpn_net }} via {{ backup_vpn_bridge }}"
|
|
28
|
+ ignore_errors: yes
|
|
29
|
+
|
|
30
|
+- name: Creates directory for NFS mount
|
|
31
|
+ file:
|
|
32
|
+ path: "{{ backup_repo_dir }}"
|
|
33
|
+ state: directory
|
|
34
|
+ owner: root
|
|
35
|
+ group: root
|
|
36
|
+ ignore_errors: yes
|
|
37
|
+
|
|
38
|
+- name: Add NFS mount to /etc/fstab
|
|
39
|
+ lineinfile:
|
|
40
|
+ path: /etc/fstab
|
|
41
|
+ line: "{{ backup_host }}:{{ backup_share }} {{ backup_repo_dir }} nfs rw,async,hard,intr,noexec 0 0"
|
|
42
|
+
|
|
43
|
+- name: Mount NFS share
|
|
44
|
+ mount:
|
|
45
|
+ path: "{{ backup_repo_dir }}"
|
|
46
|
+ src: "{{ backup_host }}:{{ backup_share }}"
|
|
47
|
+ fstype: "nfs"
|
|
48
|
+ state: mounted
|
|
49
|
+
|
|
50
|
+- name: Create Borg Repo
|
|
51
|
+ expect:
|
|
52
|
+ chdir: "{{ backup_repo_dir }}"
|
|
53
|
+ creates: "{{ backup_destination }}"
|
|
54
|
+ command: "borg init --encryption=repokey {{ backup_repo_name }}"
|
|
55
|
+ responses:
|
|
56
|
+ "Enter new passphrase": "{{ backup_borg_passphrase }}"
|
|
57
|
+ "Enter same passphrase again": "{{ backup_borg_passphrase }}"
|
|
58
|
+ "Do you want your passphrase to be displayed for verification": "y"
|
|
59
|
+
|
|
60
|
+- name: Dump Borg Repo Key
|
|
61
|
+ command: borg key export {{ backup_destination }} /home/deploy/borg_repo_key
|
|
62
|
+
|
|
63
|
+- name: Dump Borg Repo Key
|
|
64
|
+ fetch:
|
|
65
|
+ src: /home/deploy/borg_repo_key
|
|
66
|
+ dest: "{{ secret }}/borg_repo_key"
|
|
67
|
+ fail_on_missing: yes
|
|
68
|
+
|
|
69
|
+- name: Remove Borg Repo Key dump
|
|
70
|
+ command: rm -rf /home/deploy/borg_repo_key
|
|
71
|
+
|
|
72
|
+- name: Unmount NFS share
|
|
73
|
+ command: "umount -l {{ backup_repo_dir }}"
|
|
74
|
+
|
|
75
|
+- name: Copy backup script
|
|
76
|
+ template:
|
|
77
|
+ src: home_deploy_backup-root_sh.j2
|
|
78
|
+ dest: /home/deploy/backup-root.sh
|
|
79
|
+ owner: root
|
|
80
|
+ group: root
|
|
81
|
+ mode: 0500
|
|
82
|
+
|
|
83
|
+- name: Configure daily backup cronjob
|
|
84
|
+ cron:
|
|
85
|
+ hour: "1"
|
|
86
|
+ minute: "0"
|
|
87
|
+ job: /home/deploy/backup-root.sh
|
|
88
|
+ name: "nas-backup"
|