db2backup.sh
-
#!/bin/sh
-
-
DB_NAME="sample"
-
DB_USER="db2inst1"
-
DB_PASSWD="db2inst1"
-
-
BACKUP_TIME=`date +"%Y-%m-%d:%H:%M:%S"`
-
echo "DataBase Backup Time ${BACKUP_TIME} .. ..."
-
-
if [ ! -d ${HOME}/db.bak/${BACKUP_TIME} ]; then
-
mkdir -p ${HOME}/db.bak/${BACKUP_TIME}
-
fi
-
-
db2 connect to ${DB_NAME} user ${DB_USER} using ${DB_PASSWD}
-
-
db2 list tables for all | grep -v "SYSTOOLS" | grep -v "SYSSTAT" | grep -v "SYSPUBLIC" | grep -v "SYSIBMADM" | grep -v "SYSIBM" | grep -v "SYSCAT" | grep -v grep | awk '{print $1"."$2}' | sed '1,3d' | head -n -3 >${HOME}/db.bak/${BACKUP_TIME}/db2backup.tmp
-
-
for tables_name in `cat ${HOME}/db.bak/${BACKUP_TIME}/db2backup.tmp`
-
do
-
SCHEMA_NAME=`echo "$tables_name" | awk -F "." '{print $2}'`
-
table_name=`echo "$tables_name" | awk -F "." '{print $1}'`
-
db2 "export to ${HOME}/db.bak/${BACKUP_TIME}/${DB_NAME}.${SCHEMA_NAME}.${table_name}.ixf of ixf select * from ${SCHEMA_NAME}.${table_name}" >/dev/null 2>&1
-
echo "$table_name backup done ..."
-
done
-
db2 disconnect ${DB_NAME}
db2restore.sh
-
#!/bin/sh
-
-
if [ -z $1 ]; then
-
echo "usage: $0 backup_time"
-
exit 1;
-
fi
-
-
DB_NAME="sample"
-
DB_USER="db2inst1"
-
DB_PASSWD="db2inst1"
-
-
BACKUP_TIME=$1
-
echo "DataBase iRestore Time ${BACKUP_TIME} .. ..."
-
-
if [ ! -d ${HOME}/db.bak/${BACKUP_TIME} ]; then
-
echo "DataBase Backup Package for $BACKUP_TIME not found ..."
-
exit 1;
-
fi
-
-
db2 connect to ${DB_NAME} user ${DB_USER} using ${DB_PASSWD}
-
-
for tables_name in `cat ${HOME}/db.bak/${BACKUP_TIME}/db2backup.tmp`
-
do
-
SCHEMA_NAME=`echo "$tables_name" | awk -F "." '{print $2}'`
-
table_name=`echo "$tables_name" | awk -F "." '{print $1}'`
-
if [ ! -f ${HOME}/db.bak/${BACKUP_TIME}/${DB_NAME}.${SCHEMA_NAME}.${table_name}.ixf ]; then
-
echo "Backup file ${HOME}/db.bak/${BACKUP_TIME}/${DB_NAME}.${SCHEMA_NAME}.${table_name}.ixf not found "
-
else
-
db2 "import from ${HOME}/db.bak/${BACKUP_TIME}/${DB_NAME}.${SCHEMA_NAME}.${table_name}.ixf of ixf modified by lobsinfile replace into ${SCHEMA_NAME}.${table_name}" >/dev/null 2>&1
-
echo "$table_name restore done ..."
-
fi
-
done
-
db2 disconnect ${DB_NAME}
阅读(169) | 评论(0) | 转发(0) |