Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Oracle backup and recovery-rman

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

(1). Create a recovery directory

1. Create a recovery catalog database

# mkdir-p / u01/app/oracle/oradata/rmandb

# chown-R oracle/ u01/app/oracle/oradata/rmandb

[root@rhel1 ~] # su-oracle

[oracle@rhel1 ~] $sqlplus / as sysdba

SQL > create tablespace rmant datafile'/ u01 size size 20m

The tablespace has been created.

2. Create a RMAN user and authorize it in the recovery catalog database

SQL > create user c##rmant identified by rmant

Default tablespace rmant

Temporary tablespace temp

Quota unlimited on rmant

The user has been created.

SQL > grant connect,resource to c##rmant

Authorization successful.

SQL > grantrecovery_catalog_owner to c##rmant

Authorization successful.

3. Create a recovery directory in the recovery catalog database

[oracle@oracle~] $rman catalog c##rmant/rmant

Recovery Manager: Release 12.2.0.1.0-Production on Friday November 16 19:59:31 2018

Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.

Connect to the recovery catalog database

RMAN > create catalog

The recovery directory has been created

RMAN > quit

The recovery Manager is complete.

(2) register the target database to the recovery directory 1 and enter the RMAN environment

[oracle@oracle~] $rmanbr/ > 1. Enter the RMAN environment

[oracle@oracle~] $rman

Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.

2. Connect to the target database

RMAN > connect target sys/oracle

Connected to the target database: ORCL (DBID=1503444987)

3. Connect to the recovery catalog database

RMAN > connect catalog c##rmant/rmant

Connect to the recovery catalog database

4. Registration

RMAN > register database

Database registered in the recovery directory

Starting full resynchronization of the recovery directory

Complete resynchronization of all

RMAN > quit

The recovery Manager is complete.

5. View the database registered in the recovery catalog in the recovery catalog database

[oracle@oracle~] $sqlplus c##rmant/rmant

SQLPlus: Release 12.2.0.1.0 Production on Friday November 16 20:05:20 2018

Copyright (c) 1982, 2016, Oracle. All rights reserved.

Last successful login time: Friday November 16 2018 20:03:33 + 08:00

Connect to:

Oracle Database 12c Enterprise Edition Release 12.2.0.1.0-64bit Production

SQL > select count () from rc_database

COUNT (*) 1

(3) backup and restore in archive mode

1. Set the database to archive mode, the database instance must be started, and the database is already loaded or open

SQL > conn sys/oracle as sysdba

Connected.

SQL > shutdown immediate

The database has been closed.

The database has been uninstalled.

The ORACLE routine has been closed.

SQL > startup mount

The ORACLE routine has been started.

Total System Global Area 1593835520 bytes

Fixed Size 8793256 bytes

Variable Size 1023411032 bytes

Database Buffers 553648128 bytes

Redo Buffers 7983104 bytes

The database is loaded.

SQL > alter database archivelog

The database has changed.

SQL > alter database open

The database has changed.

2. Modify the parameters of the flash recovery area first.

SQL > show parameter db_recovery_file_dest

NAME TYPE

VALUE

Db_recovery_file_dest string

Db_recovery_file_dest_size big integer

0

SQL > alter system setdb_recovery_file_dest_size=2g

The system has changed.

3. Create a tablespace and table

SQL > create tablespace tab1

Datafile'/ u01 size size 10m

The tablespace has been created.

4. Create the table tab1

SQL > create table tab1 (id int)

The table has been created.

5. Add records to the table tab1

SQL > insert into tab1 values (1)

1 line has been created.

SQL > commit

The submission is complete.

SQL > quit

Disconnect from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0-64bit Production

5. Log in to RMAN using the database user sys

[oracle@oracle~] $rman target sys/oracle

Recovery Manager: Release 12.2.0.1.0-Production on Friday November 16 20:15:04 2018

Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.

Connected to the target database: ORCL (DBID=1503444987)

6. Back up the entire database to the flash area

RMAN > backup database

Starting with backup at 16-11-18

Replace the recovery directory with the target database control file

Assigned channel: ORA_DISK_1

Channel ORA_DISK_1: SID=31 device type = DISK

Channel ORA_DISK_1: starting backup set of all data files

Channel ORA_DISK_1: specifying data files in the backup set

Enter the data file, file number = 00001 name = / u01/app/oracle/oradata/orcl/system01.dbf

Enter the data file, file number = 00003 name = / u01/app/oracle/oradata/orcl/sysaux01.dbf

Enter the data file, file number = 00004 name = / u01/app/oracle/oradata/orcl/undotbs01.dbf

