MyDumper: Difference between revisions
From fakedWiki
(Created page with "== Restore == <nowiki>#!/bin/bash if [ -z $1 ]; then echo "Usage: $0 </path/to/mydumper/backup> [database-name]" exit 1 fi FINDNAME="*" if [ -n ${2} ]; then FINDNAME=...") |
No edit summary |
||
Line 15: | Line 15: | ||
DB=$(basename "${DBFILE}" | sed 's/_schema\.sql\.gz//') | DB=$(basename "${DBFILE}" | sed 's/_schema\.sql\.gz//') | ||
echo "Restoring schema for database '${DB}' from ${DBFILE}" | echo "Restoring schema for database '${DB}' from ${DBFILE}" | ||
zcat ${DBFILE} | mysql ${DB} | |||
for TFILE in $(find ${1} -iname "${DB}.*.sql.gz"); do | for TFILE in $(find ${1} -iname "${DB}.*.sql.gz"); do | ||
TABLE=$(basename "${TFILE}" | sed -n "s/${DB}\.\(.*\)\.sql\.gz/\1/p") | TABLE=$(basename "${TFILE}" | sed -n "s/${DB}\.\(.*\)\.sql\.gz/\1/p") |
Revision as of 20:17, 9 January 2016
Restore
#!/bin/bash if [ -z $1 ]; then echo "Usage: $0 </path/to/mydumper/backup> [database-name]" exit 1 fi FINDNAME="*" if [ -n ${2} ]; then FINDNAME="${2}" fi for DBFILE in $(find ${1} -iname "${FINDNAME}_schema.sql.gz"); do DB=$(basename "${DBFILE}" | sed 's/_schema\.sql\.gz//') echo "Restoring schema for database '${DB}' from ${DBFILE}" zcat ${DBFILE} | mysql ${DB} for TFILE in $(find ${1} -iname "${DB}.*.sql.gz"); do TABLE=$(basename "${TFILE}" | sed -n "s/${DB}\.\(.*\)\.sql\.gz/\1/p") echo "Restoring table ${DB}.${TABLE}..." zcat ${TFILE} | mysql ${DB} done done