1
0
mirror of https://github.com/krislamo/puppet-rsnapshot synced 2025-09-13 07:49:29 +00:00

64 Commits
0.4.0 ... 1.0.1

Author SHA1 Message Date
Norbert Varzariu
08cc0037b1 bump version to 1.0.1 2016-01-25 09:40:58 +01:00
Norbert Varzariu
b3ab06b63c add postgres to psql.ignore_dbs 2016-01-25 09:40:05 +01:00
Norbert Varzariu
d252ac64a0 move PGPASSWD variable into ssh command (so it is available on the node) 2016-01-25 08:56:04 +01:00
Norbert Varzariu
8dd6298c56 Merge branch 'master' into develop 2016-01-25 08:55:20 +01:00
Norbert Varzariu
343d12c61b Merge branch 'release/1.0.0' into develop 2016-01-22 16:06:35 +01:00
Norbert Varzariu
8817ed33ff Merge branch 'release/1.0.0'
- parameterized nearly all aspects of the script
- complete documentation with examples
- configurable database backup scripts
- configurable custom commands script
- configurable mailto for crons
- and much more
2016-01-22 16:03:49 +01:00
Norbert Varzariu
5cb6c2d235 bump version to 1.0.0 \o/ 2016-01-22 16:03:46 +01:00
Norbert Varzariu
daba8a562a Merge branch 'feature/parameterize_backup_scripts' into develop
- parameterize backup scripts
- add custom commands to misc script
- add parameters to mysql and psql scripts
- update documentation
2016-01-22 15:59:02 +01:00
Norbert Varzariu
f67cd5a517 remove debug message 2016-01-22 15:58:18 +01:00
Norbert Varzariu
33e3fa685a parameterize backup_user in scripts templates 2016-01-22 15:57:23 +01:00
Norbert Varzariu
03e385b2aa clean up repo 2016-01-22 15:50:22 +01:00
Norbert Varzariu
b9c0e0cebc add headers to scripts 2016-01-22 15:48:07 +01:00
Norbert Varzariu
46a0a4faaf update README 2016-01-22 15:44:12 +01:00
Norbert Varzariu
441c6a0584 update README 2016-01-22 15:16:55 +01:00
Norbert Varzariu
eb7a73f460 update README 2016-01-22 15:13:09 +01:00
Norbert Varzariu
3bedb6efaa update README 2016-01-22 15:09:29 +01:00
Norbert Varzariu
86073f42b1 add custom commands to misc script 2016-01-22 15:01:32 +01:00
Norbert Varzariu
eb643443fd update README 2016-01-22 14:07:06 +01:00
Norbert Varzariu
8ba0042a94 parameterize backup scripts 2016-01-22 13:17:03 +01:00
Norbert Varzariu
942e9a7697 fix readme 2016-01-22 10:51:37 +01:00
Norbert Varzariu
f7eec6ee5f Merge branch 'release/0.5.2' into develop 2016-01-22 10:43:22 +01:00
Norbert Varzariu
12b11a6a43 Merge branch 'release/0.5.2'
- Update documentation
2016-01-22 10:42:55 +01:00
Norbert Varzariu
b332e2edcb bump version to 0.5.2 2016-01-22 10:42:48 +01:00
Norbert Varzariu
5ee6544312 Merge branch 'hotfix/update_docs' into develop 2016-01-22 10:42:14 +01:00
Norbert Varzariu
dcd5f532a9 Merge branch 'hotfix/update_docs'
- Update README to reflect changes in configuration of backup_scripts
- Add example backup_scripts to README
2016-01-22 10:40:41 +01:00
Norbert Varzariu
16630094cb update README to reflect for v0.4.0 changes in backup_scripts 2016-01-22 10:40:17 +01:00
Norbert Varzariu
d57d87532b add note about range notation to README 2016-01-22 10:28:10 +01:00
Norbert Varzariu
bc3a33e6f0 fix merge conflict 2016-01-22 10:01:39 +01:00
Norbert Varzariu
0f6a6ebe31 fix template 2016-01-22 10:00:49 +01:00
Norbert Varzariu
c80ba48d4c templates/rsnapshot.erb 2016-01-22 09:58:57 +01:00
Norbert Varzariu
e823fef87c fix templates (do not create include/exclude file entries if no in/excludes given) 2016-01-22 09:56:33 +01:00
Norbert Varzariu
638ec858b0 Merge branch 'develop'
- restart cron service after config generation
2016-01-22 09:32:02 +01:00
Norbert Varzariu
d71239645f restart cron service after config change 2016-01-22 09:31:51 +01:00
Norbert Varzariu
7318f9b2dc Merge branch 'release/0.5.1' into develop 2016-01-22 09:18:03 +01:00
Norbert Varzariu
bf55ad97b6 Merge branch 'release/0.5.1' 2016-01-22 09:17:51 +01:00
Norbert Varzariu
4dedb43a22 bump version to 0.5.1 2016-01-22 09:17:49 +01:00
Norbert Varzariu
81ef65edca quick fix trailing slash in params.pp snapshot_root 2016-01-22 09:17:15 +01:00
Norbert Varzariu
9ed7f44a28 Merge branch 'release/0.5.0' into develop 2016-01-22 09:13:13 +01:00
Norbert Varzariu
d786e0088e fix merge issue 2016-01-22 09:12:32 +01:00
Norbert Varzariu
e8a287c4f8 bump version to 0.5.0 2016-01-22 09:10:12 +01:00
Norbert Varzariu
a28b27c505 Merge branch 'feature/rewrite_to_use_deep_merge' into develop
- rewrite large parts of cron file generation
- now using deep_merge to merge possible overrides into the default hash
  (eliminates a lit of spaghetti code)
