1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_restic_archiver.git synced 2024-08-16 10:09:49 +02:00

implement logrotate

This commit is contained in:
L3D 2020-12-14 15:50:39 +01:00 committed by Lilian Roller
parent 3583b99f2e
commit 80baa38a8a
No known key found for this signature in database
GPG key ID: 5215C3441797AB2B
8 changed files with 73 additions and 63 deletions

View file

@ -67,6 +67,9 @@ restic_archiver__umount_after_usage: false
restic_archiver__package:
- cron
restic_archiver__log_output: true
restic_archiver__logrotate: true
# version check for this playbook (true is recomended)
submodules_versioncheck: false
```

View file

@ -46,5 +46,8 @@ restic_archiver__umount_after_usage: false
restic_archiver__package:
- cron
restic_archiver__log_output: true
restic_archiver__logrotate: true
# version check for this playbook (true is recomended)
submodules_versioncheck: false

8
files/logrotate.conf Normal file
View file

@ -0,0 +1,8 @@
/var/log/restic/restic_archiver.log {
rotate 182
daily
compress
delaycompress
missingok
notifempty
}

28
tasks/cron.yml Normal file
View file

@ -0,0 +1,28 @@
---
- name: install cron
become: true
package:
name: "{{ restic_archiver__package }}"
state: present
- name: setup cronjob for restic with logging
become: true
cron:
name: "archive restic backup with ansible_role_restic_archiver >> /var/log/restic/restic_archiver.log"
job: /opt/restic-backup.sh
cron_file: /etc/crontab
hour: "{{ restic_archiver__hour }}"
minute: "{{ restic_archiver__minute }}"
user: "{{ restic_archiver__owner }}"
when: restic_archiver__log_output
- name: setup cronjob for restic without logging
become: true
cron:
name: "archive restic backup with ansible_role_restic_archiver"
job: /opt/restic-backup.sh
cron_file: /etc/crontab
hour: "{{ restic_archiver__hour }}"
minute: "{{ restic_archiver__minute }}"
user: "{{ restic_archiver__owner }}"
when: not restic_archiver__log_output

27
tasks/logs.yml Normal file
View file

@ -0,0 +1,27 @@
---
- name: create /var/log/restic/
become: true
file:
path: /var/log/restic
state: directory
recurse: true
group: "{{ restic_archiver__owner }}"
owner: "{{ restic_archiver__group }}"
mode: 0750
- name: install logrotate
become: true
package:
name: logrotate
state: present
when: restic_archiver__logrotate | bool
- name: create logrotate config
become: true
copy:
src: files/logrotate.conf
dest: /etc/logrotate.d/restic
group: "{{ restic_archiver__owner }}"
owner: "{{ restic_archiver__group }}"
mode: 0644
when: restic_archiver__logrotate | bool

View file

@ -11,18 +11,7 @@
mode: 0700
become: true
- name: install cron
become: true
package:
name: "{{ restic_archiver__package }}"
state: present
- include_tasks: logs.yml
when: restic_archiver__log_output | bool
- name: setup cronjob for restic
become: true
cron:
name: "archive restic backup with ansible_role_restic_archiver"
job: /opt/restic-backup.sh
cron_file: /etc/crontab
hour: "{{ restic_archiver__hour }}"
minute: "{{ restic_archiver__minute }}"
user: "{{ restic_archiver__owner }}"
- include_tasks: cron.yml

View file

@ -1,48 +0,0 @@
---
#- name: Create backup credentials
# template:
# src: restic_access_Linux.j2
# dest: '{{ restic_script_dir }}/access-{{ item.name }}.sh'
# mode: '0700'
# owner: '{{ restic_dir_owner }}'
# group: '{{ restic_dir_group }}'
# no_log: true
# with_items: '{{ restic_archiver__backups }}'
# when:
# - item.name is defined
# - item.src is defined or item.stdin is defined
# - item.src is defined or item.stdin and item.stdin_cmd is defined
# - item.repo in restic_repos
#
#- name: Create backup script
# template:
# src: restic_script_Linux.j2
# dest: '{{ restic_script_dir }}/backup-{{ item.name }}.sh'
# mode: '0700'
# owner: '{{ restic_dir_owner }}'
# group: '{{ restic_dir_group }}'
# no_log: true
# with_items: '{{ restic_archiver__backups }}'
# when:
# - item.name is defined
## - item.src is defined or item.stdin is defined
# - item.src is defined or item.stdin and item.stdin_cmd is defined
# - item.repo in restic_repos
#
#- name: Setup CRON jobs
# cron:
# name: 'do1jlr.restic_archiver {{ item.name }}'
## job: 'CRON=true {{ restic_script_dir }}/backup-{{ item.name }}.sh'
# minute: '{{ item.schedule_minute | default("*") }}'
# hour: '{{ item.schedule_hour | default("*") }}'
# weekday: '{{ item.schedule_weekday | default("*") }}'
# month: '{{ item.schedule_month | default("*") }}'
# cron_file: '/etc/crontab'
# state: present
# become: true
# no_log: true
## with_items: '{{ restic_archiver__backups }}'
# when:
# - restic_create_cron
# - item.name is defined
# - item.scheduled | default(false)

View file

@ -1,3 +1,3 @@
---
playbook_version_number: 28 # should be over ninethousand
playbook_version_number: 29 # should be over ninethousand
playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version'