Skip to content

Commit 061e599

Browse files
author
Clayton O'Neill
committed
Add pre/post client side commands
This adds the ability to run one more more commands before or after the rsync runs on the client side. This can be used for database snapshots, dumps, etc.
1 parent e10bd6e commit 061e599

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,25 @@ that it is simply discarded. This allows the use of the same mysql profile on
247247
both production and test machines, with backups only on the production machines
248248
that are also rsnapshot clients.
249249

250+
### Back Up Pre and Post Actions
251+
252+
When backing up clients hosting services like databases, you may want to run a
253+
script to snapshot or quiesce the service. You can do this by specifying pre
254+
or post wrapper actions. These will be run on the client immediately before or
255+
after the rsync operation.
256+
257+
For example, to export the contents of the puppetdb database before running a
258+
backup of your puppetmaster:
259+
260+
```puppet
261+
262+
class profiles::puppetmaster {
263+
rsnapshot::client {
264+
cmd_wrapper_preexec => ['/usr/sbin/puppetdb export -o /root/puppetdb.export --port 8083'],
265+
cmd_wrapper_postexec => ['rm -f /root/puppetdb.export'],
266+
}
267+
}
268+
```
250269

251270
### Backing Up Machines Outside of Puppet
252271

@@ -373,6 +392,8 @@ resource to the backup server.
373392
to fqdn_rand, giving each host a random weekday for backups.
374393
* `backup_time_dom`: The day of the month that monthly backups should occur.
375394
This defaults to fqdn_rand, giving each host a random day of the month.
395+
* `cmd_wrapper_preexec`: Array of commands to run on client before backups.
396+
* `cmd_wrapper_postexec`: Array of commands to run on client after backups.
376397
* `cmd_preexec`: The path to any script that should run before backups.
377398
* `cmd_postexec`: The path to any script that should run after backups.
378399
* `cmd_client_rsync`: The path to the client side rsync binary.

manifests/client.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
$backup_time_hour = $rsnapshot::params::backup_time_hour,
5050
$backup_time_weekday = $rsnapshot::params::backup_time_weekday,
5151
$backup_time_dom = $rsnapshot::params::backup_time_dom,
52+
$cmd_wrapper_preexec = [],
53+
$cmd_wrapper_postexec = [],
5254
$cmd_preexec = $rsnapshot::params::cmd_preexec,
5355
$cmd_postexec = $rsnapshot::params::cmd_postexec,
5456
$cmd_client_rsync = $rsnapshot::params::cmd_client_rsync,
@@ -86,6 +88,8 @@
8688
# Add Wrapper Scripts
8789
class { 'rsnapshot::client::wrappers' :
8890
wrapper_path => $wrapper_path_normalized,
91+
preexec => $cmd_wrapper_preexec,
92+
postexec => $cmd_wrapper_postexec,
8993
cmd_client_rsync => $cmd_client_rsync,
9094
cmd_client_sudo => $cmd_client_sudo,
9195
}

manifests/client/wrappers.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class rsnapshot::client::wrappers (
22
$wrapper_path = $rsnapshot::params::wrapper_path,
3+
$preexec = [],
4+
$postexec = [],
35
$cmd_client_rsync = $rsnapshot::params::cmd_client_rsync,
46
$cmd_client_sudo = $rsnapshot::params::cmd_client_sudo,
57
) inherits rsnapshot::params {

templates/rsync_sender.sh.erb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
#!/bin/bash -e
2-
exec <%= @cmd_client_rsync %> --server --sender $*
2+
<% if @preexec.size > 0 -%>
3+
{ # Redirect output to /dev/null so that the reciever isn't confused by
4+
# extraneous output
5+
<%= @preexec.join("\n") %>
6+
} > /dev/null 2>&1
7+
<% end -%>
8+
<%= @cmd_client_rsync %> --server --sender $*
9+
<% if @postexec.size > 0 -%>
10+
{ # Redirect output to /dev/null so that the reciever isn't confused by
11+
# extraneous output
12+
<%= @postexec.join("\n") %>
13+
} > /dev/null 2>&1
14+
<% end -%>

0 commit comments

Comments
 (0)