达梦V8备份与还原

达梦备份与还原

  1. 冷备份与还原
    1.1. 冷备份
    1)创建目录
    #su - dmdba
    $ mkdir -p /home/dmdba/backup/full
    2)检查服务
    $cd $DM_HOME/bin
    $ ./DmServiceDMSERVER stop
    Stopping DmServiceDMSERVER: [ OK ]
    $./DmAPService status
    DmAPService (pid 19303) is running.
    3)开始备份
    $ ./dmrman
    dmrman V8
    RMAN> backup database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ backupset ‘/home/dmdba/backup/full’;
    backup database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ backupset ‘/home/dmdba/backup/full’;
    file dm.key not found, use default license!
    Database mode = 0, oguid = 0
    EP[0]'s cur_lsn[42245]
    BACKUP DATABASE [DAMENG],execute…
    CMD CHECK LSN…
    BACKUP DATABASE [DAMENG],collect dbf…
    CMD CHECK …
    DBF BACKUP SUBS…
    total 1 packages processed…
    total 2 packages processed…
    total 3 packages processed…
    total 4 packages processed…
    total 5 packages processed…
    DBF BACKUP MAIN…
    BACKUPSET [/home/dmdba/backup/full] END, CODE [0]…
    META GENERATING…
    total 7 packages processed…
    total 7 packages processed…
    total 7 packages processed!
    CMD END.CODE:[0]
    backup successfully!
    time used: 00:00:03.739
    RMAN> exit
    1.2. 冷还原
    1)模拟损坏
    $ cd /home/dmdba/dmdbms/data/DAMENG/
    $ rm -rf MAIN.DBF
    $ rm -rf SYSTEM.DBF
    $ rm -rf TEMP.DBF
    $ rm -rf ROLL.DBF
    $ rm -rf DMHR.DBF
    2)还原文件
    $ ./dmrman
    dmrman V8
    RMAN> restore database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ from backupset ‘/home/dmdba/backup/full’;
    restore database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ from backupset ‘/home/dmdba/backup/full’;
    file dm.key not found, use default license!
    RESTORE DATABASE CHECK…
    RESTORE DATABASE,data collect…
    RESTORE DATABASE,database refresh …
    RESTORE BACKUPSET [/home/dmdba/backup/full] START…
    total 5 packages processed…
    total 7 packages processed…
    RESTORE DATABASE,UPDATE ctl file…
    RESTORE DATABASE,REBUILD key file…
    RESTORE DATABASE,CHECK db info…
    RESTORE DATABASE,UPDATE db info…
    total 7 packages processed…
    total 7 packages processed!
    CMD END.CODE:[0]
    restore successfully.
    time used: 682.057(ms)
    3)应用日志
    RMAN> recover database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ update db_magic;
    recover database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ update db_magic;
    Database mode = 0, oguid = 0
    EP[0]'s cur_lsn[42245]
    EP[0]'s apply_lsn[42245] >= end_lsn[42245]
    recover successfully!
    time used: 00:00:01.018
    RMAN> exit
    4)检查还原
    $ ./DmServiceDMSERVER start
    Starting DmServiceDMSERVER: [ OK ]
    $ ./disql sysdba/vmware123!
    服务器[LOCALHOST:5236]:处于普通打开状态
    登录使用时间: 19.612(毫秒)
    disql V8
    SQL> select instance_name,status$ from v i n s t a n c e ; 行 号 I N S T A N C E N A M E S T A T U S instance; 行号 INSTANCE_NAME STATUS instance;INSTANCENAMESTATUS

1 DMSERVER OPEN
2. 热备份与还原
需要先开启归档
$ ./disql sysdba/vmware123!
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间: 19.612(毫秒)
disql V8
SQL> select instance_name,status$ from v i n s t a n c e ; 行 号 I N S T A N C E N A M E S T A T U S instance; 行号 INSTANCE_NAME STATUS instance;INSTANCENAMESTATUS


1 DMSERVER OPEN
已用时间: 1.202(毫秒). 执行号:5.
SQL> alter database mount;
操作已执行
已用时间: 00:00:01.799. 执行号:0.
SQL> alter database add archivelog ‘type=local,dest=/home/dmdba,file_size=64,space_limit=0’;
操作已执行
已用时间: 71.364(毫秒). 执行号:0.
SQL> alter database archivelog;
操作已执行
已用时间: 9.384(毫秒). 执行号:0.
SQL> alter database open;
操作已执行
已用时间: 00:00:01.761. 执行号:0.
SQL> select arch_mode from v$database;
行号 ARCH_MODE


