2016-01-21 14:11:10 +00:00
|
|
|
#!/bin/bash
|
2016-01-22 14:48:07 +00:00
|
|
|
# This file is managed by puppet
|
2016-01-21 14:11:10 +00:00
|
|
|
# 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%>
|
|
|
|
|
2016-01-22 12:17:03 +00:00
|
|
|
<% if (@dbbackup_user == 'root' && @dbbackup_password == '') -%>
|
|
|
|
dbs=(
|
2016-01-22 14:57:23 +00:00
|
|
|
$(ssh -l <%=@backup_user-%> "$host" "mysql -e 'show databases' | sed '1d;<%@ignore_dbs.to_a.each do |db|-%>/<%=db-%>/d;<%end-%>'" )
|
2016-01-22 12:17:03 +00:00
|
|
|
)
|
|
|
|
<%else-%>
|
|
|
|
dbs=(
|
2016-01-22 14:57:23 +00:00
|
|
|
$(ssh -l <%=@backup_user-%> "$host" "mysql -u <%=@dbbackup_user-%> -p'<%=@dbbackup_password-%>' -e 'show databases' | sed '1d;<%@ignore_dbs.each do |db|-%>/<%=db-%>/d;<%end-%>'" )
|
2016-01-22 12:17:03 +00:00
|
|
|
)
|
|
|
|
<%end-%>
|
2016-01-21 14:11:10 +00:00
|
|
|
for db in "${dbs[@]}"; do
|
2016-12-21 17:36:49 +00:00
|
|
|
<% if (@dbbackup_user == 'root' && @dbbackup_password == '' )-%>
|
2016-01-22 14:57:23 +00:00
|
|
|
ssh -l <%=@backup_user-%> "$host" "<%=@dumper-%> <%=@dump_flags-%> ${db}" > "$db".sql
|
2016-01-22 12:17:03 +00:00
|
|
|
<%else-%>
|
2016-01-22 14:57:23 +00:00
|
|
|
ssh -l <%=@backup_user-%> "$host" "<%=@dumper-%> --user=<%=@dbbackup_user-%> --password='<%=@dbbackup_password-%>' <%=@dump_flags-%> ${db}" > "$db".sql
|
2016-01-22 12:17:03 +00:00
|
|
|
<%end-%>
|
2016-01-21 14:11:10 +00:00
|
|
|
wait
|
2016-01-22 14:01:32 +00:00
|
|
|
<% if @compress != '' -%>
|
|
|
|
<%=@compress-%> "$db".sql
|
|
|
|
<%end-%>
|
2016-01-21 14:11:10 +00:00
|
|
|
done
|
|
|
|
|