First commit
This commit is contained in:
11
roles/borg-client/defaults/main.yml
Normal file
11
roles/borg-client/defaults/main.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
borg_pass: !vault |
|
||||
$ANSIBLE_VAULT;1.1;AES256
|
||||
62333166623737363731663766353330633335306532306366356536376232396664376430613434
|
||||
3966376539303238376461386262663066376338386537660a376365643761653463393539316232
|
||||
30653130383761653432306136333733653062356635643662616133366663646132383136313530
|
||||
3866343664393330610a623930316330626166343934623230313232626131386132393866373661
|
||||
6336
|
||||
borg_backup_path: ["/srv", "/home", "/etc"]
|
||||
borg_backup_excluded_path: ["/srv/NOBACKUP"]
|
||||
borg_backup_hour: 6
|
||||
borg_backup_minute: 0
|
26
roles/borg-client/tasks/main.yml
Normal file
26
roles/borg-client/tasks/main.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
- name: create SSH key
|
||||
openssh_keypair:
|
||||
path: ~/.ssh/id_rsa
|
||||
|
||||
- name: get SSH pub key
|
||||
command: cat ~/.ssh/id_rsa.pub
|
||||
register: ssh_keys
|
||||
|
||||
- name: put backup script
|
||||
template:
|
||||
src: borgbackup.sh.j2
|
||||
dest: /usr/local/bin/borgbackup.sh
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0750'
|
||||
|
||||
- name: cron the backup script
|
||||
cron:
|
||||
name: "borg backup script"
|
||||
hour: "{{ borg_backup_hour }}"
|
||||
minute: "{{ borg_backup_minute }}"
|
||||
job: /usr/local/bin/borgbackup.sh
|
||||
|
||||
- name: warns about borg init
|
||||
debug:
|
||||
msg: "Borg has been installed. Don’t forget to init with: \nborg init --encryption=repokey-blake2 backup@{{ hostvars[groups['borg_server'][0]]['ansible_fqdn'] }}:home"
|
20
roles/borg-client/templates/borgbackup.sh.j2
Normal file
20
roles/borg-client/templates/borgbackup.sh.j2
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
## Variable
|
||||
export BORG_PASSPHRASE="{{ borg_pass }}"
|
||||
|
||||
## lancement de la sauvegarde
|
||||
borg create --exclude-caches {% for f in borg_backup_excluded_path %}-e {{ f }} {% endfor %} -s backup@{{ hostvars[groups['borg_server'][0]]['ansible_fqdn'] }}:home::{now:%Y-%m-%d} {% for f in borg_backup_path %}{{ f }} {% endfor %}
|
||||
|
||||
|
||||
## récupération de l'espace
|
||||
borg prune -d 7 -w 4 -m 3 backup@{{ hostvars[groups['borg_server'][0]]['ansible_fqdn'] }}:home
|
||||
|
||||
{% if inventory_hostname == 'n0box2.mateu.be' %}
|
||||
## la sauvegarde mais chez Holaf
|
||||
borg create -s ssh://mortal@holaf.duckdns.org:22222/home/mortal/repos/n0box2.mateu.be/home::{now:%Y-%m-%d} /etc /home /srv
|
||||
|
||||
## la sauvegarde mais chez Holaf
|
||||
borg prune -d 7 -w 4 -m 3 ssh://mortal@holaf.duckdns.org:22222/home/mortal/repos/n0box2.mateu.be/home
|
||||
|
||||
{% endif %}
|
Reference in New Issue
Block a user