1 Y
SQL> exit
2.1. 全库备份还原
1)创建目录
#su - dmdba
$ mkdir -p /home/dmdba/backup/full
2)全库备份
$ ./disql sysdba/vmware123!
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间: 3.711(毫秒)
disql V8
SQL> backup database backupset ‘/home/dmdba/backup/full’;
backup database backupset ‘/home/dmdba/backup/full’;
[-718]:收集到的归档日志不连续.
已用时间: 00:00:01.215. 执行号:0.
3)模拟损坏
$ cd /home/dmdba/dmdbms/data/DAMENG/
$ rm -rf MAIN.DBF
$ rm -rf SYSTEM.DBF
$ rm -rf TEMP.DBF
$ rm -rf ROLL.DBF
$ rm -rf DMHR.DBF
4)还原文件
$ ./DmServiceDMSERVER stop
Stopping DmServiceDMSERVER: [ OK ]
$ ./DmAPService status
DmAPService (pid 19303) is running.
$ ./dmrman
dmrman V8
RMAN> restore database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ from backupset ‘/home/dmdba/backup/full’;
restore database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ from backupset ‘/home/dmdba/backup/full’;
file dm.key not found, use default license!
RESTORE DATABASE CHECK…
RESTORE DATABASE,data collect…
RESTORE DATABASE,database refresh …
RESTORE BACKUPSET [/home/dmdba/backup/full] START…
total 5 packages processed…
total 7 packages processed…
RESTORE DATABASE,UPDATE ctl file…
RESTORE DATABASE,REBUILD key file…
RESTORE DATABASE,CHECK db info…
RESTORE DATABASE,UPDATE db info…
total 7 packages processed…
total 7 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 00:00:01.189
5)应用日志
RMAN> recover database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ from backupset ‘/home/dmdba/backup/full’;
recover database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ from backupset ‘/home/dmdba/backup/full’;
Database mode = 0, oguid = 0
EP[0]'s cur_lsn[46031]
RESTORE RLOG CHECK…
RESTORE RLOG, gen tmp file…
RESTORE RLOG FROM BACKUPSET [/home/dmdba/backup/full] START…
total 3 packages processed…
total 3 packages processed…
total 3 packages processed!
CMD END.CODE:[0]
EP:0 total 1 pkgs applied, percent: 25%
EP:0 total 2 pkgs applied, percent: 50%
EP:0 total 3 pkgs applied, percent: 75%
EP:0 total 4 pkgs applied, percent: 100%
Recover from archive log finished, time used:0.280s.
recover successfully!
time used: 568.997(ms)
RMAN> recover database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ update db_magic;
recover database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ update db_magic;
file dm.key not found, use default license!
Database mode = 0, oguid = 0
EP[0]'s cur_lsn[47294]
EP[0]'s apply_lsn[47294] >= end_lsn[47294]
recover successfully!
time used: 00:00:01.033
RMAN> exit
6)验证恢复
$ ./DmServiceDMSERVER start
Starting DmServiceDMSERVER: [ OK ]
$ ./disql sysdba/vmware123!
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间: 4.565(毫秒)
disql V8
SQL> select instance_name,status$ from v i n s t a n c e ; 行 号 I N S T A N C E N A M E S T A T U S instance; 行号 INSTANCE_NAME STATUS instance;INSTANCENAMESTATUS


