`
Fangrn
  • 浏览: 799325 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

DB2中常用备份,恢复命令和db2move,db2look的使用

阅读更多

DB2离线和在线全备、增量备份及恢复的操作步骤

1、离线全备份

1)、首先确保没有用户使用DB2:
$db2 list applications for db sample
2)、停掉数据库并重新启动,以便断掉所有连接:
db2stop force
db2start
3)、执行备份命令:(使用TSM作为备份的介质)
db2 backup db sample use tsm
备份成功,将会返回一个时间戳。
4)、检查备份成功:
db2 list history backup all for sample ,可以看到多了这个备份的纪录。
db2adutl query命令也可以看到返回值。
5)、备注:
首先对主节点(catalog表空间在的节点)执行备份命令,再对另外的节点也做这个操作。

2、 在线备份:

1)、首先打开一下支持在线备份的数据库配置参数:
db2 update db cfg for sample using userexit on 启用用户出口
db2 update db cfg for sample using logretain on 启用归档日志
db2 update db cfg for sample using trackmod on 启用增量备份功能
(需要各个Node都分别做设置)
开启这些参数后,数据库处于backup pending状态,要求做数据库的离线全备份。做一下离线全备份,参考上面的命令。
2)、在线备份命令如下:
db2 backup db sample online use tsm
备份成功,返回一个时间戳。
3)、同样可以用db2adutl 和db2 list history察看备份纪录。
4)、备注:
同样,对每个节点都做这个操作。

3、 在线增量备份

1)、在开启了必须的三个参数的情况下,做增量备份:
db2 backup db sample online incremental use tsm
备份成功,返回一个时间戳。
2)、同样可以用db2adutl 和db2 list history察看备份纪录。
3)、还有一种delta的备份:
db2 backup db sample online incremental delta use tsm
这两种备份的区别,类似Oracle Exports的Incremental和Cumulative方式,db2的incremental对应oracle的cumulative方式,而db2的delta方式则对应oracle的incremental方式。
4)、备注:
同样,对每个节点都做这个操作。


4、 恢复数据库

1)、手工drop数据库,模拟灾难恢复的情况,执行如下操作:
db2 drop db sample
2)、恢复备份历史纪录(每次backup,不论类型,都会备份历史纪录文件)。这里的时间戳应该是最新的:
db2 restore db sample history file use tsm taken at 20030102223107 buffer 100
3)、使用db2的恢复帮助工具:
db2ckrst -d sample -t 20030101224424 -r database
命令返回建议的必需的恢复操作命令。
4)、按照帮助工具的提示,先做版本恢复,恢复命令如下:
db2 restore db sample incremental use tsm taken at 20030101224424 buffer 100
同样先做主节点的恢复,再做其他节点的恢复操作。
5)、这时数据库处于rollforward-pending state的状态,需要做roll forward 操作:
db2 rollforward db sample to 2003-01-12-13.27.25.000000 on all nodes and stop
前滚到同一个时间点。这个操作要在主节点来做。


5、有关说明:

1)、恢复操作也有online和offline的,区别如同backup的操作。
2)、按照表空间的备份和恢复类似,加子句TABLESPACE ( tablespace-name )即可。表空间级别的备份/恢复操作要求数据库处于归档日志和启用增量备份模式下。
3)、恢复的例子中只做了版本恢复。若还有更新的全备份和增量备份的image,可以依次做恢复(注意使用db2ckrst的建议恢复次序和次数)后,再做roll forward.



db2 force applications all
db2 backup db ldapdb2 to directory_or_device
db2 restore db ldapdb2 from directory_or_device replace existing其中 directory_or_device 是存储备份的目录或设备的名称。

windows 迁移到 linux:
db2move tfms export;
create db tfms;
db2move tfms -u -p import > a.txt;
db2move tfmsw179 import -u db2admin -p db2admin > a.txt

确认执行:TERMINATE

6、恢复数据库
(1)先创建空数据库:db2 create db NewdbName
(2)db2 restore olddbName(需恢复数据库名称) taken at Times(时间点) into NewdbName(新数据库名称)
注:在恢复新的数据库的名称和刚创建的名称一样。
//////

我自己的运用:
导出数据:
1:在DOS里运行DB2CMD
2:在D盘新建个文件夹CMS,在DB2CMD的DOS里CD到CMS目录
3:运行db2move 要备份的数据库名称 export -u 用户名 -p 密码
4:成功
导出数据:
1:在DB2控制台里建设一个空的数据库(缺省缓冲池和表空间大小设置大点最高32K,代码集设置UTF-8)
2.首先在D盘选择一个文件夹例如cms
3:运行db2move test import -u 用户名 -p 密码


注:改日志空间大小 右键数据库--->配置参数--->LOGFILSIZ设置大小 可以设置大点 例如50000

db2look
1.db2look -d cms_dev -a -e -o cms_dev.sql
生成数据库cms_dev的DDL,包括 tables, views, automatic summary tables, indexes, triggers, sequences, primary key, referential, and check constraints, user-defined functions, and procedures

db2look -d <database-name> [<option1> <option2 … <optionn>]



You must specify the name of the database whose objects you want to describe. You can then specify one or more options (in any order) to define the scope of the extraction, including:

-e
Extracts DDL statements for database objects such as tables, views, automatic summary tables, indexes, triggers, sequences, primary key, referential, and check constraints, user-defined functions, and procedures.
-a
Extracts DDL statements for all objects created by all users. For example, if this option is specified with the -e option, all objects in the database are processed.
-z schema-name
Limits the output to objects with the specified schema name.
-t table-name
Limits the output to one or more (maximum 30) specified tables. Table names must be separated by a blank space.
-m
Generates the required UPDATE statements to replicate statistics on tables, columns, and indexes.
-l
Generates DDL statements for user-defined table spaces, database partition groups, and buffer pools.
-x
Generates DDL statements that grant or revoke privileges on database objects.
-td delimiter
Specifies the statement delimiter that the db2look utility is to use; the default is the semicolon (;).
-o file-name
Writes the output to a file. If this option is not specified, writes to standard output.
-i userid
Specifies a user ID that the utility requires to log on to a remote system.
-w password
Specifies a password that authenticates the user; the utility requires a valid user ID and password to log on to a remote system.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics