1
0
mirror of https://github.com/krislamo/puppet-rsnapshot synced 2024-11-10 08:10:34 +00:00
puppet-rsnapshot/templates/mysql.sh.erb
2016-01-22 15:48:07 +01:00

31 lines
1.0 KiB
Plaintext

#!/bin/bash
# This file is managed by puppet
# written by Norbert Varzariu <loomsen@gmail.com>
# This Script is triggered by rsnapshot and dumps the specified dbs on the configured host.
#
host=<%=@host%>
user=<%=@dbbackup_user%>
pass=<%=@dbbackup_password%>
<% if (@dbbackup_user == 'root' && @dbbackup_password == '') -%>
dbs=(
$(ssh -l root "$host" "mysql -e 'show databases' | sed '1d;<%@ignore_dbs.to_a.each do |db|-%>/<%=db-%>/d;<%end-%>'" )
)
<%else-%>
dbs=(
$(ssh -l root "$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
<% if @dbbackup_user == 'root' -%>
ssh -l root "$host" "<%=@dumper-%> <%=@dump_flags-%> ${db}" > "$db".sql
<%else-%>
ssh -l root "$host" "<%=@dumper-%> --user=<%=@dbbackup_user-%> --password='<%=@dbbackup_password-%>' <%=@dump_flags-%> ${db}" > "$db".sql
<%end-%>
wait
<% if @compress != '' -%>
<%=@compress-%> "$db".sql
<%end-%>
done