1 DMSERVER OPEN
2.2. 表空间备份还原
1)创建目录
#su - dmdba
$ mkdir -p /home/dmdba/backup/dmhr
2)表空间备份
$ ./DmServiceDMSERVER start
Starting DmServiceDMSERVER: [ OK ]
$ ./disql sysdba/vmware123!
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间: 4.301(毫秒)
disql V8
SQL> backup tablespace dmhr backupset ‘/home/dmdba/backup/dmhr’;
操作已执行
已用时间: 824.392(毫秒). 执行号:5.
3)模拟损坏
$ cd /home/dmdba/dmdbms/data/DAMENG/
$ rm -rf DMHR.DBF
4)还原文件
$ ./DmServiceDMSERVER stop
Stopping DmServiceDMSERVER: [ OK ]
$ ./DmAPService status
DmAPService (pid 19303) is running.
$ ./dmrman
dmrman V8
RMAN> restore database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ tablespace dmhr from backupset ‘/home/dmdba/backup/dmhr’;
restore database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ tablespace dmhr from backupset ‘/home/dmdba/backup/dmhr’;
file dm.key not found, use default license!
RESTORE TABLESPACE[dmhr] IN DB[/home/dmdba/dmdbms/data/DAMENG/dm.ini] CHECK…
Database mode = 0, oguid = 0
EP[0]'s cur_lsn[47458]
RESTORE TABLESPACE[dmhr] IN DB[/home/dmdba/dmdbms/data/DAMENG/dm.ini],dbf collect…
RESTORE TABLESPACE[dmhr] IN DB[/home/dmdba/dmdbms/data/DAMENG/dm.ini],ts status and dbf refresh …
RESTORE BACKUPSET [/home/dmdba/backup/dmhr] START…
total 1 packages processed…
total 3 packages processed…
RESTORE TABLESPACE[dmhr] IN DB[/home/dmdba/dmdbms/data/DAMENG/dm.ini],UPDATE ctl file…
total 3 packages processed…
total 3 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 457.231(ms)
5)应用日志
RMAN> recover database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ tablespace dmhr;
recover database ‘/home/dmdba/dmdbms/data/DAMENG/dm.ini’ tablespace dmhr;
Database mode = 0, oguid = 0
[WARN]tablespace DMHR is corrupted(state: 2), restore or drop please.
EP[0]'s cur_lsn[47458]
RECOVER TABLESPACE[dmhr] IN DB[/home/dmdba/dmdbms/data/DAMENG/dm.ini] CHECK…
EP[0]'s cur_lsn[47458]
EP:0 total 3 pkgs applied, percent: 15%
EP:0 total 6 pkgs applied, percent: 30%
EP:0 total 9 pkgs applied, percent: 45%
EP:0 total 12 pkgs applied, percent: 60%
EP:0 total 15 pkgs applied, percent: 75%
EP:0 total 18 pkgs applied, percent: 90%
EP:0 total 20 pkgs applied, percent: 100%
Recover from archive log finished, time used:0.032s.
CMD END.CODE:[0]
recover successfully.
time used: 452.919(ms)
RMAN> exit
6)验证恢复
$ ./DmServiceDMSERVER start
Starting DmServiceDMSERVER: [ OK ]
$ ./disql sysdba/vmware123!
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间: 5.299(毫秒)
disql V8
SQL> select FILE_NAME,STATUS from dba_data_files;

行号 FILE_NAME STATUS


1 /home/dmdba/dmdbms/data/DAMENG/SYSTEM.DBF AVAILABLE
2 /home/dmdba/dmdbms/data/DAMENG/DMHR.DBF AVAILABLE
3 /home/dmdba/dmdbms/data/DAMENG/BOOKSHOP.DBF AVAILABLE
4 /home/dmdba/dmdbms/data/DAMENG/MAIN.DBF AVAILABLE
5 /home/dmdba/dmdbms/data/DAMENG/TEMP.DBF AVAILABLE
6 /home/dmdba/dmdbms/data/DAMENG/ROLL.DBF AVAILABLE
6 rows got
已用时间: 14.756(毫秒). 执行号:4.
SQL>exit
2.3. 表备份与还原
1)创建目录
#su - dmdba
$ mkdir -p /home/dmdba/backup/city
2)表备份
$ ./DmServiceDMSERVER start
Starting DmServiceDMSERVER: [ OK ]
$ ./disql sysdba/vmware123!
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间: 4.301(毫秒)
disql V8
SQL> create table test1 as select * from dmhr.city;
操作已执行
已用时间: 22.507(毫秒). 执行号:1536.
SQL> backup table test1 backupset ‘/home/dmdba/backup/city/’;
操作已执行
已用时间: 896.844(毫秒). 执行号:1537.
3)模拟损坏
$ ./disql sysdba/vmware123!
SQL> drop table test1;
操作已执行
已用时间: 276.070(毫秒). 执行号:1539.
4)查看表结构

cd /home/dmdba/backup/city/

ls

city.bak city.meta

strings city.meta

