下面为您介绍的备份方法用于实现DB2备份所有表数据,如果您在DB2备份所有表方面遇到过类似的问题,不妨一看。
- ###cr by fubs
- clear;
- db2 connect to abbs>/tmp/null;
- tbname=`db2 "list tables"|grep -v "record"|awk '{if(length($1)>0 && NR>3)print $1}'`;
- ##声明变量
- s_date=`date +%Y-%m-%d,%H:%M:%S`
- v_date=`date +%Y%m%d`
- bkpath=$HOME/personal/fubs/bak/$v_date;
- if [ ! -d $bkpath ];then
- mkdir $bkpath;
- echo "备份所有数据,确认吗?\c"
- else
- echo "当天已备份,是否覆盖?\c";
- fi
- read yn;
- if [ -z "$yn" -o ! "$yn" = "y" ];then
- echo "放弃操作!";
- exit 0;
- fi
- cd $bkpath;
- num=0;
- for i in $tbname
- do
- db2 "Export to $i.del of del select * from $i";
- num=`expr $num + 1`;
- done
- db2 connect reset>/tmp/null;
- db2 terminate>/tmp/null;
- echo "备份数据成功,共备份[$num]个库表!"
【编辑推荐】