Sha256: b375dca10c7d7290a252f547eba08fed175d86d3ba551dac0d05f6ec7f574cb7

Contents?: true

Size: 1.68 KB

Versions: 14

Compression:

Stored size: 1.68 KB

Contents

#!/bin/bash
#
# 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 %>
DIR=<%= @backupdir %>
ROTATE=<%= [ Integer(@backuprotate) - 1, 0 ].max %>

PREFIX=mysql_backup_

##### STOP CONFIG ####################################################
PATH=/usr/bin:/usr/sbin:/bin:/sbin

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

<% end -%>
<% if @backupdatabases.empty? -%>
<% if @file_per_database -%>
mysql -s -r -N -e 'SHOW DATABASES' | while read dbname
do
  mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \
    ${dbname} <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end  %>
done
<% else -%>
mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \
 --all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end  %>
<% end -%>
<% else -%>
<% @backupdatabases.each do |db| -%>
mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \
 <%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end  %>
<% end -%>
<% end -%>

<% unless @delete_before_dump -%>
if [ $? -eq 0 ] ; then
    cleanup
fi
<% end -%>

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
freighthop-0.6.1 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.6.0 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.5.2 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.5.1 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.5.0 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.4.1 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.4.0 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.3.3 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.3.2 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.3.1 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.3.0 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.2.1 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.2.0 modules/mysql/templates/mysqlbackup.sh.erb
freighthop-0.1.0 modules/mysql/templates/mysqlbackup.sh.erb