mirror of
https://github.com/krislamo/puppet-rsnapshot
synced 2025-09-13 07:49:29 +00:00
Compare commits
68 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d1a262800f | ||
|
a78ccc1e43 | ||
|
6f92da8a17 | ||
|
a67dd7ea29 | ||
|
1be930d6cf | ||
|
cbf6a3db52 | ||
|
283ade9782 | ||
|
f92a8814ac | ||
|
85532a73b2 | ||
|
87775af5c7 | ||
|
960b0090e4 | ||
|
46c96d9b6c | ||
|
6e7d8e02f3 | ||
|
7dd4b98f1a | ||
|
5c35e8378b | ||
|
c5de50bd71 | ||
|
9f0fdf0547 | ||
|
90ee92acb8 | ||
|
d7436ed582 | ||
|
59cdc23ca1 | ||
|
a394973d4a | ||
|
a32ddcf208 | ||
|
7d39968e12 | ||
|
c6b7caefb7 | ||
|
75e778ad9c | ||
|
3dea0ba9e1 | ||
|
feb0898c01 | ||
|
f6e32dd53b | ||
|
cb04f5e70f | ||
|
cf50ff6251 | ||
|
decccb771f | ||
|
1feea03aaa | ||
|
a37c7f71ea | ||
|
f5003e3758 | ||
|
93be1c12ac | ||
|
ea87bf924a | ||
|
c79d1c7fc6 | ||
|
98519a8ebc | ||
|
a386a710b7 | ||
|
0c5afff356 | ||
|
3c9357f3fe | ||
|
0618f0fff3 | ||
|
5d82b82757 | ||
|
0e80853628 | ||
|
1fe21e5bba | ||
|
08cc0037b1 | ||
|
b3ab06b63c | ||
|
d252ac64a0 | ||
|
8dd6298c56 | ||
|
343d12c61b | ||
|
8817ed33ff | ||
|
5cb6c2d235 | ||
|
daba8a562a | ||
|
f67cd5a517 | ||
|
33e3fa685a | ||
|
03e385b2aa | ||
|
b9c0e0cebc | ||
|
46a0a4faaf | ||
|
441c6a0584 | ||
|
eb7a73f460 | ||
|
3bedb6efaa | ||
|
86073f42b1 | ||
|
eb643443fd | ||
|
8ba0042a94 | ||
|
942e9a7697 | ||
|
f7eec6ee5f | ||
|
12b11a6a43 | ||
|
dcd5f532a9 |
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
BUNDLE_PATH: vendor/bundle
|
|
||||||
BUNDLE_DISABLE_SHARED_GEMS: '1'
|
|
@@ -1,8 +1,10 @@
|
|||||||
fixtures:
|
fixtures:
|
||||||
forge_modules:
|
forge_modules:
|
||||||
stdlib:
|
stdlib:
|
||||||
repo: "puppetlabs/stdlib"
|
repo: "puppetlabs/stdlib"
|
||||||
epel:
|
epel:
|
||||||
repo: "stahnma/epel"
|
repo: "stahnma/epel"
|
||||||
|
concat:
|
||||||
|
repo: "puppetlabs/concat"
|
||||||
symlinks:
|
symlinks:
|
||||||
"rsnapshot": "#{source_dir}"
|
"rsnapshot": "#{source_dir}"
|
||||||
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.bundle
|
||||||
|
Gemfile.lock
|
||||||
|
pkg/
|
||||||
|
vendor/
|
@@ -7,6 +7,8 @@ script: "bundle exec rake validate && bundle exec rake spec SPEC_OPTS='--format
|
|||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
include:
|
include:
|
||||||
|
rvm: 2.1
|
||||||
env: PUPPET_GEM_VERSION="~> 4.0"
|
env: PUPPET_GEM_VERSION="~> 4.0"
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
|
|
||||||
|
1
Gemfile
1
Gemfile
@@ -5,3 +5,4 @@ gem 'puppet', puppetversion
|
|||||||
gem 'puppetlabs_spec_helper', '>= 0.8.2'
|
gem 'puppetlabs_spec_helper', '>= 0.8.2'
|
||||||
gem 'puppet-lint', '>= 1.0.0'
|
gem 'puppet-lint', '>= 1.0.0'
|
||||||
gem 'facter', '>= 1.7.0'
|
gem 'facter', '>= 1.7.0'
|
||||||
|
gem 'metadata-json-lint'
|
||||||
|
291
README.md
291
README.md
@@ -1,6 +1,6 @@
|
|||||||
# rsnapshot
|
[](https://travis-ci.org/loomsen/puppet-rsnapshot)
|
||||||
|
|
||||||
## NOTE: ! Configuration for backup_scripts changed with version 0.4.0 (it was pretty useless in prior versions) !
|
# rsnapshot
|
||||||
|
|
||||||
#### Table of Contents
|
#### Table of Contents
|
||||||
|
|
||||||
@@ -133,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:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -201,41 +205,20 @@ Takes an Integer, a String or an Array as input, and returns a random entry from
|
|||||||
|
|
||||||
The following parameters are available in the `::rsnapshot` class:
|
The following parameters are available in the `::rsnapshot` class:
|
||||||
|
|
||||||
#### `$hosts`
|
|
||||||
Hash containing the hosts to be backed up and optional overrides per host
|
|
||||||
(Default: undef (do nothing when no host given))
|
|
||||||
#### `$conf_d`
|
|
||||||
The place where the configs will be dropped
|
|
||||||
(Default: /etc/rsnapshot (will be created if it doesn't exist))
|
|
||||||
#### `$backup_user`
|
|
||||||
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.)
|
|
||||||
#### `$package_name`
|
|
||||||
(Default: rsnapshot)
|
|
||||||
#### `$package_ensure`
|
|
||||||
(Default: present)
|
|
||||||
#### `$cron_dir`
|
|
||||||
Directory to drop the cron files to. Crons will be created per host.
|
|
||||||
(Default: /etc/cron.d)
|
|
||||||
#### `$backup_levels`
|
|
||||||
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)
|
|
||||||
(Default: [ 'daily', 'weekly', ] )
|
|
||||||
#### `$backup_defaults`
|
#### `$backup_defaults`
|
||||||
Boolean. Backup default backup dirs or not.
|
Boolean. Backup default backup dirs or not.
|
||||||
(Default: true)
|
(Default: true)
|
||||||
|
|
||||||
#### `$default_backup`
|
#### `$backup_levels`
|
||||||
The default backup directories. This will apply to all hosts unless you set [backup_defaults](#backup_defaults) = false
|
Array containing the backup levels (hourly, daily, weekly, monthly)
|
||||||
Default is:
|
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)
|
||||||
|
(Default: [ 'daily', 'weekly', ] )
|
||||||
```puppet
|
#### `$backup_user`
|
||||||
$default_backup = {
|
The user to run the backup scripts as
|
||||||
'/etc' => './',
|
(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.)
|
||||||
'/home' => './',
|
#### `$conf_d`
|
||||||
}
|
The place where the configs will be dropped
|
||||||
```
|
(Default: /etc/rsnapshot (will be created if it doesn't exist))
|
||||||
|
|
||||||
#### `$cron`
|
#### `$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.
|
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
|
||||||
@@ -243,10 +226,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 +246,7 @@ Or in hiera:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
rsnapshot::cron:
|
rsnapshot::cron:
|
||||||
|
mailto: 'admin@example.com'
|
||||||
daily:
|
daily:
|
||||||
minute: '20'
|
minute: '20'
|
||||||
weekly:
|
weekly:
|
||||||
@@ -270,16 +258,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,
|
||||||
@@ -297,6 +301,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'],
|
||||||
@@ -328,6 +333,44 @@ Default is:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### `$cron_dir`
|
||||||
|
Directory to drop the cron files to. Crons will be created per host.
|
||||||
|
(Default: /etc/cron.d)
|
||||||
|
#### `$default_backup`
|
||||||
|
The default backup directories. This will apply to all hosts unless you set [backup_defaults](#backup_defaults) = false
|
||||||
|
Default is:
|
||||||
|
|
||||||
|
```puppet
|
||||||
|
$default_backup = {
|
||||||
|
'/etc' => './',
|
||||||
|
'/home' => './',
|
||||||
|
}
|
||||||
|
```
|
||||||
|
#### `$cronfile_prefix_use`
|
||||||
|
Bool. Set this to true if you want your cronfiles to have a prefix.
|
||||||
|
(Default: false)
|
||||||
|
#### `$cronfile_prefix`
|
||||||
|
Optional prefix to add to the cronfiles name. Your files will be named: prefix_hostname
|
||||||
|
(Default: 'rsnapshot_' only if you set $cronfile_prefix_use = true)
|
||||||
|
#### `$hosts`
|
||||||
|
Hash containing the hosts to be backed up and optional overrides per host
|
||||||
|
(Default: undef (do nothing when no host given))
|
||||||
|
#### `$interval`
|
||||||
|
How many backups of each level to keep.
|
||||||
|
Default is:
|
||||||
|
|
||||||
|
```puppet
|
||||||
|
$interval = {
|
||||||
|
'daily' => '7',
|
||||||
|
'weekly' => '4',
|
||||||
|
'monthly' => '6',
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `$package_ensure`
|
||||||
|
(Default: present)
|
||||||
|
#### `$package_name`
|
||||||
|
(Default: rsnapshot)
|
||||||
#### `$snapshot_root`
|
#### `$snapshot_root`
|
||||||
global. the directory holding your backups.
|
global. the directory holding your backups.
|
||||||
(Default: /backup)
|
(Default: /backup)
|
||||||
@@ -351,35 +394,68 @@ You will end up with a structure like:
|
|||||||
└── weekly.0
|
└── weekly.0
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `$interval`
|
|
||||||
How many backups of each level to keep.
|
|
||||||
Default is:
|
|
||||||
|
|
||||||
```puppet
|
|
||||||
$interval = {
|
|
||||||
'daily' => '7',
|
|
||||||
'weekly' => '4',
|
|
||||||
'monthly' => '6',
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `$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 => '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 => [ 'postgres' ],
|
||||||
},
|
},
|
||||||
misc => {},
|
misc => {
|
||||||
|
commands => $::osfamily ? {
|
||||||
|
'RedHat' => [
|
||||||
|
'rpm -qa --qf="%{name}," > packages.txt',
|
||||||
|
],
|
||||||
|
'Debian' => [
|
||||||
|
'dpkg --get-selections > packages.txt',
|
||||||
|
],
|
||||||
|
default => [],
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Configuration example:
|
Configuration example:
|
||||||
@@ -398,21 +474,31 @@ 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' ]
|
||||||
|
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:
|
The scripts look like this:
|
||||||
mysql:
|
|
||||||
|
##### `bazqux.de`
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
@@ -420,34 +506,103 @@ host=bazqux.de
|
|||||||
user=myuser
|
user=myuser
|
||||||
pass=mypassword
|
pass=mypassword
|
||||||
|
|
||||||
dbs=( $(mysql -h "$host" -u "$user" -p"$pass" -e 'show databases' | sed '1d;/information_schema/d;/performance_schema/d') )
|
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
|
for db in "${dbs[@]}"; do
|
||||||
mysqldump --host="$host" --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
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
ssh bazqux.de 'cat /etc/hostname > hostname.txt'
|
||||||
|
|
||||||
|
ssh bazqux.de 'date > date.txt'
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### `foobar.com`
|
||||||
|
|
||||||
psql:
|
psql:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
host=foobar.com
|
host=foobar.com
|
||||||
user=backupuser
|
user=dbbackup
|
||||||
pass=password
|
pass=yeshorsebatterystaple
|
||||||
|
|
||||||
PGPASSWORD="$pass"
|
PGPASSWORD="$pass"
|
||||||
dbs=( $(psql -h "$host" -U "$user" -Atc "SELECT datname FROM pg_database WHERE NOT datistemplate AND datname <> 'postgres'") )
|
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
|
for db in "${dbs[@]}"; do
|
||||||
ssh -l root "$host" "pg_dump -U ${user} -Fc ${db}" > "$db".sql
|
ssh -l root "$host" "pg_dump -U ${user} -Fc ${db}" > "$db".sql
|
||||||
wait
|
wait
|
||||||
pbzip2 -p3 "$db".sql
|
pbzip2 "$db".sql
|
||||||
done
|
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
|
||||||
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)
|
||||||
@@ -596,4 +751,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.
|
||||||
|
@@ -2,8 +2,8 @@
|
|||||||
#
|
#
|
||||||
# manage host configs
|
# manage host configs
|
||||||
class rsnapshot::config (
|
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
|
||||||
@@ -12,6 +12,8 @@ class rsnapshot::config (
|
|||||||
$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')
|
||||||
$logpath = pick($rsnapshot::logpath, $rsnapshot::params::config_logpath)
|
$logpath = pick($rsnapshot::logpath, $rsnapshot::params::config_logpath)
|
||||||
|
$cronfile_prefix_use = pick($rsnapshot::cronfile_prefix_use, $rsnapshot::params::cronfile_prefix_use, false)
|
||||||
|
$cronfile_prefix = pick($rsnapshot::cronfile_prefix, $rsnapshot::params::cronfile_prefix, '')
|
||||||
# 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',
|
||||||
@@ -31,12 +33,12 @@ class rsnapshot::config (
|
|||||||
|
|
||||||
# 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:
|
||||||
# { foo => } and converts those to { foo => {} }
|
# { foo => } and converts those to { foo => {} }
|
||||||
$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::backup_levels, 'weekly')
|
$backup_levels = pick($hash['backup_levels'], $rsnapshot::backup_levels, 'weekly')
|
||||||
$backup = $hash['backup']
|
$backup = $hash['backup']
|
||||||
@@ -135,21 +137,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":
|
||||||
@@ -157,18 +160,44 @@ class rsnapshot::config (
|
|||||||
content => template("rsnapshot/${script}.sh.erb"),
|
content => template("rsnapshot/${script}.sh.erb"),
|
||||||
mode => '0755',
|
mode => '0755',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if $cronfile_prefix_use {
|
||||||
|
$rsnapshot_prefix = $rsnapshot::cronfile_prefix
|
||||||
|
} else {
|
||||||
|
$rsnapshot_prefix = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
# cron on Debian seems to ignore files that have dots in their name; replace
|
||||||
|
# them with underscores (issue #2)
|
||||||
|
case $::osfamily {
|
||||||
|
'Debian': {
|
||||||
|
$cron_name = regsubst($host, '\.', '_', 'G')
|
||||||
|
$cronfile = "${cron_dir}/${rsnapshot_prefix}${cron_name}"
|
||||||
|
}
|
||||||
|
'RedHat': {
|
||||||
|
$cronfile = "${cron_dir}/${rsnapshot_prefix}${host}"
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
$cronfile = "${cron_dir}/${rsnapshot_prefix}${host}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$cronfile = "${cron_dir}/${host}"
|
|
||||||
concat { $cronfile:
|
concat { $cronfile:
|
||||||
}
|
}
|
||||||
# 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")
|
||||||
@@ -178,8 +207,8 @@ 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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,20 +5,24 @@
|
|||||||
# === Parameters
|
# === Parameters
|
||||||
#
|
#
|
||||||
class rsnapshot (
|
class rsnapshot (
|
||||||
$hosts = $rsnapshot::params::hosts,
|
$hosts = $rsnapshot::params::hosts,
|
||||||
$conf_d = $rsnapshot::params::conf_d,
|
$conf_d = $rsnapshot::params::conf_d,
|
||||||
$logpath = $rsnapshot::params::config_logpath,
|
$logpath = $rsnapshot::params::config_logpath,
|
||||||
$lockpath = $rsnapshot::params::config_lockpath,
|
$lockpath = $rsnapshot::params::config_lockpath,
|
||||||
$default_backup = $rsnapshot::params::config_default_backup,
|
$default_backup = $rsnapshot::params::config_default_backup,
|
||||||
$package_name = $rsnapshot::params::package_name,
|
$package_name = $rsnapshot::params::package_name,
|
||||||
$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,
|
$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,
|
$backup_levels = $rsnapshot::params::config_backup_levels,
|
||||||
$cron_service_name = $rsnapshot::params::cron_service_name,
|
$cron_service_name = $rsnapshot::params::cron_service_name,
|
||||||
|
$cronfile_prefix = $rsnapshot::params::config_cronfile_prefix,
|
||||||
|
$cronfile_prefix_use = $rsnapshot::params::config_cronfile_prefix_use,
|
||||||
|
$check_mk_job = $rsnapshot::params::config_check_mk_job,
|
||||||
|
|
||||||
) inherits rsnapshot::params {
|
) inherits rsnapshot::params {
|
||||||
|
|
||||||
$default_backup_scripts = $rsnapshot::params::backup_scripts + $backup_scripts
|
$default_backup_scripts = $rsnapshot::params::backup_scripts + $backup_scripts
|
||||||
@@ -32,4 +36,3 @@ class rsnapshot (
|
|||||||
contain '::rsnapshot::service'
|
contain '::rsnapshot::service'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,11 +7,16 @@ 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 = 'crond'
|
$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
|
||||||
$config_version = '1.2'
|
$config_version = '1.2'
|
||||||
|
$config_check_mk_job = false
|
||||||
$config_cmd_cp = '/bin/cp'
|
$config_cmd_cp = '/bin/cp'
|
||||||
$config_cmd_rm = '/bin/rm'
|
$config_cmd_rm = '/bin/rm'
|
||||||
$config_cmd_rsync = '/usr/bin/rsync'
|
$config_cmd_rsync = '/usr/bin/rsync'
|
||||||
@@ -21,6 +26,8 @@ class rsnapshot::params {
|
|||||||
$config_cmd_rsnapshot_diff = '/usr/bin/rsnapshot-diff'
|
$config_cmd_rsnapshot_diff = '/usr/bin/rsnapshot-diff'
|
||||||
$config_cmd_preexec = undef
|
$config_cmd_preexec = undef
|
||||||
$config_cmd_postexec = undef
|
$config_cmd_postexec = undef
|
||||||
|
$config_cronfile_prefix = 'rsnapshot_'
|
||||||
|
$config_cronfile_prefix_use = false
|
||||||
$config_use_lvm = undef
|
$config_use_lvm = undef
|
||||||
$config_linux_lvm_cmd_lvcreate = undef # '/sbin/lvcreate'
|
$config_linux_lvm_cmd_lvcreate = undef # '/sbin/lvcreate'
|
||||||
$config_linux_lvm_cmd_lvremove = undef # '/sbin/lvremove'
|
$config_linux_lvm_cmd_lvremove = undef # '/sbin/lvremove'
|
||||||
@@ -39,7 +46,7 @@ class rsnapshot::params {
|
|||||||
$config_loglevel = '4'
|
$config_loglevel = '4'
|
||||||
$config_stop_on_stale_lockfile = undef # bool
|
$config_stop_on_stale_lockfile = undef # bool
|
||||||
$config_rsync_short_args = '-az'
|
$config_rsync_short_args = '-az'
|
||||||
$config_rsync_long_args = undef # defaults are --delete --numeric-ids --relative --delete-excluded
|
$config_rsync_long_args = undef # defaults are --delete --numeric-ids --relative --delete-excluded
|
||||||
$config_ssh_args = undef
|
$config_ssh_args = undef
|
||||||
$config_du_args = undef
|
$config_du_args = undef
|
||||||
$config_one_fs = undef
|
$config_one_fs = undef
|
||||||
@@ -63,6 +70,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'],
|
||||||
@@ -93,14 +101,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 => {
|
||||||
|
commands => $::osfamily ? {
|
||||||
|
'RedHat' => [
|
||||||
|
'rpm -qa --qf="%{name}," > packages.txt',
|
||||||
|
],
|
||||||
|
'Debian' => [
|
||||||
|
'dpkg --get-selections > packages.txt',
|
||||||
|
],
|
||||||
|
default => [],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
misc => {},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "loomsen-rsnapshot",
|
"name": "loomsen-rsnapshot",
|
||||||
"version": "0.5.2",
|
"version": "1.1.1",
|
||||||
"author": "loomsen",
|
"author": "loomsen",
|
||||||
"summary": "Configures rsnapshot.",
|
"summary": "Configures rsnapshot.",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
@@ -12,13 +12,10 @@
|
|||||||
"backup",
|
"backup",
|
||||||
"rsync"
|
"rsync"
|
||||||
],
|
],
|
||||||
"requirements": [
|
|
||||||
{ "name": "pe", "version_requirement": ">= 4.0.0" },
|
|
||||||
{ "name": "puppet", "version_requirement": ">= 4.0.0" }
|
|
||||||
],
|
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
{ "name": "puppetlabs-stdlib","version_range": ">= 1.0.0" },
|
{ "name": "puppetlabs-stdlib","version_requirement": ">= 1.0.0" },
|
||||||
{ "name": "stahnma-epel","version_range": ">= 1.0.0" }
|
{ "name": "stahnma-epel","version_requirement": ">= 1.0.0" },
|
||||||
|
{ "name": "puppetlabs-concat","version_requirement": ">= 2.0.0 < 3.0.0" }
|
||||||
],
|
],
|
||||||
"operatingsystem_support": [
|
"operatingsystem_support": [
|
||||||
{
|
{
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
describe 'rsnapshot' do
|
describe 'rsnapshot' do
|
||||||
|
let(:facts) {{ :osfamily => 'RedHat' }}
|
||||||
|
|
||||||
it { should contain_class('rsnapshot::params') }
|
it { should contain_class('rsnapshot::params') }
|
||||||
it { is_expected.to compile }
|
it { is_expected.to compile }
|
||||||
end
|
end
|
||||||
|
@@ -1 +1 @@
|
|||||||
<%= @minute %> <%= @hour %> <%= @month %> <%= @monthday %> <%= @weekday %> root /usr/bin/rsnapshot -c <%= @config %> <%= @level %>
|
<%= @minute %> <%= @hour %> <%= @monthday %> <%= @month %> <%= @weekday %> root<% if scope['rsnapshot::check_mk_job'] == true -%> mk-job rsnapshot_<%= @host %>_<%= @level %><% end -%> /usr/bin/rsnapshot -c <%= @config %> <%= @level %>
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# add custom stuff here
|
#This file is managed by puppet
|
||||||
# FIXME: remember to concat for custom stuff after the last line of the puppet generated script
|
#
|
||||||
<% if @osfamily == 'RedHat' -%>
|
<%@commands.each do |command| -%>
|
||||||
ssh <%=@host-%> rpm -qa --qf='%{name},' > packages.txt
|
ssh -l <%=@backup_user-%> <%=@host-%> <%=command-%>
|
||||||
|
|
||||||
<%end-%>
|
<%end-%>
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# ++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
|
@@ -1,16 +1,29 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# This file is managed by puppet
|
||||||
# written by Norbert Varzariu <loomsen@gmail.com>
|
# written by Norbert Varzariu <loomsen@gmail.com>
|
||||||
# This Script is triggered by rsnapshot and dumps the specified dbs on the configured host.
|
# This Script is triggered by rsnapshot and dumps the specified dbs on the configured host.
|
||||||
#
|
#
|
||||||
host=<%=@host%>
|
host=<%=@host%>
|
||||||
user=<%=@dbbackup_user%>
|
user=<%=@dbbackup_user%>
|
||||||
pass=<%=@dbbackup_password%>
|
|
||||||
|
|
||||||
dbs=( $(mysql -h "$host" -u "$user" -p"$pass" -e 'show databases' | sed '1d;/information_schema/d;/performance_schema/d') )
|
|
||||||
|
|
||||||
|
<% 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
|
for db in "${dbs[@]}"; do
|
||||||
mysqldump --host="$host" --user="$user" --password="$pass" --single-transaction --quick --routines --ignore-table=mysql.event "$db" > "$db".sql
|
<% 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
|
wait
|
||||||
pbzip2 -p3 "$db".sql
|
<% if @compress != '' -%>
|
||||||
|
<%=@compress-%> "$db".sql
|
||||||
|
<%end-%>
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@@ -1,17 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# This file is managed by puppet
|
||||||
# written by Norbert Varzariu <loomsen@gmail.com>
|
# written by Norbert Varzariu <loomsen@gmail.com>
|
||||||
# This Script is triggered by rsnapshot and dumps the specified dbs on the configured host.
|
# This Script is triggered by rsnapshot and dumps the specified dbs on the configured host.
|
||||||
#
|
#
|
||||||
host=<%=@host%>
|
host=<%=@host%>
|
||||||
user=<%=@dbbackup_user%>
|
user=<%=@dbbackup_user%>
|
||||||
pass=<%=@dbbackup_password%>
|
|
||||||
|
|
||||||
PGPASSWORD="$pass"
|
|
||||||
dbs=( $(psql -h "$host" -U "$user" -Atc "SELECT datname FROM pg_database WHERE NOT datistemplate AND datname <> 'postgres'") )
|
|
||||||
|
|
||||||
|
dbs=(
|
||||||
|
$(ssh -l <%=@backup_user-%> "$host" "PGPASSWORD='<%=@dbbackup_password%>' 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
|
for db in "${dbs[@]}"; do
|
||||||
ssh -l root "$host" "pg_dump -U ${user} -Fc ${db}" > "$db".sql
|
ssh -l <%=@backup_user-%> "$host" "PGPASSWORD='<%=@dbbackup_password%>' <%=@dumper-%> -U ${user} <%=@dump_flags-%> ${db}" > "$db".sql
|
||||||
wait
|
wait
|
||||||
pbzip2 -p3 "$db".sql
|
<% if @compress != '' -%>
|
||||||
|
<%=@compress-%> "$db".sql
|
||||||
|
<%end-%>
|
||||||
done
|
done
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user