| Install and configure rsnapshot.
Easy, everyone needs backups. :) And keep in mind: No Backup, No Mercy
Install from Ansible Galaxy
ansible-galaxy install while_true_do.rsnapshot
Install from Github
git clone https://github.com/while-true-do/ansible-role-rsnapshot.git while_true_do.rsnapshot
Used Modules:
# defaults/main.yml
wtd_rsnapshot_state: "present"
wtd_rsnapshot_packages: "rsnapshot"
wtd_rsnapshot_config_version: 1.2
wtd_rsnapshot_config_snapshot_root: "/backup"
wtd_rsnapshot_config_cmd_rm: "/usr/bin/rm"
wtd_rsnapshot_config_cmd_rsync: "/usr/bin/rsync"
wtd_rsnapshot_config_cmd_logger: "/usr/bin/logger"
wtd_rsnapshot_config_retains:
- name: "alpha"
value: "6"
- name: "beta"
value: "7"
- name: "gamma"
value: "4"
- name: "delta"
value: "3"
wtd_rsnapshot_config_verbose: 3
wtd_rsnapshot_config_loglevel: 3
wtd_rsnapshot_config_logfile: "/var/log/rsnapshot"
wtd_rsnapshot_config_lockfile: "/var/run/rsnapshot.pid"
wtd_rsnapshot_config_backups:
- backup: /home/
target: localhost/
Simple Example:
- hosts: servers
roles:
- { role: while_true_do.rsnapshot }
vars:
- wtd_rsnapshot_config_shapshot_root: '/backup/'
- wtd_rsnapshot_config_retains:
- name: 'daily'
value: '7'
- wtd_rsnapshot_config_backups:
- backup: /home/cinux
target: home/
Advanced Example:
rsnapshot is not designed to run multiple instance at the same time by using one config-file.
Because of this its possible to set the wtd_rsnapshot_config_multi_enabled
to true
and configure multiple configurations of rsnapshot include systemd timers and services.
Below you find a playbook with variable to get an illustration how the role works if you want to use multiple configurations.
NOTE: Please only run this playbook in a test machine. Its for testing purpose.
- hosts: testmachine
become: yes
tasks:
- name: create folders
file:
path: "{{ item }}"
state: directory
with_items:
- /media/Share
- /media/Audio
- /media/Videos
- /media/ISOs
- hosts: $VMIP
become: yes
roles:
- { role: while_true_do.rsnapshot }
vars:
- wtd_rsnapshot_config_multi_enabled: true
- wtd_rsnapshot_config_multi:
- name: Backup_etc_systemd
retains:
- name: daily
value: '7'
backups:
- src: /etc/systemd
target: localhost/
execStart: "/usr/bin/rsnapshot -c /etc/rsnapshot-Backup_etc_systemd.conf %i"
logfile: "/var/log/rsnapshot-Backup_etc_systemd"
- name: homes
retains:
- name: hourly
value: '12'
time: '*-*-* *:24:00'
- name: montly
value: '3'
time: '1-*-* 00:00:00'
backups:
- src: /home/
target: homes/
snapshot_root: '/backup_home'
execStart: "/usr/bin/rsnapshot -c /etc/rsnapshot-homes.conf %i"
logfile: "/var/log/rsnapshot-homes"
- wtd_rsnapshot_config_snapshot_root: /backup
- wtd_rsnapshot_timer_time: "*-*-* 00:00:00"
After you have execute the playbook you can check with following commands:
systemctl list-timers | grep rsnapshot
ls -la /etc/rsnapshot-*
For each entry a separate configuration file gets created under /etc/rsnapshot-*. Additionally to this for each retains a timer will be created. And of course you can create for each retains a different time. This helps to run different retains at different times. Its also possible to set a default time by set wtd_rsnapshot_timer_time, but the time of a retain will overwrite it (can be seen in the above example by "Backup_etc_systemd"
Following variables, started with wtd_rsnapshot_config get overwritten by wtd_rsnapshot_config_multi if defined:
- config_version
- snapshot_root
- verbose
- loglevel
- lockfile
- timer
All tests are located in test directory.
Basic testing:
bash ./tests/test-spelling.sh
bash ./tests/test-ansible.sh
Thank you so much for considering to contribute. Every contribution helps us. We are really happy, when somebody is joining the hard work. Please have a look at the links first.
This work is licensed under a BSD License.
Site: while-true-do.org
Mail: [email protected]