mirror of
https://github.com/krislamo/puppet-rsnapshot
synced 2024-12-16 09:40:35 +00:00
update README
This commit is contained in:
parent
8ba0042a94
commit
eb643443fd
132
README.md
132
README.md
@ -243,10 +243,14 @@ The range notation is '$start..$end', so to pick a random hour from 8 pm to 2 am
|
|||||||
For the range feature to work, hours >0 and <10 must not have a preceding zero.
|
For the range feature to work, hours >0 and <10 must not have a preceding zero.
|
||||||
Wrong: `00.09`
|
Wrong: `00.09`
|
||||||
Correct: `0..9`
|
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' ],
|
||||||
@ -259,6 +263,7 @@ Or in hiera:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
rsnapshot::cron:
|
rsnapshot::cron:
|
||||||
|
mailto: 'admin@example.com'
|
||||||
daily:
|
daily:
|
||||||
minute: '20'
|
minute: '20'
|
||||||
weekly:
|
weekly:
|
||||||
@ -270,16 +275,24 @@ 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:
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Mails for webhost will go to admin@example.com (from the global override), those for webserver will go to support@example.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,
|
||||||
@ -297,6 +310,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'],
|
||||||
@ -365,33 +379,42 @@ 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
|
||||||
|
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
|
||||||
|
|
||||||
NOTE: the psql and mysql scripts will SSH into your host and try and use pg_dump/mysqldump respectively.
|
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.
|
Make sure you have those tools installed on your DB hosts.
|
||||||
|
|
||||||
You can do this by passing an array to [$rsnapshot::package_name](#package_name)
|
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)
|
||||||
|
|
||||||
Example:
|
|
||||||
```yaml
|
|
||||||
rsnapshot::package_name:
|
|
||||||
- rsnapshot
|
|
||||||
- pbzip2
|
|
||||||
```
|
|
||||||
|
|
||||||
Default is:
|
Default is:
|
||||||
|
|
||||||
```puppet
|
```puppet
|
||||||
$backup_scripts = {
|
$backup_scripts = {
|
||||||
mysql => {
|
mysql => {
|
||||||
dbbackup_user => 'root',
|
dbbackup_user => 'root',
|
||||||
dbbackup_password => 'myPassWord',
|
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 => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Configuration example:
|
Configuration example:
|
||||||
@ -410,8 +433,9 @@ rsnapshot::hosts:
|
|||||||
backup_scripts:
|
backup_scripts:
|
||||||
mysql:
|
mysql:
|
||||||
psql:
|
psql:
|
||||||
dbbackup_user: 'backupuser'
|
dumper: '/usr/local/bin/pg_dump'
|
||||||
dbbackup_password: 'password'
|
dump_flags: '-Fc'
|
||||||
|
ignore_dbs: [ 'db1', 'tmp_db' ]
|
||||||
bazqux:de:
|
bazqux:de:
|
||||||
backup_scripts:
|
backup_scripts:
|
||||||
mysql:
|
mysql:
|
||||||
@ -421,11 +445,13 @@ rsnapshot::hosts:
|
|||||||
|
|
||||||
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`
|
||||||
|
|
||||||
The scripts look like this:
|
The scripts look like this:
|
||||||
|
|
||||||
mysql:
|
##### `bazqux.de`
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
@ -440,17 +466,63 @@ dbs=(
|
|||||||
for db in "${dbs[@]}"; do
|
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"
|
ssh -l root "$host" "mysqldump --user=${user} --password=${pass} --single-transaction --quick --routines --ignore-table=mysql.event ${db}" > "${db}.sql"
|
||||||
wait
|
wait
|
||||||
pbzip2 -p3 "$db".sql
|
pbzip2 "$db".sql
|
||||||
done
|
done
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### `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
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### another example with root user and empty password
|
||||||
|
|
||||||
mysql with root user:
|
mysql with root user:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
host=bazqux.de
|
host=bazqux.de
|
||||||
user=root
|
user=root
|
||||||
|
password=
|
||||||
|
|
||||||
dbs=(
|
dbs=(
|
||||||
$(ssh -l root "$host" "mysql -e 'show databases' | sed '1d;/information_schema/d;/performance_schema/d'")
|
$(ssh -l root "$host" "mysql -e 'show databases' | sed '1d;/information_schema/d;/performance_schema/d'")
|
||||||
@ -459,31 +531,11 @@ dbs=(
|
|||||||
for db in "${dbs[@]}"; do
|
for db in "${dbs[@]}"; do
|
||||||
ssh -l root "$host" "mysqldump --single-transaction --quick --routines --ignore-table=mysql.event ${db}" > "${db}.sql"
|
ssh -l root "$host" "mysqldump --single-transaction --quick --routines --ignore-table=mysql.event ${db}" > "${db}.sql"
|
||||||
wait
|
wait
|
||||||
pbzip2 -p3 "$db".sql
|
pbzip2 "$db".sql
|
||||||
done
|
done
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
psql:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
#!/bin/bash
|
|
||||||
host=foobar.com
|
|
||||||
user=backupuser
|
|
||||||
pass=password
|
|
||||||
|
|
||||||
PGPASSWORD="$pass"
|
|
||||||
dbs=(
|
|
||||||
$(ssh -l root "$host" "psql -U ${user} -Atc \"SELECT datname FROM pg_database WHERE NOT datistemplate AND datname <> 'postgres'\"" )
|
|
||||||
)
|
|
||||||
|
|
||||||
for db in "${dbs[@]}"; do
|
|
||||||
ssh -l root "$host" "pg_dump -U ${user} -Fc ${db}" > "$db".sql
|
|
||||||
wait
|
|
||||||
pbzip2 -p3 "$db".sql
|
|
||||||
done
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### rsnapshot configuration variables
|
### rsnapshot configuration variables
|
||||||
Please read up on the following in the [rsnapshot manpage](http://linux.die.net/man/1/rsnapshot)
|
Please read up on the following in the [rsnapshot manpage](http://linux.die.net/man/1/rsnapshot)
|
||||||
|
@ -169,8 +169,14 @@ class rsnapshot::config (
|
|||||||
# create cron files for each backup level
|
# create cron files for each backup level
|
||||||
# merge possible cron definitions to one
|
# merge possible cron definitions to one
|
||||||
$real_cron = deep_merge($rsnapshot::params::cron, $rsnapshot::cron, $hash[cron])
|
$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")
|
$minute = rand_from_array($real_cron[$level][minute], "${host}.${level}.minute")
|
||||||
$hour = rand_from_array($real_cron[$level][hour], "${host}.${level}.hour")
|
$hour = rand_from_array($real_cron[$level][hour], "${host}.${level}.hour")
|
||||||
$monthday = rand_from_array($real_cron[$level][monthday], "${host}.${level}.monthday")
|
$monthday = rand_from_array($real_cron[$level][monthday], "${host}.${level}.monthday")
|
||||||
@ -180,6 +186,7 @@ class rsnapshot::config (
|
|||||||
concat::fragment { "${host}.${level}":
|
concat::fragment { "${host}.${level}":
|
||||||
target => $cronfile,
|
target => $cronfile,
|
||||||
content => template('rsnapshot/cron.erb'),
|
content => template('rsnapshot/cron.erb'),
|
||||||
|
order => 2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,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'],
|
||||||
|
Loading…
Reference in New Issue
Block a user