diff --git a/rsnapshot/defaults/main.yml b/rsnapshot/defaults/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..47c45ef8926e314fcd28fe877362391607a044ce --- /dev/null +++ b/rsnapshot/defaults/main.yml @@ -0,0 +1,3 @@ +--- + +rsnapshot_enable_frequently: true diff --git a/rsnapshot/files/list-rsnapshot-config-files.sh b/rsnapshot/files/list-rsnapshot-config-files.sh new file mode 100644 index 0000000000000000000000000000000000000000..487652c83ee3250af08ef9829732b0356bca25c1 --- /dev/null +++ b/rsnapshot/files/list-rsnapshot-config-files.sh @@ -0,0 +1,4 @@ +#!/bin/sh +for file in /etc/rsnapshot.d/*.conf; do + echo "include_conf $file" +done diff --git a/rsnapshot/tasks/main.yml b/rsnapshot/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..86dfd49bf7d669c65d2afe69a52fb1418a2fa36a --- /dev/null +++ b/rsnapshot/tasks/main.yml @@ -0,0 +1,38 @@ +--- + +- name: install rsnapshot + apt: + name: rsnapshot + state: present + +- name: create drop-in directory for backup config + file: + path: /etc/rsnapshot.d + state: directory + owner: root + group: root + mode: '0755' + +- name: create script for rsnapshot's crazy include_conf to work + copy: + src: "list-rsnapshot-config-files.sh" + dest: "/usr/local/bin" + owner: root + group: root + mode: '0755' + +- name: configure rsnapshot + template: + src: rsnapshot.conf.j2 + dest: /etc/rsnapshot.conf + owner: root + group: root + mode: '0644' + +- name: make rsnapshot run regularly + template: + src: crontab.j2 + dest: /etc/cron.d/rsnapshot + owner: root + group: root + mode: '0644' diff --git a/rsnapshot/templates/crontab.j2 b/rsnapshot/templates/crontab.j2 new file mode 100644 index 0000000000000000000000000000000000000000..e6cfe4fe48ddaa3990153a5a7c9dda2cc7cb68ca --- /dev/null +++ b/rsnapshot/templates/crontab.j2 @@ -0,0 +1,7 @@ +{% if rsnapshot_enable_frequently %} +5,20,35,50 * * * * root /usr/bin/rsnapshot -c /etc/rsnapshot.conf frequently +{% endif %} +3 * * * * root /usr/bin/rsnapshot -c /etc/rsnapshot.conf hourly +51 23 * * * root /usr/bin/rsnapshot -c /etc/rsnapshot.conf daily +41 23 * * 6 root /usr/bin/rsnapshot -c /etc/rsnapshot.conf weekly +31 23 2 * * root /usr/bin/rsnapshot -c /etc/rsnapshot.conf monthly diff --git a/rsnapshot/templates/rsnapshot.conf.j2 b/rsnapshot/templates/rsnapshot.conf.j2 new file mode 100644 index 0000000000000000000000000000000000000000..381b296ceba7a8d46caf5ece3f52642eeb775ecb --- /dev/null +++ b/rsnapshot/templates/rsnapshot.conf.j2 @@ -0,0 +1,22 @@ +config_version 1.2 +snapshot_root /var/backups + +include_conf `/usr/local/bin/list-rsnapshot-config-files.sh` + +cmd_cp /bin/cp +cmd_rm /bin/rm +cmd_rsync /usr/bin/rsync +cmd_logger /usr/bin/logger +cmd_du /usr/bin/du + +{% if rsnapshot_enable_frequently %} +retain frequently 4 +{% endif %} +retain hourly 6 +retain daily 7 +retain weekly 4 +retain monthly 6 + +verbose 2 +loglevel 4 +lockfile /run/rsnapshot.pid