This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
tsmpipe/scripts/tdp.mysql.restore.sh

60 lines
1.0 KiB
Bash
Raw Normal View History

2013-12-17 12:44:37 +00:00
#!/bin/bash
# Check our arguments
while getopts ":DF:m:p:P:s:u:" opt; do
case $opt in
D) DEBUG=1 ;;
# Filespace to store in TSM
F) FILESPACE=$OPTARG ;;
# Optional MYSQL arguments
m) MYSQL_ARGS=$OPTARG ;;
# Mysql PASSWORD
p) DBPASS=$OPTARG ;;
# PITDATE to restore
P) PITDATE=$OPTARG ;;
# Skip DBs
s) SKIP_DB=$OPTARG ;;
# Mysql USERNAME
u) DBUSER=$OPTARG ;;
# Error Checking
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Our defaults
DB=${@:?"You need to specicify a database to restore"}
FILESPACE=${FILESPACE:-"/mysqldump"}
[ -n "$DBPASS" ] && MYSQL_AUTH="-p${DBPASS}"
[ -n "$DBUSER" ] && MYSQL_AUTH="-u${DBUSER} ${MYSQL_AUTH}"
# TSMPIPE ARGUMENTS
[ -n "$PITDATE" ] && TSMPIPE_ARGS="${TSMPIPE_ARGS} -P ${PITDATE}"
OLDIFS=$IFS
IFS=":"
for db in $DB; do
[ -n "$DEBUG" ] && echo "Processing DB ($db)"
# Restore from TSM
tsmpipe -Bxs ${FILESPACE} -f ${db}.FULL ${TSMPIPE_ARGS} | mysql ${MYSQL_AUTH} ${db}
done;
IFS=$OLDIFS