日期:2014-05-16 浏览次数:20544 次
su – db2inst1 #断开所有连接,关闭数据库 #db2 force applications all db2 db2stop force #启动数据库 db2 db2start #显示所有数据库及其路径列表 db2 list database directory #显示所有活动的数据库 db2 list active databases #释放一个数据库 db2 deactivate database db_test #数据库的备份和恢复,注意:不能跨平台恢复 #离线备份 db2 backup database db_test to "/data/DB2/db2idb/dbback" #恢复到相同数据库 --db2 restore database db_dev from "/data/DB2/db2idb/dbback" #恢复到不同数据库 db2 restore database db_test from "/data/DB2/db2idb/dbback" into db_dev
su - db2inst1 #显示配置信息 db2 get db cfg for db_db #启用日志归档模式 db2 update db cfg for db_db using LOGRETAIN ON #设置日志归档目录 db2 update db cfg for db_db using LOGARCHMETH1 DISK:/data/db2data/logs/db_db #做一次离线备份,否则数据库会登录不了[如果提示有连接无法备份,请参考db2离线备份] db2 backup db db_db to "/data/db2data/backup/db_db" #在线备份--备份日志(首个活动日志到当前日志会一同备份到备份文件里) db2 backup db db_db online to "/data/db2data/backup/db_db" include logs #从包含日志的备份集恢复[恢复同一个数据库 into db_db 可省略] #要导入的数据库的归档目录不要和备份恢复的日志目录相同 #db2 force applications all db2 RESTORE db db_db FROM /data/db2data/backup/db_test/ taken at 20130618142149 into db_test LOGTARGET /data/db2data/logs/db_test #前滚 #由于从备份成功到数据库崩溃的时间间隔会产生其他的归档日志,可以将这些日志拷贝到/data/db2data/logs/中, #或者直接从归档日志目录进行前滚,同"从不包含日志的备份集恢复"中的"前滚" db2 "rollforward db db_test to end of logs and stop overflow log path(/data/db2data/logs/db_test)"
#指定redirect db2 RESTORE db dbdb FROM /data/db2data/backup/ taken at 20130618180228 into db_db LOGTARGET /data/db2data/backup/log redirect #db2 list tablespace containers for 0 查看空间 #db2 list tablespaces show detail 查看所有空间 #设置新的表空间,空间位置和参数可通过上两个指令查看 db2 "set tablespace containers for 0 using (file '/home/db2inst1/db2inst1/NODE0000/DB_DB/T0000000/C0000000.CAT' 6144)" db2 "set tablespace containers for 1 using (Path '/home/db2inst1/db2inst1/NODE0000/DB_DB/T0000001/C0000000.TMP')" db2 "set tablespace containers for 2 using (File '/home/db2inst1/db2inst1/NODE0000/DB_DB/T0000002/C0000000.LRG' 14336)" db2 "set tablespace containers for 3 using (file '/home/db2inst1/db2inst1/NODE0000/DB_DB/T0000003/C0000000.LRG' 1024)" db2 "set tablespace containers for 4 using (Path '/home/db2inst1/db2inst1/NODE0000/DB_DB/T0000004/C0000000.UTM')" #应用设置 db2 RESTORE DATABASE dbdb CONTINUE --db2 rollforward db db_db query status 查看状态 db2 "rollforward db db_db to end of logs and stop overflow log path(/data/db2data/backup/log)"
#表结构导出 db2look -d db_test -e -z AM -l -o exdb.sql #导入表结构操作: db2 -tvf exdb.sql