Chinaunix首页 | 论坛 | 博客
  • 博客访问: 830561
  • 博文数量: 137
  • 博客积分: 3477
  • 博客等级: 中校
  • 技术积分: 1409
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-30 21:53
文章分类

全部博文(137)

文章存档

2024年(8)

2023年(10)

2022年(4)

2021年(10)

2020年(9)

2018年(1)

2017年(1)

2014年(4)

2013年(3)

2012年(12)

2011年(24)

2010年(2)

2009年(8)

2008年(6)

2007年(34)

2006年(1)

分类: DB2/Informix

2023-11-24 20:46:17

db2backup.sh


点击(此处)折叠或打开

  1. #!/bin/sh
  2. DB_NAME="sample"
  3. DB_USER="db2inst1"
  4. DB_PASSWD="db2inst1"
  5. BACKUP_TIME=`date +"%Y-%m-%d:%H:%M:%S"`
  6. echo "DataBase Backup Time ${BACKUP_TIME} .. ..."
  7. if [ ! -d ${HOME}/db.bak/${BACKUP_TIME} ]; then
  8. mkdir -p ${HOME}/db.bak/${BACKUP_TIME}
  9. fi
  10. db2 connect to ${DB_NAME} user ${DB_USER} using ${DB_PASSWD}
  11. 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
  12. for tables_name in `cat ${HOME}/db.bak/${BACKUP_TIME}/db2backup.tmp`
  13. do
  14. SCHEMA_NAME=`echo "$tables_name" | awk -F "." '{print $2}'`
  15. table_name=`echo "$tables_name" | awk -F "." '{print $1}'`
  16. 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
  17. echo "$table_name backup done ..."
  18. done
  19. db2 disconnect ${DB_NAME}

db2restore.sh

点击(此处)折叠或打开

  1. #!/bin/sh
  2. if [ -z $1 ]; then
  3. echo "usage: $0 backup_time"
  4. exit 1;
  5. fi
  6. DB_NAME="sample"
  7. DB_USER="db2inst1"
  8. DB_PASSWD="db2inst1"
  9. BACKUP_TIME=$1
  10. echo "DataBase iRestore Time ${BACKUP_TIME} .. ..."
  11. if [ ! -d ${HOME}/db.bak/${BACKUP_TIME} ]; then
  12. echo "DataBase Backup Package for $BACKUP_TIME not found ..."
  13. exit 1;
  14. fi
  15. db2 connect to ${DB_NAME} user ${DB_USER} using ${DB_PASSWD}
  16. for tables_name in `cat ${HOME}/db.bak/${BACKUP_TIME}/db2backup.tmp`
  17. do
  18. SCHEMA_NAME=`echo "$tables_name" | awk -F "." '{print $2}'`
  19. table_name=`echo "$tables_name" | awk -F "." '{print $1}'`
  20. if [ ! -f ${HOME}/db.bak/${BACKUP_TIME}/${DB_NAME}.${SCHEMA_NAME}.${table_name}.ixf ]; then
  21. echo "Backup file ${HOME}/db.bak/${BACKUP_TIME}/${DB_NAME}.${SCHEMA_NAME}.${table_name}.ixf not found "
  22. else
  23. 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
  24. echo "$table_name restore done ..."
  25. fi
  26. done
  27. db2 disconnect ${DB_NAME}

阅读(169) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~