Enter the data file, file number = 00013 name = / opt/oracle/oradata/rmandb/rmants.ora

Enter the data file, file number = 00014 name = / u01/app/oracle/oradata/rmandb/rmants.ora

Enter the data file, file number = 00015 name = / u01/app/oracle/oradata/rmandb/tab1.dbf

Enter the data file, file number = 00007 name = / u01/app/oracle/oradata/orcl/users01.dbf

Channel ORA_DISK_1: starting segment 1 from 16 to November 18

Channel ORA_DISK_1: completed startup segment 1 from 16 to November 18

Fragment handle = / u01/app/oracle/product/12.2.0/dbhome_1/dbs/01ticu3n_1_1 tag = TAG20181116T201551 comment = NONE

Channel ORA_DISK_1: backup set completed, time: 00:00:55

Channel ORA_DISK_1: starting backup set of all data files

Channel ORA_DISK_1: specifying data files in the backup set

Enter the data file, file number = 00010 name = / u01/app/oracle/oradata/orcl/orclpdb/sysaux01.dbf

Enter the data file, file number = 00009 name = / u01/app/oracle/oradata/orcl/orclpdb/system01.dbf

Enter the data file, file number = 00011 name = / u01/app/oracle/oradata/orcl/orclpdb/undotbs01.dbf

Enter the data file, file number = 00012 name = / u01/app/oracle/oradata/orcl/orclpdb/users01.dbf

Channel ORA_DISK_1: starting segment 1 from 16 to November 18

Channel ORA_DISK_1: completed startup segment 1 from 16 to November 18

Fragment handle = / u01/app/oracle/product/12.2.0/dbhome_1/dbs/02ticu5f_1_1 tag = TAG20181116T201551 comment = NONE

Channel ORA_DISK_1: backup set completed, time: 00:00:25

Channel ORA_DISK_1: starting backup set of all data files

Channel ORA_DISK_1: specifying data files in the backup set

Enter the data file, file number = 00006 name = / u01/app/oracle/oradata/orcl/pdbseed/sysaux01.dbf

Enter the data file, file number = 00005 name = / u01/app/oracle/oradata/orcl/pdbseed/system01.dbf

Enter the data file, file number = 00008 name = / u01/app/oracle/oradata/orcl/pdbseed/undotbs01.dbf

Channel ORA_DISK_1: starting segment 1 from 16 to November 18

Channel ORA_DISK_1: completed startup segment 1 from 16 to November 18

Fragment handle = / u01/app/oracle/product/12.2.0/dbhome_1/dbs/03ticu68_1_1 tag = TAG20181116T201551 comment = NONE

Channel ORA_DISK_1: backup set completed, time: 00:00:26

Completed backup in 16-11-18

Starting with Control File and SPFILE Autobackup at 16-11-18

Fragment handle = / u01/app/oracle/product/12.2.0/dbhome_1/dbs/c-1503444987-20181116-00 comment = NONE

Completed Control File and SPFILE Autobackup in 16-11-18

RMAN > quit

The recovery Manager is complete.

7. Delete tab1 table

SQL > drop table tab1; (remember when to delete)

Table TAB1 has been deleted.

SQL > commit

The submission is complete.

8. Restore the table

① restores the database when the database is in mount state

SQL > shutdown immediate

The database is closed.

The database has been unloaded.

The ORACLE routine closes.

SQL > startup mount

ORACLE instance has been started

Total System Global Area 1593835520 bytes

Fixed Size 8793256 bytes

Variable Size 1023411032 bytes

Database Buffers 553648128 bytes

Redo Buffers 7983104 bytes

The database is mounted.

SQL > quit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0-64bit Production

[oracle@oracle~] $rman target sys/oracle

Recovery Manager: Release 12.2.0.1.0-Production on Friday November 16 20:23:39 2018

Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.

Connected to the target database: ORCL (DBID=1503444987, not open)

RMAN > restore database

Starting with restore at 16-11-18

Replace the recovery directory with the target database control file

Assigned channel: ORA_DISK_1

Channel ORA_DISK_1: SID=257 device type = DISK

Skipping data file 5; restored to file / u01/app/oracle/oradata/orcl/pdbseed/system01.dbf

Skipping data file 6; restored to file / u01/app/oracle/oradata/orcl/pdbseed/sysaux01.dbf

Skipping data file 8; restored to file / u01/app/oracle/oradata/orcl/pdbseed/undotbs01.dbf

Skipping data file 9; restored to file / u01/app/oracle/oradata/orcl/orclpdb/system01.dbf

