mirror of
https://github.com/krislamo/puppet-rsnapshot
synced 2024-12-16 09:40:35 +00:00
add custom commands to misc script
This commit is contained in:
parent
eb643443fd
commit
86073f42b1
39
README.md
39
README.md
@ -385,7 +385,7 @@ You can set
|
|||||||
`dumper` : path to the dump bin you wish to use
|
`dumper` : path to the dump bin you wish to use
|
||||||
`dump_flags`: flags for your dump bin
|
`dump_flags`: flags for your dump bin
|
||||||
`ignore_dbs` : databases to be ignored
|
`ignore_dbs` : databases to be ignored
|
||||||
|
`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
|
See below for defaults
|
||||||
|
|
||||||
NOTE: the psql and mysql scripts will SSH into your host and try and use $dumper.
|
NOTE: the psql and mysql scripts will SSH into your host and try and use $dumper.
|
||||||
@ -412,7 +412,16 @@ Default is:
|
|||||||
dump_flags => '-Fc',
|
dump_flags => '-Fc',
|
||||||
ignore_dbs => [],
|
ignore_dbs => [],
|
||||||
},
|
},
|
||||||
misc => {},
|
misc => {
|
||||||
|
commands => $::osfamily ? {
|
||||||
|
'RedHat' => [
|
||||||
|
'rpm -qa --qf="%{name}," > packages.txt',
|
||||||
|
],
|
||||||
|
'Debian' => [
|
||||||
|
'dpkg --get-selections > packages.txt',
|
||||||
|
],
|
||||||
|
default => [],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -436,11 +445,16 @@ rsnapshot::hosts:
|
|||||||
dumper: '/usr/local/bin/pg_dump'
|
dumper: '/usr/local/bin/pg_dump'
|
||||||
dump_flags: '-Fc'
|
dump_flags: '-Fc'
|
||||||
ignore_dbs: [ 'db1', 'tmp_db' ]
|
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
|
||||||
@ -448,6 +462,7 @@ This creates
|
|||||||
- the psql script will use `/usr/local/bin/pg_dump` as the dump program with flags `-Fc`
|
- 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
|
- 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:
|
||||||
|
|
||||||
@ -471,6 +486,17 @@ done
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
ssh bazqux.de 'cat /etc/hostname > hostname.txt'
|
||||||
|
|
||||||
|
ssh bazqux.de 'date > date.txt'
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##### `foobar.com`
|
##### `foobar.com`
|
||||||
|
|
||||||
psql:
|
psql:
|
||||||
@ -514,6 +540,15 @@ 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
|
##### another example with root user and empty password
|
||||||
|
|
||||||
mysql with root user:
|
mysql with root user:
|
||||||
|
@ -147,7 +147,8 @@ class rsnapshot::config (
|
|||||||
$dumper = $real_script[dumper]
|
$dumper = $real_script[dumper]
|
||||||
$dump_flags = $real_script[dump_flags]
|
$dump_flags = $real_script[dump_flags]
|
||||||
$ignore_dbs = $real_script[ignore_dbs]
|
$ignore_dbs = $real_script[ignore_dbs]
|
||||||
|
$compress = $real_script[compress]
|
||||||
|
$commands = $real_script[commands]
|
||||||
|
|
||||||
concat::fragment { "${host}_${script}_backup":
|
concat::fragment { "${host}_${script}_backup":
|
||||||
target => $config,
|
target => $config,
|
||||||
|
@ -7,7 +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 = '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
|
||||||
@ -100,6 +104,7 @@ class rsnapshot::params {
|
|||||||
dumper => 'mysqldump',
|
dumper => 'mysqldump',
|
||||||
dump_flags => '--single-transaction --quick --routines --ignore-table=mysql.event',
|
dump_flags => '--single-transaction --quick --routines --ignore-table=mysql.event',
|
||||||
ignore_dbs => [ 'information_schema', 'performance_schema' ],
|
ignore_dbs => [ 'information_schema', 'performance_schema' ],
|
||||||
|
compress => 'pbzip2',
|
||||||
},
|
},
|
||||||
psql => {
|
psql => {
|
||||||
dbbackup_user => 'postgres',
|
dbbackup_user => 'postgres',
|
||||||
@ -107,7 +112,18 @@ class rsnapshot::params {
|
|||||||
dumper => 'pg_dump',
|
dumper => 'pg_dump',
|
||||||
dump_flags => '-Fc',
|
dump_flags => '-Fc',
|
||||||
ignore_dbs => [],
|
ignore_dbs => [],
|
||||||
|
compress => 'pbzip2',
|
||||||
},
|
},
|
||||||
misc => {},
|
misc => {
|
||||||
|
commands => $::osfamily ? {
|
||||||
|
'RedHat' => [
|
||||||
|
'rpm -qa --qf="%{name}," > packages.txt',
|
||||||
|
],
|
||||||
|
'Debian' => [
|
||||||
|
'dpkg --get-selections > packages.txt',
|
||||||
|
],
|
||||||
|
default => [],
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# add custom stuff here
|
|
||||||
# FIXME: remember to concat for custom stuff after the last line of the puppet generated script
|
<%@commands.each do |command| -%>
|
||||||
<% if @osfamily == 'RedHat' -%>
|
ssh <%=@host-%> '<%=command-%>'
|
||||||
ssh <%=@host-%> rpm -qa --qf='%{name},' > packages.txt
|
|
||||||
<%end-%>
|
<%end-%>
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# ++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
|
@ -22,6 +22,8 @@ for db in "${dbs[@]}"; do
|
|||||||
ssh -l root "$host" "<%=@dumper-%> --user=<%=@dbbackup_user-%> --password='<%=@dbbackup_password-%>' <%=@dump_flags-%> ${db}" > "$db".sql
|
ssh -l root "$host" "<%=@dumper-%> --user=<%=@dbbackup_user-%> --password='<%=@dbbackup_password-%>' <%=@dump_flags-%> ${db}" > "$db".sql
|
||||||
<%end-%>
|
<%end-%>
|
||||||
wait
|
wait
|
||||||
pbzip2 "$db".sql
|
<% if @compress != '' -%>
|
||||||
|
<%=@compress-%> "$db".sql
|
||||||
|
<%end-%>
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@ dbs=(
|
|||||||
for db in "${dbs[@]}"; do
|
for db in "${dbs[@]}"; do
|
||||||
ssh -l root "$host" "<%=@dumper-%> -U ${user} <%=@dump_flags-%> ${db}" > "$db".sql
|
ssh -l root "$host" "<%=@dumper-%> -U ${user} <%=@dump_flags-%> ${db}" > "$db".sql
|
||||||
wait
|
wait
|
||||||
pbzip2 "$db".sql
|
<% if @compress != '' -%>
|
||||||
|
<%=@compress-%> "$db".sql
|
||||||
|
<%end-%>
|
||||||
done
|
done
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user