V7.1.7.78-Build(2020.04.28-121039)ENT
Parameter[%s] has setup, repeat setting is not allowed
Parameter [%s]‘s value[%s] Inval
city.bak
TEST1
SYSDBA
MAIN
SYSDBA’
CREATE SCHEMA “%s” AUTHORIZATION “%s” ;x
CREATE TABLE “TEST1”
“CITY_ID” CHAR(3),
“CITY_NAME” VARCHAR(40),
“REGION_ID” INT) STORAGE(ON “MAIN”, CLUSTERBTR) ;
CITY_ID
CITY_NAME
REGION_ID
setup, repeat setting is not allowed
Parameter [%s]'s value[%s] Inval

5)创建表结构
$ ./disql sysdba/vmware123!
SQL> CREATE TABLE TEST1
2 (CITY_ID CHAR(3),
3 CITY_NAME VARCHAR(40),
4 REGION_ID INT);
操作已执行
已用时间: 8.757(毫秒). 执行号:1540.
6)恢复表
SQL> restore table test1 from backupset ‘/home/dmdba/backup/city/’;
操作已执行
已用时间: 85.044(毫秒). 执行号:1541.
6)验证恢复
SQL> select count() from test1;
行号 COUNT(
)


1 11
已用时间: 2.536(毫秒). 执行号:1542.
3. 逻辑备份与还原
3.1. 全库备份还原
1)创建目录
#su - dmdba
$ mkdir -p /home/dmdba/backup/full
$ ./disql sysdba/vmware123!
SQL> create directory “expdir” as ‘/home/dmdba/backup/’;
操作已执行
已用时间: 118.778(毫秒). 执行号:1422.
2)全库备份
$ ./dexp sysdba/vmware123! file=full.dmp full=y directory=/home/dmdba/backup
3)模拟损坏
SQL> drop user dmhr cascade;
操作已执行
已用时间: 140.474(毫秒). 执行号:1252.
SQL> exit
4)恢复数据
$ ./dimp sysdba/vmware123! file=full.dmp full=y directory=/home/dmdba/backup
5)验证恢复
$ ./disql sysdba/vmware123!
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间: 3.138(毫秒)
disql V8
SQL> select count() from dmhr.employee;
行号 COUNT(
)


1 856
已用时间: 2.812(毫秒). 执行号:1339.
3.2. 用户备份还原
#su - dmdba
$ mkdir -p /home/dmdba/backup/full
$ ./disql sysdba/vmware123!
SQL> create directory “userdir” as ‘/home/dmdba/backup/’;
操作已执行
已用时间: 118.778(毫秒). 执行号:1422.
2)用户备份
$ ./dexp sysdba/vmware123! file=dmhr.dmp owner=dmhr directory=/home/dmdba/backup
3)模拟损坏
SQL> drop user dmhr cascade;
操作已执行
已用时间: 140.474(毫秒). 执行号:1252.
SQL> exit
4)恢复数据
$ ./dimp sysdba/vmware123! file=dmhr.dmp fromuser= dmhr touser= dmhr directory=/home/dmdba/backup
5)验证恢复
$ ./disql sysdba/vmware123!
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间: 3.138(毫秒)
disql V8
SQL> select count() from dmhr.employee;
行号 COUNT(
)


1 856
已用时间: 2.812(毫秒). 执行号:1339.
3.3. 表恢复还原
#su - dmdba
$ mkdir -p /home/dmdba/backup/full
$ ./disql sysdba/vmware123!
SQL> create directory “tabledir” as ‘/home/dmdba/backup/’;
操作已执行
已用时间: 118.778(毫秒). 执行号:1422.
2)表备份
$ ./dexp sysdba/vmware123! file=city.dmp tables=DMHR.CITY directory=/home/dmdba/backup
3)模拟损坏
$ ./disql sysdba/vmware123!
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间: 3.263(毫秒)
disql V8
SQL> drop table dmhr.city cascade;
操作已执行
已用时间: 87.628(毫秒). 执行号:1462.
4)恢复数据
$./dimp sysdba/vmware123! file=city.dmp tables=DMHR.CITY directory=/home/dmdba/backup
5)验证恢复
$ ./disql sysdba/vmware123!
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间: 3.138(毫秒)
disql V8
SQL> select count() from dmhr.city;
行号 COUNT(
)


1 11
已用时间: 8.524(毫秒). 执行号:1473.

你可能感兴趣的:(达梦)