1
0
mirror of https://github.com/krislamo/puppet-rsnapshot synced 2024-12-16 09:40:35 +00:00
puppet-rsnapshot/README.md

558 lines
13 KiB
Markdown
Raw Normal View History

2015-12-19 10:16:05 +00:00
# rsnapshot
## NOTE: ! Configuration for backup_scripts changed with version 0.4.0 (it was pretty useless in prior versions) !
2015-12-19 10:16:05 +00:00
#### Table of Contents
1. [Overview](#overview)
2. [Module Description - What the module does and why it is useful](#module-description)
2015-12-21 12:33:29 +00:00
* [Notes](#notes)
2015-12-19 10:16:05 +00:00
3. [Setup - The basics of getting started with rsnapshot](#setup)
* [What rsnapshot affects](#what-rsnapshot-affects)
2015-12-21 12:33:29 +00:00
* [Setup requirements](#setup-requirements)
* [Getting started with rsnapshot](#getting-started)
4. [Configuration - options and additional functionality](#configuration)
* [Examples](#examples)
* [More Options](#more-options)
2015-12-19 10:16:05 +00:00
5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
* [Classes](#classes)
* [Functions](#functions)
* [Parameters](parameters)
* [Rsnapshot Configuration Parameters](#rsnapshot-configuration-variables)
2015-12-19 10:16:05 +00:00
5. [Limitations - OS compatibility, etc.](#limitations)
6. [Development - Guide for contributing to the module](#development)
2015-12-21 12:33:29 +00:00
7. [Editors](#editors)
8. [Contributors](#contributors)
2015-12-19 10:16:05 +00:00
## Overview
2015-12-21 12:33:29 +00:00
The rsnapshot module installs, configures and manages rsnapshot on a dedicated backup server.
2015-12-19 10:16:05 +00:00
## Module Description
2015-12-21 12:33:29 +00:00
The rsnapshot module installs, configures and manages rsnapshot on a dedicated backup server. It allows to set up a centralized Backup Server for all your nodes.
For the cron setup, the module will pick random time entries for the crons from an Array or a Range of time. For how to configure this, [please see below](#more-options)
2015-12-19 10:16:05 +00:00
2015-12-21 12:33:29 +00:00
### Notes
This module is best used with an ENC like hiera. It will make your config much easier to read and to maintain. Check the examples to see what I mean.
2015-12-19 10:16:05 +00:00
## Setup
### What rsnapshot affects
2015-12-21 12:33:29 +00:00
* This module will install the rsnapshot package on your system
* This module will manage the rsnapshot config on your system
* This module will manage cron entries for your configured nodes
2015-12-19 10:16:05 +00:00
2015-12-21 12:33:29 +00:00
### Setup Requirements
2015-12-19 10:16:05 +00:00
2015-12-21 12:33:29 +00:00
On CentOS Systems this module requires the stahnma-epel module. Also you will need to have rsync installed on all nodes to be backed up.
It will create repeatable random cron entries from a configurable timerange for all hosts.
2015-12-19 10:16:05 +00:00
2015-12-21 12:33:29 +00:00
### Getting Started
2015-12-19 10:16:05 +00:00
2015-12-21 12:33:29 +00:00
You will need to pass the nodenames to be backed up at least.
This will pickup all defaults and add localhost to the backups:
2015-12-19 10:16:05 +00:00
2015-12-21 12:33:29 +00:00
```puppet
class { '::rsnapshot':
hosts => {
'localhost' => {},
2015-12-19 10:16:05 +00:00
}
}
```
2015-12-21 12:33:29 +00:00
## Configuration
Here are some more elaborate examples of what you can do with this module.
2015-12-19 10:16:05 +00:00
2015-12-21 12:33:29 +00:00
### Examples
This will backup localhost with defaults. It will disable the default backup locations for example.com
and just backup '/var' for example.com.
2016-01-05 14:24:26 +00:00
2015-12-21 12:33:29 +00:00
```puppet
class { '::rsnapshot':
hosts => {
'localhost' => {},
'example.com' => {
backup_defaults => false,
backup => {
'/var/' => './'
}
}
2015-12-19 10:16:05 +00:00
}
}
```
2016-01-05 14:24:26 +00:00
2015-12-21 12:33:29 +00:00
The same in hiera:
2016-01-05 14:24:26 +00:00
2015-12-21 12:33:29 +00:00
```yaml
---
classes: rsnapshot
rsnapshot::hosts:
localhost:
example.com:
backup_defaults: false
backup:
'/var/': './'
```
2015-12-19 10:16:05 +00:00
2015-12-21 12:33:29 +00:00
A more complete hiera example:
2016-01-05 14:24:26 +00:00
2015-12-21 12:33:29 +00:00
```yaml
---
classes:
- rsnapshot
2015-12-19 10:16:05 +00:00
2015-12-21 12:33:29 +00:00
# override default backup dirs for all hosts:
rsnapshot::default_backup:
'/etc': './'
'/usr/local': './'
'/home': './'
2015-12-19 10:16:05 +00:00
2015-12-21 12:33:29 +00:00
# configure hosts to be backed up
rsnapshot::hosts:
# pick all defaults for localhost
localhost:
# add futher backups for node foo.example.com (additional to default_backup) and use a different snapshot root
foo.example.com:
backup:
'/foo': './'
'/bar': './'
'/baz': './misc'
snapshot_root: '/tmp/rsnapshot'
# all defaults
foo1.example.com:
foo2:
# disable default backup dirs and just backup /var for node bar1
# also set the minute to 0-10 for daily cron (note: this is not particularly useful, it's just meant to document the features)
# lastly set the range of hours to pick a random hour from (the cron for bar1 will have hour set to something between 1 and 5)
bar1:
backup_defaults: false
backup:
'/var': './var'
cron:
'daily':
'minute': '0-10'
'hour': '1..5'
2015-12-19 10:16:05 +00:00
2015-12-21 12:33:29 +00:00
```
### More options
The defaults are pretty reasonable, I hope. However, you may override pretty much anything. Available parameters are discussed below.
#### Specials
As mentioned, this module will generate random time entries for your hosts. The random number generator is hashed with hostname and backup_level, so the randomness will be repeatable per host.level. This is important so puppet won't override the crons with each run.
You may specify time ranges as follows:
2016-01-05 14:29:54 +00:00
* default cron syntax
2015-12-21 12:33:29 +00:00
* an array with allowed values, for example, if you want the backup for a host to run between 1am and 5am, you would override the hours setting for the host in question.
in hiera this would look like: (Explanation see below)
2016-01-05 14:28:06 +00:00
2015-12-21 12:33:29 +00:00
```yaml
rsnapshot::hosts:
example.com:
cron:
'daily':
'minute': '1'
'hour': '1..5'
```
2016-01-05 14:28:06 +00:00
2015-12-21 12:33:29 +00:00
This will create the rsnapshot config using defaults from params.pp, but set the minute of the daily backup to '1' and the hour to something random between 1 and 5.
So it would look something like:
2016-01-05 14:28:06 +00:00
2015-12-21 12:33:29 +00:00
```
1 4 * * * foo daily
```
2016-01-05 14:28:06 +00:00
2015-12-21 12:33:29 +00:00
or maybe
2016-01-05 14:28:06 +00:00
2015-12-21 12:33:29 +00:00
```
1 2 * * * foo daily
```
2016-01-05 14:28:06 +00:00
2015-12-21 12:33:29 +00:00
## Reference
### Classes
#### Public Classes
* rsnapshot: Main class, includes all other classes.
2016-01-05 14:24:26 +00:00
#### Private Classes
2015-12-21 12:33:29 +00:00
* rsnapshot::install: Handles the packages.
* rsnapshot::config: Handles configuration and cron files.
* rsnapshot::params: default values.
### Functions
2016-01-05 14:24:26 +00:00
#### `assert_empty_hash`
2015-12-21 12:33:29 +00:00
Sets an empty value to a hash (we need this so a loop doesn't break if just a hostname is given to pick up all defaults.
2016-01-05 14:24:26 +00:00
#### `pick_undef`
2015-12-21 12:33:29 +00:00
Like pick but returns undef values.
2016-01-05 14:24:26 +00:00
#### `rand_from_array`
2015-12-21 12:33:29 +00:00
Takes an Integer, a String or an Array as input, and returns a random entry from the array (or just the String/Integer)
### Parameters
The following parameters are available in the `::rsnapshot` class:
2016-01-05 14:24:26 +00:00
#### `$hosts`
2015-12-21 12:33:29 +00:00
Hash containing the hosts to be backed up and optional overrides per host
2015-12-22 07:32:41 +00:00
(Default: undef (do nothing when no host given))
2016-01-05 14:24:26 +00:00
#### `$conf_d`
2015-12-22 07:32:41 +00:00
The place where the configs will be dropped
(Default: /etc/rsnapshot (will be created if it doesn't exist))
2016-01-05 14:24:26 +00:00
#### `$backup_user`
2015-12-22 07:32:41 +00:00
The user to run the backup scripts as
(Default: root, also the user used for ssh connections, if you change this make sure you have proper key deployed and the user exists in the nodes to be backed up.)
2016-01-05 14:24:26 +00:00
#### `$package_name`
2015-12-22 07:32:41 +00:00
(Default: rsnapshot)
2016-01-05 14:24:26 +00:00
#### `$package_ensure`
2015-12-22 07:32:41 +00:00
(Default: present)
2016-01-05 14:24:26 +00:00
#### `$cron_dir`
2015-12-22 07:32:41 +00:00
Directory to drop the cron files to. Crons will be created per host.
(Default: /etc/cron.d)
2016-01-05 14:24:26 +00:00
#### `$backup_levels`
2015-12-21 12:33:29 +00:00
Array containing the backup levels (hourly, daily, weekly, monthly)
Configure the backup_levels (valid per host and global, so you may either set: rsnapshot::backup_levels for all hosts or override default backup_levels for specific hosts)
2015-12-22 07:32:41 +00:00
(Default: [ 'daily', 'weekly', ] )
2016-01-05 14:24:26 +00:00
#### `$backup_defaults`
2015-12-21 12:33:29 +00:00
Boolean. Backup default backup dirs or not.
2015-12-22 07:32:41 +00:00
(Default: true)
2016-01-05 14:24:26 +00:00
#### `$default_backup`
The default backup directories. This will apply to all hosts unless you set [backup_defaults](#backup_defaults) = false
Default is:
2016-01-05 14:28:06 +00:00
```puppet
2015-12-22 14:00:50 +00:00
$default_backup = {
'/etc' => './',
'/home' => './',
}
```
2016-01-05 14:24:26 +00:00
#### `$cron`
Hash. Set time ranges for different backup levels. Each item (minute, hour...) allows for cron notation, an array to pick a random time from and a range to pick a random time from.
The range notation is '$start..$end', so to pick a random hour from 8 pm to 2 am, you could set the hour of your desired backup level to
`[ '20..23','0..2' ]`
Example:
2016-01-05 14:28:06 +00:00
```puppet
$cron = {
hourly => {
minute => '0..59',
hour => [ '20..23','0..2' ],
}
}
```
2016-01-05 14:28:06 +00:00
Or in hiera:
- global override
2016-01-05 14:28:06 +00:00
```yaml
rsnapshot::cron:
daily:
minute: '20'
weekly:
minute: '20'
```
2016-01-05 14:28:06 +00:00
- per host override
2016-01-05 14:28:06 +00:00
```yaml
rsnapshot::hosts:
webserver:
daily:
hour: [ '20..23','0..2' ]
weekly:
hour: [ '20..23','0..2' ]
```
Hash is of the form:
2016-01-05 14:24:26 +00:00
```puppet
$cron =>{
daily => {
minute => param,
hour => param,
}
weekly => {
minute => param,
hour => param,
}
{...}
}
```
2016-01-05 14:28:06 +00:00
Default is:
2016-01-05 14:24:26 +00:00
```puppet
$cron = {
hourly => {
minute => '0..59', # random from 0 to 59
hour => '*', # you could also do: ['21..23','0..4','5'],
monthday => '*',
month => '*',
weekday => '*',
},
daily => {
minute => '0..10', # random from 0 to 10
hour => '0..23', # you could also do: ['21..23','0..4','5'],
monthday => '*',
month => '*',
weekday => '*',
},
weekly => {
minute => '0..59',
hour => '0..23', # you could also do: ['21..23','0..4','5'],
monthday => '*',
month => '*',
weekday => '0..6',
},
monthly => {
minute => '0..59',
hour => '0..23', # you could also do: ['21..23','0..4','5'],
monthday => '0..28',
month => '*',
weekday => '*',
},
}
```
2016-01-05 14:24:26 +00:00
#### `$snapshot_root`
2015-12-22 07:32:41 +00:00
global. the directory holding your backups.
(Default: /backup)
You will end up with a structure like:
2016-01-05 14:24:26 +00:00
2015-12-21 13:50:17 +00:00
```
/backup/
├── example.com
│   ├── daily.0
│   ├── daily.1
│   ├── daily.2
│   ├── daily.3
│   ├── weekly.0
│   ├── weekly.1
│   ├── weekly.2
│   └── weekly.3
└── localhost
├── daily.0
├── daily.1
├── daily.2
└── weekly.0
```
2015-12-21 13:56:20 +00:00
2016-01-05 14:24:26 +00:00
#### `$interval`
How many backups of each level to keep.
Default is:
2016-01-05 14:24:26 +00:00
```puppet
$interval = {
'daily' => '7',
'weekly' => '4',
'monthly' => '6',
}
```
2016-01-19 16:37:59 +00:00
#### `$backup_scripts`
Additional scripts to create, possible values are: mysql, psql, misc
Default is:
```puppet
$backup_scripts = {
mysql => {
dbbackup_user => 'root',
dbbackup_password => 'myFancyPassWord',
},
psql => {
dbbackup_user => 'postgres',
dbbackup_password => '',
},
misc => {},
}
```
Configuration example:
```yaml
rsnapshot::backup_scripts:
mysql:
dbbackup_user: 'dbbackup'
dbbackup_password: 'hunter2'
psql:
dbbackup_user: 'dbbackup'
dbbackup_password: 'yeshorsebatterystaple'
rsnapshot::hosts:
foobar.com:
backup_scripts:
mysql:
psql:
bazqux:de:
backup_scripts:
mysql:
dbbackup_user: 'myuser'
dbbackup_password: 'mypassword'
```
This creates
- a mysql and a psql backup script for `foobar.com` using the credentials `dbbackup:hunter2` for mysql and `dbbackup:yeshorsebatterystaple` for psql
- a mysql backup script for `bazqux.de` using the credentials `myuser:mypassword`
2015-12-21 12:33:29 +00:00
### rsnapshot configuration variables
Please read up on the following in the [rsnapshot manpage](http://linux.die.net/man/1/rsnapshot)
2016-01-05 14:24:26 +00:00
#### `$config_version`
Default is: '1.2'
2016-01-05 14:24:26 +00:00
#### `$cmd_cp`
Default is: '/bin/cp'
2016-01-05 14:24:26 +00:00
#### `$cmd_rm`
Default is: '/bin/rm'
2016-01-05 14:24:26 +00:00
#### `$cmd_rsync`
Default is: '/usr/bin/rsync'
2016-01-05 14:24:26 +00:00
#### `$cmd_ssh`
Default is: '/usr/bin/ssh'
2016-01-05 14:24:26 +00:00
#### `$cmd_logger`
Default is: '/usr/bin/logger'
2016-01-05 14:24:26 +00:00
#### `$cmd_du`
Default is: '/usr/bin/du'
2016-01-05 14:24:26 +00:00
#### `$cmd_rsnapshot_diff`
Default is: '/usr/bin/rsnapshot-diff'
2016-01-05 14:24:26 +00:00
#### `$cmd_preexec`
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$cmd_postexec`
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$use_lvm`
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$linux_lvm_cmd_lvcreate`
Default is: undef # '/sbin/lvcreate'
2016-01-05 14:24:26 +00:00
#### `$linux_lvm_cmd_lvremove`
Default is: undef # '/sbin/lvremove'
2016-01-05 14:24:26 +00:00
#### `$linux_lvm_cmd_mount`
Default is: undef # '/sbin/mount'
2016-01-05 14:24:26 +00:00
#### `$linux_lvm_cmd_umount`
Default is: undef # '/sbin/umount'
2016-01-05 14:24:26 +00:00
#### `$linux_lvm_snapshotsize`
Default is: undef # '100M'
2016-01-05 14:24:26 +00:00
#### `$linux_lvm_snapshotname`
2016-01-05 14:33:09 +00:00
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$linux_lvm_vgpath`
2016-01-05 14:31:27 +00:00
2016-01-05 14:33:09 +00:00
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$linux_lvm_mountpath`
2016-01-05 14:33:09 +00:00
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$logpath`
Default is: '/var/log/rsnapshot'
2016-01-05 14:24:26 +00:00
#### `$logfile`
unused, we are logging to $logpath/$host.log
Default is: '/var/log/rsnapshot.log'
2016-01-05 14:24:26 +00:00
#### `$lockpath`
Default is: '/var/run/rsnapshot'
2016-01-05 14:24:26 +00:00
#### `$snapshot_root`
Default is: '/backup/'
2016-01-05 14:24:26 +00:00
#### `$no_create_root`
Boolean: true or false
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$verbose`
Default is: '2'
2016-01-05 14:24:26 +00:00
#### `$loglevel`
Default is: '4'
2016-01-05 14:24:26 +00:00
#### `$stop_on_stale_lockfile`
2016-01-05 14:31:27 +00:00
Boolean: true or false
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$rsync_short_args`
Default is: '-az'
2016-01-05 14:24:26 +00:00
#### `$rsync_long_args`
rsync defaults are: --delete --numeric-ids --relative --delete-excluded
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$ssh_args`
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$du_args`
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$one_fs`
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$retain`
Default is: { }
2016-01-05 14:24:26 +00:00
#### `$include`
Default is: []
2016-01-05 14:24:26 +00:00
#### `$exclude`
Default is: []
2016-01-05 14:24:26 +00:00
#### `$include_file`
2016-01-05 14:31:27 +00:00
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$exclude_file`
Other than this might suggest, the default behavior is to create an exclude file per host.
Default is: undef
2016-01-05 14:24:26 +00:00
#### `$link_dest`
Default is: false
2016-01-05 14:24:26 +00:00
#### `$sync_first`
Default is: false
2016-01-05 14:24:26 +00:00
#### `$rsync_numtries`
2016-01-05 14:31:27 +00:00
Default is: 1
2016-01-05 14:24:26 +00:00
#### `$use_lazy_deletes`
Default is: false
## Limitations
2015-12-22 07:32:41 +00:00
Currently, this module support CentOS, Fedora, Ubuntu and Debian.
## Development
I have limited access to resources and time, so if you think this module is useful, like it, hate it, want to make it better or
want it off the face of the planet, feel free to get in touch with me.
## Editors
Norbert Varzariu (loomsen)
## Contributors
Please see the [list of contributors.](https://github.com/loomsen/puppet-bloonix_agent/graphs/contributors)
2015-12-22 07:32:41 +00:00