-
Notifications
You must be signed in to change notification settings - Fork 796
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dinesh Gujar
authored and
Dinesh Gujar
committed
Aug 3, 2023
1 parent
fae6549
commit 26c3eff
Showing
15 changed files
with
343 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
Puppet::Functions.create_function(:'mysql::innobackupex_args') do | ||
dispatch :innobackupex_args do | ||
required_param 'Optional[String]', :backupuser | ||
required_param 'Boolean', :backupcompress | ||
required_param 'Optional[Variant[String, Sensitive[String]]]', :backuppassword_unsensitive | ||
required_param 'Array[String[1]]', :backupdatabases | ||
required_param 'Array[String[1]]', :optional_args | ||
return_type 'Variant[String]' | ||
end | ||
|
||
def innobackupex_args(backupuser, backupcompress, backuppassword_unsensitive, backupdatabases, optional_args) | ||
innobackupex_args = '' | ||
innobackupex_args = "--user=\"#{backupuser}\" --password=\"#{backuppassword_unsensitive}\"" if backupuser && backuppassword_unsensitive | ||
|
||
innobackupex_args = "#{innobackupex_args} --compress" if backupcompress | ||
|
||
innobackupex_args = "#{innobackupex_args} --databases=\"#{backupdatabases.join(' ')}\"" if backupdatabases.is_a?(Array) && !backupdatabases.empty? | ||
|
||
if optional_args.is_a?(Array) | ||
optional_args.each do |arg| | ||
innobackupex_args = "#{innobackupex_args} #{arg}" | ||
end | ||
end | ||
innobackupex_args | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'mysql::innobackupex_args' do | ||
it 'exists' do | ||
expect(subject).not_to be_nil | ||
end | ||
|
||
it 'accepts empty strings as puppet undef' do | ||
expect(subject).to run.with_params('', true, '', [], []) | ||
end | ||
|
||
context 'should work with username and password' do | ||
it 'returns args with username and password' do | ||
expect(subject).to run.with_params('root', false, '12345', [], []).and_return('--user="root" --password="12345"') | ||
end | ||
|
||
it 'returns args with database lists' do | ||
expect(subject).to run.with_params('root', false, '12345', ['db1', 'db2'], []).and_return('--user="root" --password="12345" --databases="db1 db2"') | ||
end | ||
|
||
it 'returns args with backup compress only' do | ||
expected_results = '--user="root" --password="12345" --compress' | ||
expect(subject).to run.with_params('root', true, '12345', [], []).and_return(expected_results) | ||
end | ||
|
||
it 'returns args with backup compress, database list and optional_args' do | ||
expected_results = '--user="root" --password="12345" --compress --databases="db1 db2" tst_arg_1 tst_arg_2' | ||
expect(subject).to run.with_params('root', true, '12345', ['db1', 'db2'], ['tst_arg_1', 'tst_arg_2']).and_return(expected_results) | ||
end | ||
end | ||
|
||
context 'should work without database args' do | ||
it 'returns args without database list' do | ||
expect(subject).to run.with_params('root', false, '12345', [], []).and_return('--user="root" --password="12345"') | ||
end | ||
end | ||
|
||
it 'returns args without backup compress' do | ||
expect(subject).to run.with_params('root', false, '12345', [], []).and_return('--user="root" --password="12345"') | ||
end | ||
|
||
it 'returns args with backup compress and database list' do | ||
expected_results = '--user="root" --password="12345" --compress --databases="db1 db2"' | ||
expect(subject).to run.with_params('root', true, '12345', ['db1', 'db2'], []).and_return(expected_results) | ||
end | ||
|
||
it 'returns args without backup compress database list and optional_args' do | ||
expected_results = '--user="root" --password="12345" --databases="db1 db2" tst_arg_1 tst_arg_2' | ||
expect(subject).to run.with_params('root', false, '12345', ['db1', 'db2'], ['tst_arg_1', 'tst_arg_2']).and_return(expected_results) | ||
end | ||
|
||
it 'returns args without backup compress database list and with optional_args' do | ||
expected_results = '--user="root" --password="12345" tst_arg_1 tst_arg_2' | ||
expect(subject).to run.with_params('root', false, '12345', [], ['tst_arg_1', 'tst_arg_2']).and_return(expected_results) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
### MANAGED BY PUPPET ### | ||
|
||
<% sort($options.map |$key, $value| { [$key, $value] }).map |$v| { -%> | ||
<% if type($v[1]) =~ Type[Hash] { -%> | ||
[<%= $v[0] %>] | ||
<%sort($v[1].map |$key, $value| { [$key, $value] }).map |$vi| { -%> | ||
<%- if ($vi[0] == 'ssl-disable') or ($vi[0] =~ /^ssl/ and $v[1]['ssl-disable'] == true) or ($vi[0] =~ /^ssl-/ and $v[1]['ssl'] == false) { -%> | ||
<%- next -%> | ||
<%- } elsif $vi[1] == true or $vi[1] == '' { -%> | ||
<%= $vi[0] -%> | ||
<%- } elsif type($vi[1]) =~ Type[Array] { -%> | ||
<%- $vi[1].each |$vii| { -%> | ||
<%-$base = $vi[0]-%> | ||
<%= $base %> = <%= $vii %> | ||
<%- } -%> | ||
<%- } elsif !($vi[1] ==nil or $vi[1]=='' or $vi[1]==undef) { -%> | ||
<%-$base = $vi[0]-%> | ||
<%= $base %> = <%= $vi[1] -%> | ||
<% } %> | ||
<% } %> | ||
<% } %> | ||
<% } %> | ||
<% if $includedir and $includedir != '' { -%> | ||
!includedir <%= $includedir %> | ||
<% } -%> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%['mysql', 'client', 'mysqldump', 'mysqladmin', 'mysqlcheck'].each |$section| { %> | ||
[<%= $section -%>] | ||
user=root | ||
host=localhost | ||
<% if $root_password_set { -%> | ||
password='<%= $root_password %>' | ||
<% } -%> | ||
socket=<%= $options['client']['socket'] %> | ||
<% } %> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<%- if $kernel == 'Linux' { -%> | ||
#!/bin/bash | ||
<%- } else { -%> | ||
#!/bin/sh | ||
<%- } -%> | ||
# | ||
# MySQL Backup Script | ||
# Dumps mysql databases to a file for another backup tool to pick up. | ||
# | ||
# MySQL code: | ||
# GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'user'@'localhost' | ||
# IDENTIFIED BY 'password'; | ||
# FLUSH PRIVILEGES; | ||
# | ||
##### START CONFIG ################################################### | ||
|
||
USER=<%= $backupuser %> | ||
PASS='<%= $backuppassword_unsensitive %>' | ||
MAX_ALLOWED_PACKET=<%= $maxallowedpacket %> | ||
DIR=<%= $backupdir %> | ||
ROTATE=<%= [ Integer($backuprotate) - 1, 0 ].max %> | ||
|
||
# Create temporary mysql cnf file. | ||
TMPFILE=`mktemp /tmp/backup.XXXXXX` || exit 1 | ||
echo -e "[client]\npassword=$PASS\nuser=$USER\nmax_allowed_packet=$MAX_ALLOWED_PACKET" > $TMPFILE | ||
|
||
<% if $prescript { -%> | ||
<%- [$prescript].flatten().filter |$value| {$value}.each |$script| { %> | ||
<%= $script %> | ||
<%- } -%> | ||
<% } -%> | ||
|
||
# Ensure backup directory exist. | ||
mkdir -p $DIR | ||
|
||
PREFIX=mysql_backup_ | ||
<% if $ignore_events { %> | ||
ADDITIONAL_OPTIONS="--ignore-table=mysql.event" | ||
<% } else { %> | ||
ADDITIONAL_OPTIONS="--events" | ||
<% } %> | ||
|
||
<%# Only include routines or triggers if we're doing a file per database -%> | ||
<%# backup. This happens if we named databases, or if we explicitly set -%> | ||
<%# file per database mode -%> | ||
<% if !$backupdatabases.empty or $file_per_database { -%> | ||
<% if $include_triggers { -%> | ||
ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --triggers" | ||
<% } else { -%> | ||
ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --skip-triggers" | ||
<% } -%> | ||
<% if $include_routines { -%> | ||
ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --routines" | ||
<% } else { -%> | ||
ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --skip-routines" | ||
<% } -%> | ||
<% } -%> | ||
|
||
<%- if $optional_args and type($optional_args) =~ Type(Array) { -%> | ||
<% $optional_args.each |$arg| { -%> | ||
ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS <%= $arg %>" | ||
<%- } -%> | ||
<%- } -%> | ||
##### STOP CONFIG #################################################### | ||
PATH=<%= $execpath %> | ||
|
||
<%- if $kernel == 'Linux' { -%> | ||
set -o pipefail | ||
<%- } -%> | ||
|
||
|
||
|
||
cleanup() | ||
{ | ||
find "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | xargs -0 -r rm -f | ||
} | ||
|
||
<% if $delete_before_dump { -%> | ||
cleanup | ||
|
||
<% } -%> | ||
<% if $backupdatabases.empty { -%> | ||
<% if $file_per_database { -%> | ||
<% if $excludedatabases.empty { -%> | ||
mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read dbname | ||
<%} else {-%> | ||
mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | grep -v '^\(<%= $excludedatabases.join('|') %>\)$' | while read dbname | ||
<% } -%> | ||
do | ||
<%= $backupmethod %> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ | ||
${ADDITIONAL_OPTIONS} \ | ||
${dbname} <% if $backupcompress { %>| <%= $compression_command %> <% } %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if $backupcompress { %><%= $compression_extension %><% } %> | ||
done | ||
<% } else { -%> | ||
<%= $backupmethod %> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ | ||
${ADDITIONAL_OPTIONS} \ | ||
--all-databases <% if $backupcompress { %>| <%= $compression_command %> <% } %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if $backupcompress { %><%= $compression_extension %><% } %> | ||
<% } -%> | ||
<% } else { -%> | ||
<% $backupdatabases.each |$db| { -%> | ||
<%= $backupmethod %> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ | ||
${ADDITIONAL_OPTIONS} \ | ||
<%= $db %><% if $backupcompress { %>| <%= $compression_command %> <% } %>> ${DIR}/${PREFIX}<%= $db %>_`date +%Y%m%d-%H%M%S`.sql<% if $backupcompress { %><%= $compression_extension %><% } %> | ||
<% } -%> | ||
<% } -%> | ||
|
||
<% unless $delete_before_dump { -%> | ||
if [ $? -eq 0 ] ; then | ||
cleanup | ||
touch <%= $backup_success_file_path %> | ||
fi | ||
<% } -%> | ||
|
||
<% if $postscript { -%> | ||
<%- [$postscript].flatten().filter |$value| { $value }.each |$script| { %> | ||
<%= $script %> | ||
<%- } -%> | ||
<% } -%> | ||
|
||
# Remove temporary file | ||
rm -f $TMPFILE |
Oops, something went wrong.