-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnc_dump.sh.erb
29 lines (25 loc) · 1.25 KB
/
nc_dump.sh.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
PRIMARY_MASTER=<%= @fqdn %>
SECONDARY_MASTER=<%= @passive_master %>
SCRIPTNAME=$(basename $0)
PATH="/opt/puppetlabs/bin:/opt/puppetlabs/puppet/bin:/opt/puppet/bin:$PATH"
logger "PE_FAILOVER: ${SCRIPTNAME} ---> [SUCCESS] Starting NC Export"
ncio -c "/etc/puppetlabs/puppet/ssl/certs/${PRIMARY_MASTER}.pem" \
-k "/etc/puppetlabs/puppet/ssl/private_keys/${PRIMARY_MASTER}.pem" \
--uri="https://${PRIMARY_MASTER}:4433/classifier-api/v1" backup | ncio transform \
--hostname $PRIMARY_MASTER:$SECONDARY_MASTER \
-o <%= @nc_dump_path %>/nc_dump.latest.json
if [ $? -ne 0 ]; then
logger "PE_FAILOVER: ${SCRIPTNAME} ---> [FAILURE] Failed to export NC data, error code: $?"
else
logger "PE_FAILOVER: ${SCRIPTNAME} ---> [SUCCESS] Export Completed. Attempting to sync data to ${SECONDARY_MASTER}"
<%= @rsync_command %> \
-e '/usr/bin/ssh -i <%= @rsync_user_ssh_id %>' --exclude 'archive' \
<%= @nc_dump_path %>/* <%= @rsync_user %>@<%= @passive_master %>:<%= @nc_dump_path %>/
result="$?"
if [ $result -eq 0 ]; then
logger "PE_FAILOVER: ${SCRIPTNAME} ---> [SUCCESS] Completed sync of Puppet NC Dump directory to <%= @passive_master %>"
else
logger "PE_FAILOVER: ${SCRIPTNAME} ---> [FAILURE] Failed to sync. Exit code is: ${result}"
fi
fi