Skipping data file 10; restored to file / u01/app/oracle/oradata/orcl/orclpdb/sysaux01.dbf

Skipping data file 11; restored to file / u01/app/oracle/oradata/orcl/orclpdb/undotbs01.dbf

Skipping data file 12; restored to file / u01/app/oracle/oradata/orcl/orclpdb/users01.dbf

Channel ORA_DISK_1: starting to restore data file backup set

Channel ORA_DISK_1: specifying data files to restore from the backup set

Channel ORA_DISK_1: restore data file 00001 to / u01/app/oracle/oradata/orcl/system01.dbf

Channel ORA_DISK_1: restore data file 00003 to / u01/app/oracle/oradata/orcl/sysaux01.dbf

Channel ORA_DISK_1: restore data file 00004 to / u01/app/oracle/oradata/orcl/undotbs01.dbf

Channel ORA_DISK_1: restore data file 00007 to / u01/app/oracle/oradata/orcl/users01.dbf

Channel ORA_DISK_1: restore data file 00013 to / opt/oracle/oradata/rmandb/rmants.ora

Channel ORA_DISK_1: restore data file 00014 to / u01/app/oracle/oradata/rmandb/rmants.ora

Channel ORA_DISK_1: restore data file 00015 to / u01/app/oracle/oradata/rmandb/tab1.dbf

Channel ORA_DISK_1: reading backup fragment / u01/app/oracle/product/12.2.0/dbhome_1/dbs/01ticu3n_1_1

Channel ORA_DISK_1: fragment handle = / u01/app/oracle/product/12.2.0/dbhome_1/dbs/01ticu3n_1_1 tag = TAG20181116T201551

Channel ORA_DISK_1: backup fragment 1 restored

Channel ORA_DISK_1: restore completed. Time: 00:01:16

Completed restore in 16-11-18

RMAN > recover database until time "to_date ('2018-11-16 20-20-20-20-20-20-20-20-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12, 2018-11-16, 20, 20, 20, 12, 15, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 12, 20, 20, 20, 20, 20, 20,

Starting with recover at 16-11-18

Use channel ORA_DISK_1

Starting media recovery

Media recovery complete, time: 00:00:01

Completed recover in 16-11-18

RMAN > alter database open resetlogs

Processed statement

RMAN > quit

The recovery Manager is complete.

[oracle@oracle~] $sqlplus sys/oracle as sysdba

SQLPlus: Release 12.2.0.1.0 Production on Friday November 16 20:29:53 2018

Copyright (c) 1982, 2016, Oracle. All rights reserved.

Connect to:

Oracle Database 12c Enterprise Edition Release 12.2.0.1.0-64bit Production

SQL > select from tab1

ID 1

9. Restore tablespaces

Note: if only the data files in a specific tablespace are lost, you can choose to restore only this tablespace instead of the entire database, and the tablespace can be done without shutting down the database, just offline the tablespace

Sql > create tablespace tab2

Datafile'/u01/app/oracle/oradata/rmandb/tab2.dbf' size 10m

Sql > quit

$rman target sys/oracl

Rman > backup tablespace tab2

Rman > quit

$mv/u01/app/oracle/oradata/rmandb/tab2.dbf / u01/app/oracle/oradata/rmandb/tab2.dbf.bak (simulated tablespace data file is missing)

$rman target sys/oracle

Rman > run {

Sql 'alter tablespace tab2 offline immediate'

Restore tablespace tab2

Recover tablespace tab2

Sql 'alter tablespace tab2 online'

}

Rman > quit

$ls / opt/oracle/oradata/rmandb/ (see if tab2.dbf appears below)

10. Backup and recovery of data files

① views all data files in the current database

Sql > col file_name for A55

Sql > set line 100

Sql > select file_id,file_name,tablespace_name from dba_data_files; (write down the id of the data file)

② backup data files

Sql > quit

$rman target sys/oracle11g

Rman > backup datafile 6

③ simulation deletes the data file tab6.dbf

Rman > quit

$mv / u01/app/oracle/oradata/rmandb/tab6.dbf / u01/app/oracle/oradata/rmandb/tab6.bak1

$rman target sys/oracle

Rman > run {

Allocate channel dev1 type disk

Sql 'alter tablespace tab2 offline immediate'

Restore datafile 6

Recover datafile 6

Sql 'alter tablespace tab6 online'

Release channel dev1

}

Rman > quit

$ls / opt/oracle/oradata/rmandb/ (see if tab2.dbf appears below)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report