2016-01-22 09:08:28 +01:00
Norbert Varzariu
0235f202b4 rewrite cron file generation using deep_merge (why is this function undocumented?) 2016-01-22 09:08:12 +01:00
Norbert Varzariu
a5558bf329 Merge branch 'master' of gitlab.flx.bn:devops/puppet-rsnapshot 2016-01-21 16:13:35 +01:00
Norbert Varzariu
d4cd5282f7 quick fixes 2016-01-21 16:12:07 +01:00
Norbert Varzariu
0a489a4eb8 quick fixes 2016-01-21 16:11:56 +01:00
Norbert Varzariu
80d1756087 Merge branch 'release/0.4.2' into develop 2016-01-21 15:19:31 +01:00
Norbert Varzariu
8f7da1a1ee Merge branch 'release/0.4.2'
- add db backup template scripts
2016-01-21 15:19:06 +01:00
Norbert Varzariu
413ca69760 bump version to 0.4.2 2016-01-21 15:19:02 +01:00
Norbert Varzariu
c7756458f1 Merge branch 'feature/rewrite_to_use_deep_merge' 2016-01-21 15:15:12 +01:00
Norbert Varzariu
d5e4ebbb9c add backup script templates 2016-01-21 15:11:10 +01:00
Norbert Varzariu
d6ea0821c0 Merge branch 'release/0.4.1' into develop 2016-01-20 11:45:58 +01:00
Norbert Varzariu
2cccc86433 Merge branch 'release/0.4.1' 2016-01-20 11:45:41 +01:00
Norbert Varzariu
e39f638dfa bump version to 0.4.1 2016-01-20 11:45:31 +01:00
Norbert Varzariu
ab9ec44ced ensure in-/exclude file is absent if no in-/excludes given 2016-01-20 11:41:59 +01:00
Norbert Varzariu
941036d986 testing 2016-01-20 10:38:27 +01:00
Norbert Varzariu
396d71cb8e testing 2016-01-20 10:27:29 +01:00
Norbert Varzariu
d1008c99eb add warning to README about configuration change in 0.4.0 2016-01-19 17:39:46 +01:00
Norbert Varzariu
ed9de1e8cd Merge branch 'release/0.4.0' into develop 2016-01-19 17:38:14 +01:00
Norbert Varzariu
d5d7507fa9 Merge branch 'release/0.4.0' 2016-01-19 17:38:03 +01:00
Norbert Varzariu
5f65000606 Merge branch 'develop' 2016-01-18 20:53:46 +01:00
Norbert Varzariu
fce58cf09a Merge branch 'develop' 2016-01-18 19:58:32 +01:00
Norbert Varzariu
5cccf8200d Merge branch 'release/0.3.2' 2016-01-18 19:56:18 +01:00
Norbert Varzariu
ae2083c6ee Merge branch 'develop' 2016-01-18 12:11:28 +01:00
Norbert Varzariu
8e62ff526e Merge branch 'release/0.3.1' 2016-01-18 11:23:21 +01:00
13 changed files with 359 additions and 97 deletions

View File

@@ -1,3 +0,0 @@
---
BUNDLE_PATH: vendor/bundle
BUNDLE_DISABLE_SHARED_GEMS: '1'

220
README.md
View File

