init commit borg
This commit is contained in:
1 parent
36ed650628
commit
e8430206a1
14 files changed
+105
-296
No files matched your search
Executable → Regular
+35
-27
@@ -1,38 +1,46 @@
|
||||
---
|
||||
- name: generate backup ssh user
|
||||
user:
|
||||
name: "{{ backup_owner }}"
|
||||
- name: Setup backup storage password
|
||||
copy:
|
||||
content: "{{ backup_storage_key }}"
|
||||
dest: "{{ backup_home }}/.borg.key"
|
||||
owner: "{{ backup_owner }}"
|
||||
group: "{{ backup_group }}"
|
||||
comment: Backup user
|
||||
shell: /bin/sh
|
||||
mode: "0600"
|
||||
|
||||
- name: Setup User ssh_key
|
||||
authorized_key:
|
||||
user: "{{ backup_owner }}"
|
||||
key: "{{ backup_owner_ssh_key }}"
|
||||
- name: Setup ssh folder
|
||||
file:
|
||||
state: directory
|
||||
path: "{{ backup_home }}/.ssh"
|
||||
owner: "{{ backup_owner }}"
|
||||
group: "{{ backup_group }}"
|
||||
mode: "0700"
|
||||
|
||||
- name: generate config lists
|
||||
template:
|
||||
src: backup/conf/{{ conf }}.list.j2
|
||||
dest: "{{ backup_conf }}/{{ conf }}.list"
|
||||
- name: Setup ssh keys
|
||||
copy:
|
||||
content: "{{ item.content }}"
|
||||
dest: "{{ backup_home }}/.ssh/{{ item.file }}"
|
||||
owner: "{{ backup_owner }}"
|
||||
group: "{{ backup_group }}"
|
||||
mode: "0600"
|
||||
loop:
|
||||
- filedir
|
||||
- db
|
||||
- mail
|
||||
- content: "{{ backup_owner_ssh_private_key }}"
|
||||
file: "id_rsa"
|
||||
- content: "{{ backup_owner_ssh_public_key }}"
|
||||
file: "id_rsa.pub"
|
||||
loop_control:
|
||||
loop_var: conf
|
||||
label: "{{ conf }}.list"
|
||||
label: "{{ item.file }}"
|
||||
|
||||
- name: setup backup script
|
||||
template:
|
||||
src: backup/backup_on_client.sh.j2
|
||||
dest: "{{ backup_folder }}/backup.sh"
|
||||
mode: 0740
|
||||
src: "./usr/local/bin/{{ backup_host }}-backup.sh.j2"
|
||||
dest: "/usr/local/bin/backup.sh"
|
||||
owner: "{{ backup_owner }}"
|
||||
group: "{{ backup_group }}"
|
||||
mode: "0750"
|
||||
|
||||
- name: setup cronjob for client backup generation
|
||||
- name: setup cron backup job
|
||||
cron:
|
||||
name: "backup"
|
||||
weekday: "{{ backup_times_weekday }}"
|
||||
hour: "{{ backup_times_hour | join(',') }}"
|
||||
minute: "{{ backup_times_minute }}"
|
||||
job: "{{ backup_folder }}/backup.sh"
|
||||
name: "{{ backup_host }} backup"
|
||||
user: "{{ backup_cron_owner }}"
|
||||
job: "/usr/local/bin/backup.sh"
|
||||
special_time: "{{ backup_cron_specialtime }}"
|
||||
+28
-19
@@ -1,34 +1,43 @@
|
||||
---
|
||||
# Basics
|
||||
- name: install requirements for backup system
|
||||
apt:
|
||||
update_cache: yes
|
||||
state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}"
|
||||
install_recommends: yes
|
||||
pkg:
|
||||
- rsync
|
||||
- borgbackup
|
||||
|
||||
- name: setup storage folders for backup
|
||||
- name: setup backup location
|
||||
file:
|
||||
state: directory
|
||||
path: "{{ dir.value.path }}"
|
||||
path: "{{ backup_root }}"
|
||||
owner: "root"
|
||||
group: "root"
|
||||
mode: "0755"
|
||||
|
||||
- name: Setup required groups of users
|
||||
group:
|
||||
name: "{{ backup_group }}"
|
||||
state: present
|
||||
|
||||
- name: generate backup user
|
||||
user:
|
||||
name: "{{ backup_owner }}"
|
||||
group: "{{ backup_group }}"
|
||||
comment: backup user
|
||||
shell: /sbin/nologin
|
||||
home: "{{ backup_home }}"
|
||||
|
||||
- name: setup backup storage
|
||||
file:
|
||||
state: directory
|
||||
path: "{{ backup_storage }}"
|
||||
owner: "{{ backup_owner }}"
|
||||
group: "{{ backup_group }}"
|
||||
mode: "{{ backup_permission }}"
|
||||
with_dict: "{{ backup_storage }}"
|
||||
loop_control:
|
||||
loop_var: dir
|
||||
label: "{{ dir.key }}"
|
||||
mode: "0777"
|
||||
|
||||
- name: setup conf folder
|
||||
file:
|
||||
state: directory
|
||||
path: "{{ backup_folder }}/conf"
|
||||
- include_tasks: master.yml
|
||||
when: not backup_client
|
||||
|
||||
- name: setup client backup structure
|
||||
include_tasks: client.yml
|
||||
- include_tasks: client.yml
|
||||
when: backup_client
|
||||
|
||||
- name: setup server backup structure
|
||||
include_tasks: server.yml
|
||||
when: not backup_client
|
||||
@@ -0,0 +1 @@
|
||||
---
|
||||
@@ -1,27 +0,0 @@
|
||||
---
|
||||
- name: analyse backup hours for pulling server
|
||||
set_fact:
|
||||
backup_times_server_hour: "{{ backup_times_server_hour | default([]) + [item + backup_hour_shift] }}"
|
||||
loop: "{{ backup_times_hour }}"
|
||||
|
||||
- name: generate backup user ssh key
|
||||
user:
|
||||
name: "{{ backup_owner }}"
|
||||
generate_ssh_key: yes
|
||||
ssh_key_type: rsa
|
||||
ssh_key_bits: 4096
|
||||
home: "{{ backup_folder }}"
|
||||
|
||||
- name: template main server backup pull script
|
||||
template:
|
||||
src: backup/backup_from_clients.sh.j2
|
||||
dest: "{{ backup_folder }}/pull-backup.sh"
|
||||
mode: 0740
|
||||
|
||||
- name: setup cronjob for server backup pull
|
||||
cron:
|
||||
name: "pull backups"
|
||||
weekday: "{{ backup_times_weekday }}"
|
||||
hour: "{{ backup_times_server_hour | join(',') }}"
|
||||
minute: "{{ backup_times_minute }}"
|
||||
job: "{{ backup_folder }}/pull-backup.sh"
|
||||
Reference in new issue
Block a user