1. 管理员权限用户登录
[re@localhost ~]$db2 connect to 数据库名 user 管理用户名(db2inst1 ) using 密码
如果 已经登录而非管理员用户,需要切换用户:
[resrt@localhost ~]$ su db2inst1 切换管理员身份用户
Password: 输入密码
失败返回:su: Authentication failure,可能账户密码错误
成功返回 :Last login: Wed Apr 8 09:34:42 CST 2020 on pts/1
2.首先确保没有用户在使用数据库
[db2inst1@localhost ~] db2 list applications for db re(re为我的数据库名称);
返回 :SQL1611W No data was returned by Database System Monitor. 表示没有连接
3. 如果存在多条连接
例如返回:
RE db2XXX_applica 342 ::ffff:192.168.***.**.66666.202008012826 RE 1
RE db2XXX_applica 315 ::ffff:192.168.***.**.66666.202008011506 RE 1
需要先强制退出数据库所有连接 :
[db2inst1@localhost ~]db2 force applications all
返回(
DB20000I The FORCE APPLICATION command completed successfully.
DB21024I This command is asynchronous and may not be effective immediately. 成功)
4.然后备份数据库数据
[db2inst1@localhost ~]db2 backup db re to /home/db2inst1/
(返回时间戳文件名,备份成功:Backup successful. The timestamp for this backup image is : 20200407213240)
5.完成之后到对应目录查找文件
[db2inst1@localhost ~]cd /home/db2inst1/
[db2inst1@localhost ~]ll
找到RE.0.db2inst1.DBPART000.20200407213240.001(最新時間戳的为刚刚备份文件)
6,拷贝备份文件到新数据库
在新数据库中创建路径为/home/db2inst1,拷贝备份文件到里面,恢复备份文件数据:
[db2inst1@localhost ~]db2 restore db 新数据库名称 from /home/db2inst1 takenat 20200407213240
(20200407213240 对应之前Backup successful. The timestamp for this backup image is : 20200407213240 的时间戳)
7.恢复数据后检查数据是否恢复成功
登录管理員用户db2inst1:
[re@localhost ~]$db2 connect to 数据库名 user 管理用户名(db2inst1 ) using 密码
[db2inst1@localhost re]$ db2start 启动数据库。
返回 (
04/08/2020 09:59:43 0 0 SQL1026N The database manager is already active.
SQL1026N The database manager is already active. 成功
)
[db2inst1@localhost ~]$ db2 list db directory (查询所有数据库,
返回(
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = RE
Database name = RE
Local database directory = /db2data/re
Database release level = 15.00
Comment = re
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
)
[db2inst1@localhost re]$ db2 list active databases (查询所有活跃数据库,
返回:
Active Databases
Database name = RE
Applications connected currently = 8
Database path = /db2***/re/db2inst1/***/***
,RE 为活跃数据库。
)
[db2inst1@localhost re]$ db2 connect to re (链接RE 数据库)
Database Connection Information
Database server = DB2/LINUXXss64 11.5.0.0
SQL authorization ID = DB2INST1
Local database alias = RE
[db2inst1@localhost re]$ db2 list tables for all (查看数据库下所有表,
返回
DB2_TEST_INFO_V SYSCAT V 2019-07-31-17.57.28.970320
HMON_***_INFO SYSCAT T 2019-07-26-09.51.46.682115
xx record(s) selected.
)
, 核对备份表数据是否全部成功。
[db2inst1@localhost /]$ db2`` 进入SQL命令行
db2 => select * from SYSCAT. HMON_***_INFO ; 随便查询一个表,查看数据是否正确
对大有帮助的话,多多点赞,谢谢!