@@ -1,5 +1,7 @@
# rsnapshot # rsnapshot
## NOTE: ! Configuration for backup_scripts changed with version 0.4.0 (it was pretty useless in prior versions) !
#### Table of Contents #### Table of Contents
1. [Overview](#overview) 1. [Overview](#overview)
@@ -131,10 +133,14 @@ rsnapshot::hosts:
backup: backup:
'/var': './var' '/var': './var'
cron: cron:
'daily': mailto: 'bar1@example.com'
'minute': '0-10' daily:
'hour': '1..5' minute: '0-10'
hour: '1..5'
db1:
backup_scripts:
mysql:
misc:
``` ```
@@ -238,10 +244,17 @@ Default is:
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. 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 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' ]` `[ '20..23','0..2' ]`
For the range feature to work, hours >0 and <10 must not have a preceding zero.
Wrong: `00.09`
Correct: `0..9`
Also, you can set a mailto for each host, or globally now. The settings will be merged bottom to top, so if you override a setting in a hosts cron, it will have precedence over the global setting,
which in turn has precedence over the default.
Example: Example:
```puppet ```puppet
$cron = { $cron = {
mailto => 'admin@example.com',
hourly => { hourly => {
minute => '0..59', minute => '0..59',
hour => [ '20..23','0..2' ], hour => [ '20..23','0..2' ],
@@ -254,6 +267,7 @@ Or in hiera:
```yaml ```yaml
rsnapshot::cron: rsnapshot::cron:
mailto: 'admin@example.com'
daily: daily:
minute: '20' minute: '20'
weekly: weekly:
@@ -265,16 +279,32 @@ rsnapshot::cron:
```yaml ```yaml
rsnapshot::hosts: rsnapshot::hosts:
webserver: webserver:
daily: cron:
hour: [ '20..23','0..2' ] mailto: 'support@example.com'
weekly: daily:
hour: [ '20..23','0..2' ] hour: [ '20..23','0..2' ]
weekly:
hour: [ '20..23','0..2' ]
webhost:
customervm.provider.com:
backup_user: 'customer'
``` ```
`webhost`: Mails will go to `admin@example.com` (from the global override).
`webserver`: Mails will go to `support@example.com`.
`customervm.provider.com`: The backup (and thus ssh) user will be `customer@customervm.provider.com`
Hash is of the form: Hash is of the form:
```puppet ```puppet
$cron =>{ $cron =>{
mailto => param,
daily => { daily => {
minute => param, minute => param,
hour => param, hour => param,
@@ -292,6 +322,7 @@ Default is:
```puppet ```puppet
$cron = { $cron = {
mailto => 'admin@example.com',
hourly => { hourly => {
minute => '0..59', # random from 0 to 59 minute => '0..59', # random from 0 to 59
hour => '*', # you could also do: ['21..23','0..4','5'], hour => '*', # you could also do: ['21..23','0..4','5'],
@@ -361,20 +392,65 @@ Default is:
#### `$backup_scripts` #### `$backup_scripts`
Additional scripts to create, possible values are: mysql, psql, misc Additional scripts to create, possible values are: mysql, psql, misc
`mysql`: used for mysql backups
`psql`: used for postgresql backups
`misc`: custom commands to run on the node
You can set
`$dbbackup_user`: backup user
`$dbbackup_password`: password for the backup user
`$dumper`: path to the dump bin you wish to use
`$dump_flags`: flags for your dump bin
`$ignore_dbs`: databases to be ignored (the psql script ignores template and postgres databases by default)
`$commands`: array of commands to run on the host (this has no effect on psql and mysql scripts and is intended for your custom needs, see misc script section)
See below for defaults
NOTE: the psql and mysql scripts will SSH into your host and try and use $dumper.
Make sure you have those tools installed on your DB hosts.
Also, this module will try and use pbzip to compress your databases. You can install pbzip2 (and additional packages you might need) by passing an array to [$rsnapshot::package_name](#package_name)
Default is: Default is:
```puppet ```puppet
$backup_scripts = { $backup_scripts = {
mysql => { mysql => {
dbbackup_user => 'root', dbbackup_user => 'root',
dbbackup_password => 'myFancyPassWord', dbbackup_password => '',
dumper => 'mysqldump',
dump_flags => '--single-transaction --quick --routines --ignore-table=mysql.event',
ignore_dbs => [ 'information_schema', 'performance_schema' ],
}, },
psql => { psql => {
dbbackup_user => 'postgres', dbbackup_user => 'postgres',
dbbackup_password => '', dbbackup_password => '',
dumper => 'pg_dump',
dump_flags => '-Fc',
ignore_dbs => [],
}, },
misc => {}, misc => {
commands => $::osfamily ? {
'RedHat' => [
'rpm -qa --qf="%{name}," > packages.txt',
],
'Debian' => [
'dpkg --get-selections > packages.txt',
],
default => [],
},
}
} }
``` ```
Configuration example: Configuration example:
@@ -393,16 +469,134 @@ rsnapshot::hosts:
backup_scripts: backup_scripts:
mysql: mysql:
psql: psql:
dumper: '/usr/local/bin/pg_dump'
dump_flags: '-Fc'
ignore_dbs: [ 'db1', 'tmp_db' ]
misc:
bazqux:de: bazqux:de:
backup_scripts: backup_scripts:
mysql: mysql:
dbbackup_user: 'myuser' dbbackup_user: 'myuser'
dbbackup_password: 'mypassword' dbbackup_password: 'mypassword'
misc:
commands:
- 'cat /etc/hostname > hostname.txt'
- 'date > date.txt'
``` ```
This creates 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 and a psql backup script for `foobar.com` using the credentials `dbbackup:hunter2` for mysql and `dbbackup:yeshorsebatterystaple` for psql
- the psql script will use `/usr/local/bin/pg_dump` as the dump program with flags `-Fc`
- it will ignore the postgres databases `db1` and `tmp_db` for postgres
- a mysql backup script for `bazqux.de` using the credentials `myuser:mypassword` - a mysql backup script for `bazqux.de` using the credentials `myuser:mypassword`
- a misc script for bazqux.de containing two commands to run on the node. the output will be redirected to hostname.txt and date.txt in the misc/ subfolder of the hosts backup directory (i.e. /snapshot_root/bazqux.de/daily.0/misc/hostname.txt)
The scripts look like this:
##### `bazqux.de`
```bash
#!/bin/bash
host=bazqux.de
user=myuser
pass=mypassword
dbs=(
$(ssh -l root "$host" "mysql -u ${user} -p${pass} -e 'show databases' | sed '1d;/information_schema/d;/performance_schema/d'")
)
for db in "${dbs[@]}"; do
ssh -l root "$host" "mysqldump --user=${user} --password=${pass} --single-transaction --quick --routines --ignore-table=mysql.event ${db}" > "${db}.sql"
wait
pbzip2 "$db".sql
done
```
```bash
#!/bin/bash
ssh bazqux.de 'cat /etc/hostname > hostname.txt'
ssh bazqux.de 'date > date.txt'
```
##### `foobar.com`
psql:
```bash
#!/bin/bash
host=foobar.com
user=dbbackup
pass=yeshorsebatterystaple
PGPASSWORD="$pass"
dbs=(
$(ssh -l root "$host" "psql -U ${user} -Atc \"SELECT datname FROM pg_database WHERE NOT datistemplate AND datname ~ 'postgres|db1|tmp_db'\"" )
)
for db in "${dbs[@]}"; do
ssh -l root "$host" "pg_dump -U ${user} -Fc ${db}" > "$db".sql
wait
pbzip2 "$db".sql
done
```
mysql:
```bash
#!/bin/bash
host=foobar.com
user=dbbackup
pass=hunter2
dbs=(
$(ssh -l root "$host" "mysql -u ${user} -p${pass} -e 'show databases' | sed '1d;/information_schema/d;/performance_schema/d'")
)
for db in "${dbs[@]}"; do
ssh -l root "$host" "mysqldump --user=${user} --password=${pass} --single-transaction --quick --routines --ignore-table=mysql.event ${db}" > "${db}.sql"
wait
pbzip2 "$db".sql
done
```
misc (assuming foobar.com is a RedHat node):
```bash
#!/bin/bash
ssh foobar.com 'rpm -qa --qf "%{name}," > packages.txt'
```
##### another example with root user and empty password
mysql with root user:
```bash
#!/bin/bash
host=bazqux.de
user=root
password=
dbs=(
$(ssh -l root "$host" "mysql -e 'show databases' | sed '1d;/information_schema/d;/performance_schema/d'")
)
for db in "${dbs[@]}"; do
ssh -l root "$host" "mysqldump --single-transaction --quick --routines --ignore-table=mysql.event ${db}" > "${db}.sql"
wait
pbzip2 "$db".sql
done
```
### rsnapshot configuration variables ### rsnapshot configuration variables
@@ -552,4 +746,4 @@ Norbert Varzariu (loomsen)
## Contributors ## Contributors
Please see the [list of contributors.](https://github.com/loomsen/puppet-bloonix_agent/graphs/contributors) Please see the [list of contributors.](https://github.com/loomsen/puppet-bloonix_agent/graphs/contributors)
A big thank you to Hendrik Horeis <hendrik.horeis@gmail.com> for all his input and testing of this module.

View File

@@ -5,12 +5,13 @@ class rsnapshot::config (
$hosts = $rsnapshot::hosts, $hosts = $rsnapshot::hosts,
$cron_dir = $rsnapshot::cron_dir, $cron_dir = $rsnapshot::cron_dir,
) { ) {
# these are global settings, no point in setting them per host # these are global settings, no point in setting them per host
$config_version = $rsnapshot::params::config_version $config_version = $rsnapshot::params::config_version
$lockpath = pick($rsnapshot::lockpath, $rsnapshot::params::config_lockpath, '/var/run/rsnapshot') $lockpath = pick($rsnapshot::lockpath, $rsnapshot::params::config_lockpath, '/var/run/rsnapshot')
$conf_d = pick($rsnapshot::conf_d, $rsnapshot::params::conf_d, '/etc/rsnapshot') $conf_d = pick($rsnapshot::conf_d, $rsnapshot::params::conf_d, '/etc/rsnapshot')
$snapshot_root = pick($hosts['snapshot_root'], $rsnapshot::snapshot_root, '/backup') $snapshot_root = pick($hosts['snapshot_root'], $rsnapshot::snapshot_root, '/backup')
$default_cron = assert_empty_hash($::rsnapshot::cron) $logpath = pick($rsnapshot::logpath, $rsnapshot::params::config_logpath)
# make sure lock path and conf path exist # make sure lock path and conf path exist
file { $conf_d: file { $conf_d:
ensure => 'directory', ensure => 'directory',
@@ -24,6 +25,10 @@ class rsnapshot::config (
file { $snapshot_root: file { $snapshot_root:
ensure => 'directory', ensure => 'directory',
} }
file { $logpath:
ensure => directory,
}
# custom function, if only a hostname is given as a param, this is an empty hash # custom function, if only a hostname is given as a param, this is an empty hash
# the next loop would break as puppet does not allow to reassign variables # the next loop would break as puppet does not allow to reassign variables
# the function checks $hosts for elements like: # the function checks $hosts for elements like:
@@ -31,9 +36,9 @@ class rsnapshot::config (
$hosts_clean = assert_empty_hash($hosts) $hosts_clean = assert_empty_hash($hosts)
$hosts_clean.each |String $host, $hash | { $hosts_clean.each |String $host, $hash | {
$backup_user = pick($hash['backup_user'], $rsnapshot::params::config_backup_user) $backup_user = pick($hash['backup_user'], $rsnapshot::backup_user, $rsnapshot::params::config_backup_user, 'root')
$default_backup_dirs = pick($rsnapshot::default_backup, $rsnapshot::params::config_default_backup) $default_backup_dirs = pick($rsnapshot::default_backup, $rsnapshot::params::config_default_backup)
$backup_levels = pick($hash['backup_levels'], $rsnapshot::params::config_backup_levels, 'weekly') $backup_levels = pick($hash['backup_levels'], $rsnapshot::backup_levels, 'weekly')
$backup = $hash['backup'] $backup = $hash['backup']
$backup_defaults = pick($hash['backup_defaults'], $rsnapshot::params::config_backup_defaults) $backup_defaults = pick($hash['backup_defaults'], $rsnapshot::params::config_backup_defaults)
$cmd_cp = pick($hash['cmd_cp'], $rsnapshot::params::config_cmd_cp) $cmd_cp = pick($hash['cmd_cp'], $rsnapshot::params::config_cmd_cp)
@@ -55,7 +60,6 @@ class rsnapshot::config (
$linux_lvm_vgpath = pick_undef($hash['linux_lvm_vgpath'], $rsnapshot::params::config_linux_lvm_vgpath) $linux_lvm_vgpath = pick_undef($hash['linux_lvm_vgpath'], $rsnapshot::params::config_linux_lvm_vgpath)
$linux_lvm_mountpath = pick_undef($hash['linux_lvm_mountpath'], $rsnapshot::params::config_linux_lvm_mountpath) $linux_lvm_mountpath = pick_undef($hash['linux_lvm_mountpath'], $rsnapshot::params::config_linux_lvm_mountpath)
$no_create_root = pick_undef($hash['no_create_root'], $rsnapshot::params::config_no_create_root) $no_create_root = pick_undef($hash['no_create_root'], $rsnapshot::params::config_no_create_root)
$logpath = pick($hash['logpath'], $rsnapshot::logpath, $rsnapshot::params::config_logpath)
$verbose = pick($hash['verbose'], $rsnapshot::params::config_verbose) $verbose = pick($hash['verbose'], $rsnapshot::params::config_verbose)
$loglevel = pick($hash['loglevel'], $rsnapshot::params::config_loglevel) $loglevel = pick($hash['loglevel'], $rsnapshot::params::config_loglevel)
$stop_on_stale_lockfile = pick_undef($hash['stop_on_stale_lockfile'], $rsnapshot::params::config_stop_on_stale_lockfile) $stop_on_stale_lockfile = pick_undef($hash['stop_on_stale_lockfile'], $rsnapshot::params::config_stop_on_stale_lockfile)
@@ -66,9 +70,9 @@ class rsnapshot::config (
$one_fs = pick_undef($hash['one_fs'], $rsnapshot::params::config_one_fs) $one_fs = pick_undef($hash['one_fs'], $rsnapshot::params::config_one_fs)
$interval = pick($hash['interval'], $rsnapshot::params::config_interval) $interval = pick($hash['interval'], $rsnapshot::params::config_interval)
$retain = pick_undef($hash['retain'], $rsnapshot::params::config_retain) $retain = pick_undef($hash['retain'], $rsnapshot::params::config_retain)
$include = pick_undef($hash['include'], $rsnapshot::params::config_include) $include = pick($hash['include'], [])
$exclude = pick_undef($hash['exclude'], $rsnapshot::params::config_exclude) $exclude = pick($hash['exclude'], [])
$include_file = pick_undef($hash['include_file'], $rsnapshot::params::config_include_file) $include_file = pick($hash['include_file'], $rsnapshot::params::config_include_file, "${conf_d}/${host}.include")
$exclude_file = pick($hash['exclude_file'], $rsnapshot::params::config_exclude_file, "${conf_d}/${host}.exclude") $exclude_file = pick($hash['exclude_file'], $rsnapshot::params::config_exclude_file, "${conf_d}/${host}.exclude")
$link_dest = pick_undef($hash['link_dest'], $rsnapshot::params::config_link_dest) $link_dest = pick_undef($hash['link_dest'], $rsnapshot::params::config_link_dest)
$sync_first = pick_undef($hash['sync_first'], $rsnapshot::params::config_sync_first) $sync_first = pick_undef($hash['sync_first'], $rsnapshot::params::config_sync_first)
@@ -108,19 +112,22 @@ class rsnapshot::config (
$use_lazy_deletes_num = bool2num($use_lazy_deletes) $use_lazy_deletes_num = bool2num($use_lazy_deletes)
} }
if $include != '' { $real_include = $rsnapshot::include + $include
unless empty($real_include) {
file { $include_file: file { $include_file:
ensure => 'file', ensure => 'file',
content => template('rsnapshot/include.erb'), content => template('rsnapshot/include.erb'),
} }
} }
if $exclude != '' { $real_exclude = $rsnapshot::exclude + $exclude
unless empty($real_exclude) {
file { $exclude_file: file { $exclude_file:
ensure => 'file', ensure => 'file',
content => template('rsnapshot/exclude.erb'), content => template('rsnapshot/exclude.erb'),
} }
} }
concat { $config: concat { $config:
} }
concat::fragment { "${config} for ${host}": concat::fragment { "${config} for ${host}":
@@ -128,21 +135,22 @@ class rsnapshot::config (
content => template('rsnapshot/rsnapshot.erb'), content => template('rsnapshot/rsnapshot.erb'),
} }
if has_key($hash, backup_scripts) { if has_key($hash, backup_scripts) {
$hash[backup_scripts].each |$script, $scriptconf| {
$hash[backup_scripts].each |$script, $credentials| { $real_script = deep_merge($rsnapshot::params::backup_scripts[$script], $rsnapshot::backup_scripts[$script], $hash[backup_scripts][$script])
$dbbackup_user = $real_script[dbbackup_user]
if is_hash($credentials) { $dbbackup_password = $real_script[dbbackup_password]
$dbbackup_user = $credentials['dbbackup_user'] $dumper = $real_script[dumper]
$dbbackup_password = $credentials['dbbackup_password'] $dump_flags = $real_script[dump_flags]
} else { $ignore_dbs = $real_script[ignore_dbs]
$dbbackup_user = $rsnapshot::default_backup_scripts[$script]['dbbackup_user'] $compress = $real_script[compress]
$dbbackup_password = $rsnapshot::default_backup_scripts[$script]['dbbackup_password'] $commands = $real_script[commands]
}
concat::fragment { "${host}_${script}_backup": concat::fragment { "${host}_${script}_backup":
target => $config, target => $config,
content => "backup_script ${conf_d}/${host}.${script}.sh ./${script}\n", content => "backup_script ${conf_d}/${host}.${script}.sh ./${script}\n",
} }
file { "${conf_d}/${host}.${script}.sh": file { "${conf_d}/${host}.${script}.sh":
@@ -158,60 +166,26 @@ class rsnapshot::config (
concat { $cronfile: concat { $cronfile:
} }
# create cron files for each backup level # create cron files for each backup level
# merge possible cron definitions to one
$real_cron = deep_merge($rsnapshot::params::cron, $rsnapshot::cron, $hash[cron])
concat::fragment { "mailto for $host":
content => "#This file is managed by puppet\nMAILTO=${real_cron[mailto]}\n\n",
target => $cronfile,
order => 1,
}
$backup_levels.each |String $level| { $backup_levels.each |String $level| {
$mailto = $real_cron[mailto]
$minute = rand_from_array($real_cron[$level][minute], "${host}.${level}.minute")
$hour = rand_from_array($real_cron[$level][hour], "${host}.${level}.hour")
$monthday = rand_from_array($real_cron[$level][monthday], "${host}.${level}.monthday")
$month = rand_from_array($real_cron[$level][month], "${host}.${level}.month")
$weekday = rand_from_array($real_cron[$level][weekday], "${host}.${level}.weekday")
# allow to globally override ranges, create random numbers for backup_levels daily, weekly, monthly
if has_key($hash,cron){
if has_key($hash[cron], $level) {
$cron = $hash[cron][$level]
} else {
if has_key($default_cron, $level) {
$cron = $default_cron[$level]
} else {
$cron = $rsnapshot::params::cron[$level]
}
}
} else {
if has_key($default_cron, $level) {
$cron = $default_cron[$level]
} else {
$cron = $rsnapshot::params::cron[$level]
}
}
if has_key($cron, minute) {
$c_min = $cron[minute]
} else {
$c_min = $rsnapshot::params::cron[$level][minute]
}
if has_key($cron, hour) {
$c_hour = $cron[hour]
} else {
$c_hour = $rsnapshot::params::cron[$level][hour]
}
if has_key($cron, monthday) {
$c_monthday = $cron[monthday]
} else {
$c_monthday = $rsnapshot::params::cron[$level][monthday]
}
if has_key($cron, month) {
$c_month = $cron[month]
} else {
$c_month = $rsnapshot::params::cron[$level][month]
}
if has_key($cron, weekday) {
$c_weekday = $cron[weekday]
} else {
$c_weekday = $rsnapshot::params::cron[$level][weekday]
}
$minute = rand_from_array($c_min, "${host}.${level}.minute")
$hour = rand_from_array($c_hour, "${host}.${level}.hour")
$monthday = rand_from_array($c_monthday, "${host}.${level}.monthday")
$month = rand_from_array($c_month, "${host}.${level}.month")
$weekday = rand_from_array($c_weekday, "${host}.${level}.weekday")
concat::fragment { "${host}.${level}": concat::fragment { "${host}.${level}":
target => $cronfile, target => $cronfile,
content => template('rsnapshot/cron.erb'), content => template('rsnapshot/cron.erb'),
order => 2,
} }
} }
} }

View File

@@ -14,17 +14,22 @@ class rsnapshot (
$package_ensure = $rsnapshot::params::package_ensure, $package_ensure = $rsnapshot::params::package_ensure,
$cron = $rsnapshot::params::cron, $cron = $rsnapshot::params::cron,
$backup_scripts = $rsnapshot::params::backup_scripts, $backup_scripts = $rsnapshot::params::backup_scripts,
$include = $rsnapshot::params::config_include,
$exclude = $rsnapshot::params::config_exclude, $exclude = $rsnapshot::params::config_exclude,
$snapshot_root = $rsnapshot::params::config_snapshot_root, $snapshot_root = $rsnapshot::params::config_snapshot_root,
$backup_levels = $rsnapshot::params::config_backup_levels,
$cron_service_name = $rsnapshot::params::cron_service_name,
) inherits rsnapshot::params { ) inherits rsnapshot::params {
$default_backup_scripts = $rsnapshot::params::backup_scripts + $backup_scripts $default_backup_scripts = $rsnapshot::params::backup_scripts + $backup_scripts
$default_exclude = $rsnapshot::params::config_exclude + $exclude $default_exclude = $rsnapshot::params::config_exclude + $exclude
if $hosts { if $hosts {
class { '::rsnapshot::install': }-> class { '::rsnapshot::install': }->
class { '::rsnapshot::config': } class { '::rsnapshot::config': }~>
class { '::rsnapshot::service': }
contain '::rsnapshot::install' contain '::rsnapshot::install'
contain '::rsnapshot::config' contain '::rsnapshot::config'
contain '::rsnapshot::service'
} }
} }

View File

@@ -7,6 +7,11 @@ class rsnapshot::params {
$config_backup_user = 'root' $config_backup_user = 'root'
$package_name = 'rsnapshot' $package_name = 'rsnapshot'
$package_ensure = 'present' $package_ensure = 'present'
$cron_service_name = $::osfamily ? {
'RedHat' => 'crond',
'Debian' => 'cron',
default => '',
}
$cron_dir = '/etc/cron.d' $cron_dir = '/etc/cron.d'
$config_backup_levels = [ 'daily', 'weekly', 'monthly' ] $config_backup_levels = [ 'daily', 'weekly', 'monthly' ]
$config_backup_defaults = true $config_backup_defaults = true
@@ -32,7 +37,7 @@ class rsnapshot::params {
$config_logpath = '/var/log/rsnapshot' $config_logpath = '/var/log/rsnapshot'
$config_logfile = '/var/log/rsnapshot.log' # unused, we are logging to $logpath/$host.log $config_logfile = '/var/log/rsnapshot.log' # unused, we are logging to $logpath/$host.log
$config_lockpath = '/var/run/rsnapshot' $config_lockpath = '/var/run/rsnapshot'
$config_snapshot_root = '/backup/' $config_snapshot_root = '/backup'
$config_no_create_root = undef # bool, true or false $config_no_create_root = undef # bool, true or false
$config_verbose = '2' $config_verbose = '2'
$config_loglevel = '4' $config_loglevel = '4'
@@ -62,6 +67,7 @@ class rsnapshot::params {
} }
$config_backup_scripts = {} $config_backup_scripts = {}
$cron = { $cron = {
mailto => 'admin@example.com',
hourly => { hourly => {
minute => '0..59', minute => '0..59',
hour => '*', # you could also do: ['21..23','0..4','5'], hour => '*', # you could also do: ['21..23','0..4','5'],
@@ -92,14 +98,32 @@ class rsnapshot::params {
}, },
} }
$backup_scripts = { $backup_scripts = {
mysql => { mysql => {
dbbackup_user => 'root', dbbackup_user => 'root',
dbbackup_password => 'myFancyPassWord', dbbackup_password => '',
dumper => 'mysqldump',
dump_flags => '--single-transaction --quick --routines --ignore-table=mysql.event',
ignore_dbs => [ 'information_schema', 'performance_schema' ],
compress => 'pbzip2',
}, },
psql => { psql => {
dbbackup_user => 'postgres', dbbackup_user => 'postgres',
dbbackup_password => '', dbbackup_password => '',
dumper => 'pg_dump',
dump_flags => '-Fc',
ignore_dbs => [ 'postgres' ],
compress => 'pbzip2',
}, },
misc => {}, misc => {
commands => $::osfamily ? {
'RedHat' => [
'rpm -qa --qf="%{name}," > packages.txt',
],
'Debian' => [
'dpkg --get-selections > packages.txt',
],
default => [],
},
}
} }
} }

10
manifests/service.pp Normal file
View File

@@ -0,0 +1,10 @@
# == Class: rsnapshot::service
#
# Reloads cron
class rsnapshot::service {
service { $rsnapshot::cron_service_name:
ensure => running,
}
}

View File

@@ -1,6 +1,6 @@
{ {
"name": "loomsen-rsnapshot", "name": "loomsen-rsnapshot",
"version": "0.4.0", "version": "1.0.1",
"author": "loomsen", "author": "loomsen",
"summary": "Configures rsnapshot.", "summary": "Configures rsnapshot.",
"license": "Apache-2.0", "license": "Apache-2.0",

View File

@@ -1,3 +1,3 @@
<% @exclude.each do |exc| -%> <% @real_exclude.each do |exc| -%>
<%= exc %> <%= exc %>
<% end %> <% end %>

View File

@@ -1,3 +1,3 @@
<% @include.each do |inc| -%> <% @real_include.each do |inc| -%>
<%= inc %> <%= inc %>
<% end %> <% end %>

7
templates/misc.sh.erb Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
#This file is managed by puppet
#
<%@commands.each do |command| -%>
ssh -l <%=@backup_user-%> <%=@host-%> '<%=command-%>'
<%end-%>

30
templates/mysql.sh.erb Normal file
View File

@@ -0,0 +1,30 @@
#!/bin/bash
# This file is managed by puppet
# written by Norbert Varzariu <loomsen@gmail.com>
# This Script is triggered by rsnapshot and dumps the specified dbs on the configured host.
#
host=<%=@host%>
user=<%=@dbbackup_user%>
pass=<%=@dbbackup_password%>
<% if (@dbbackup_user == 'root' && @dbbackup_password == '') -%>
dbs=(
$(ssh -l <%=@backup_user-%> "$host" "mysql -e 'show databases' | sed '1d;<%@ignore_dbs.to_a.each do |db|-%>/<%=db-%>/d;<%end-%>'" )
)
<%else-%>
dbs=(
$(ssh -l <%=@backup_user-%> "$host" "mysql -u <%=@dbbackup_user-%> -p'<%=@dbbackup_password-%>' -e 'show databases' | sed '1d;<%@ignore_dbs.each do |db|-%>/<%=db-%>/d;<%end-%>'" )
)
<%end-%>
for db in "${dbs[@]}"; do
<% if (@dbbackup_user == 'root' && @dbbackup_password = '' )-%>
ssh -l <%=@backup_user-%> "$host" "<%=@dumper-%> <%=@dump_flags-%> ${db}" > "$db".sql
<%else-%>
ssh -l <%=@backup_user-%> "$host" "<%=@dumper-%> --user=<%=@dbbackup_user-%> --password='<%=@dbbackup_password-%>' <%=@dump_flags-%> ${db}" > "$db".sql
<%end-%>
wait
<% if @compress != '' -%>
<%=@compress-%> "$db".sql
<%end-%>
done

21
templates/psql.sh.erb Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
# This file is managed by puppet
# written by Norbert Varzariu <loomsen@gmail.com>
# This Script is triggered by rsnapshot and dumps the specified dbs on the configured host.
#
host=<%=@host%>
user=<%=@dbbackup_user%>
pass=<%=@dbbackup_password%>
#PGPASSWORD="$pass"
dbs=(
$(ssh -l <%=@backup_user-%> "$host" "PGPASSWORD=${pass} psql -U ${user} -Atc \"SELECT datname FROM pg_database WHERE NOT datistemplate AND NOT datname ~ '<%@ignore_dbs.each do |db|-%><%if db == @ignore_dbs.last-%><%=db-%><%else-%><%=db-%>|<%end-%><%end-%>'\"")
)
for db in "${dbs[@]}"; do
ssh -l <%=@backup_user-%> "$host" "PGPASSWORD=${pass} <%=@dumper-%> -U ${user} <%=@dump_flags-%> ${db}" > "$db".sql
wait
<% if @compress != '' -%>
<%=@compress-%> "$db".sql
<%end-%>
done

View File

@@ -85,12 +85,12 @@ du_args <%= @du_args %>
<% if @one_fs != '' -%> <% if @one_fs != '' -%>
one_fs <%= @one_fs_num %> one_fs <%= @one_fs_num %>
<% end -%> <% end -%>
<% if @include != '' -%> <% unless @real_include.empty? -%>
<% if @include_file != '' -%> <% if @include_file != '' -%>
include_file <%= @include_file %> include_file <%= @include_file %>
<% end -%> <% end -%>
<% end -%> <% end -%>
<% if @exclude != '' -%> <% unless @real_exclude.empty? -%>
<% if @exclude_file != '' -%> <% if @exclude_file != '' -%>
exclude_file <%= @exclude_file %> exclude_file <%= @exclude_file %>
<% end -%> <% end -%>