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 cold backup script

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

I. principle

Cold backup

Database completes the process of copying all physical system files in a closed state, also known as offline backup

Suitable for non-archived mode, the database is in a consistent state

Steps

First get all the physical file locations where the database is running in the running library, and then shut down the database in the plan (shutdown)

Then copy the physical writer to the backup path or backup device

Start the database to provide normal services immediately after the backup is completed

Summary-benefits

The concept of cold backup mode is easy to understand, that is, files that need to be backed up are copied to a secure location.

The operation is relatively simple and does not require much intervention.

Easy to recover to a certain point in time (just copy the file back)

Can be combined with the archiving method to restore the "latest state" of the database.

4. Summary-shortcomings

When backing up, the database must be in a consistent closed state

Recovery can only be provided to a certain point in time

The speed of backup is relatively slow, especially the large amount of data has a great impact on performance.

Unable to achieve table-and user-level data recovery

II. Cases

First of all, you should find out the location of the database's data files, log files, control files, and temporary files in the relevant views. Note: do not directly put the cp under oradata on the line, because the files in the production library are usually distributed on different disks and different places, so get the real path in the view.

1)。 Check whether the database is CDB

SYS@newtest > select name, decode (cdb, 'YES',' Multitenant Option enabled', 'Regular 12c Database:') "Multitenant Option", open_mode, con_id from v$database

NAME Multitenant Option OPEN_MODE CON_ID

NEWTEST Multitenant Option enabled READ WRITE 0

YES indicates that the database is CDB, and if it is NO, it is NO-CDB (normal database).

2)。 View information about instances and databases

SYS@newtest > select instance_name,version,status,archiver,database_status from v$instance

INSTANCE_NAME VERSION STATUS ARCHIVE DATABASE_STATUS

Newtest 12.2.0.1.0 OPEN STARTED ACTIVE

SYS@newtest > select dbid,name,log_mode from v$database

DBID NAME LOG_MODE

1779551310 NEWTEST ARCHIVELOG

SYS@newtest > set linesize 180

SYS@newtest > col guid format A40

SYS@newtest > col name format A20

SYS@newtest > select con_id, dbid, guid, name, open_mode from v$pdbs

CON_ID DBID GUID NAME OPEN_MODE 2 603865257 32CAC9A05E614355926257BE671D9AFC PDB$SEED READ ONLY 3 3394996704 24549D14BBEB417BAB312BF19BC5259E PDBTEST READ WRITE 4 50957894 D4B2FCAAC2B944CC8AF5864EC7CB853C CLONEPDB_PLUG READ WRITE

3)。 View data files and status information

SYS@newtest > col file_name format A60

SYS@newtest > select file_name,tablespace_name,status,online_status from dba_data_files

FILE_NAME TABLESPACENAME STATUS ONLINE

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ SYSTEM01.DBF SYSTEM AVAILABLE SYSTEM

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ SYSAUX01.DBF SYSAUX AVAILABLE ONLINE

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ UNDOTBS01.DBF UNDOTBS1 AVAILABLE ONLINE

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ USERS01.DBF USERS AVAILABLE ONLINE

SYS@newtest > col con_id format 99

SYS@newtest > col name format A80

SYS@newtest > select con_id,FILE#,NAME,status,enabled from v$datafile order by 1

CON_ID FILE# NAME STATUS ENABLED

1 1 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ SYSTEM01.DBF SYSTEM READ WRITE 1 3 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ SYSAUX01.DBF ONLINE READ WRITE 1 5 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ UNDOTBS01.DBF ONLINE READ WRITE 1 7 C:\ APP\ ADMINISTRATOR \ VIRTUAL\ ORADATA\ NEWTEST\ USERS01.DBF ONLINE READ WRITE 2 2 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBSEED\ SYSTEM01.DBF SYSTEM READ WRITE 2 4 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBSEED\ SYSAUX01.DBF ONLINE READ WRITE 2 6 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBSEED\ UNDOTBS01.DBF ONLINE READ WRITE 3 8 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBTEST\ SYSTEM01.DBF SYSTEM READ WRITE 3 11 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBTEST\ USERS01.DBF ONLINE READ WRITE 3 10 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBTEST\ UNDOTBS01.DBF ONLINE READ WRITE 3 9 C:\ APP \ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBTEST\ SYSAUX01.DBF ONLINE READ WRITE

CON_ID FILE# NAME STATUS ENABLED

4 42 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CLONEPDB_PLUG\ UNDOTBS01.DBF ONLINE READ WRITE 4 41 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CLONEPDB_PLUG\ SYSAUX01.DBF ONLINE READ WRITE 4 40 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CLONEPDB_PLUG\ SYSTEM01.DBF SYSTEM READ WRITE 4 43 C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CLONEPDB_ PLUG\ USERS01.DBF ONLINE READ WRITE

15 rows selected.

4)。 View temporary files

SYS@newtest > col name format A100

SYS@newtest > select name from v$tempfile

NAME

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ TEMP01.DBF

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBSEED\ TEMP012017-12-13 October 17-23-31-944-PM.DBF

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBTEST\ TEMP012017-12-13 October 17-23-31-944-PM.DBF

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CLONEPDB_PLUG\ TEMP012017-12-13 October 17-23-31-944-PM.DBF

5)。 View log files

SYS@newtest > col member format A60

SYS@newtest > select member from v$logfile

MEMBER

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ REDO03.LOG

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ REDO02.LOG

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ REDO01.LOG

6)。 View control file

SYS@newtest > select name from v$controlfile

NAME

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CONTROL01.CTL

C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CONTROL02.CTL

7)。 Create a backup directory

SYS@newtest > ho mkdir c:\ oracleback

SYS@newtest > select'ho mkdir'| |'& dir\'| | NAME from v$pdbs

Enter value for dir: C:\ oracleback

Old 1: select'ho mkdir'| |'& dir\'| | NAME from v$pdbs

New 1: select'ho mkdir'| |'C:\ oracleback\'| | NAME from v$pdbs

'HOMKDIR' | |' C:\ ORACLEBACK\'| | NAME

Ho mkdir C:\ oracleback\ PDB$SEED

Ho mkdir C:\ oracleback\ PDBTEST

Ho mkdir C:\ oracleback\ CLONEPDB_PLUG

8)。 Use connectors to generate copy file commands

SYS@newtest > select'ho copy'| | name |'& dir' from v$controlfile

2 union all

3 select'ho copy'| | member | |'& dir' from v$logfile

4 union all

5 select'ho copy'| | file_name | |'& dir' from dba_data_files

6 union all

7 select'ho copy'| | vd.name | |'& dir\'| | vp.name as command from v$datafile vd join v$pdbs vp using (con_id)

8 union all

9 select'ho copy'| | vt.name | |'& dir\'| | vp.name as command from v$tempfile vt join v$pdbs vp using (con_id)

10 /

Enter value for dir: C:\ oracleback

Old 1: select'ho copy'| | name |'& dir' from v$controlfile

New 1: select'ho copy'| | name | |'C:\ oracleback' from v$controlfile'

Enter value for dir: C:\ oracleback

Old 3: select'ho copy'| | member |'& dir' from v$logfile

New 3: select'ho copy'| | member | |'C:\ oracleback' from v$logfile'

Enter value for dir: C:\ oracleback

Old 5: select'ho copy'| | file_name |'& dir' from dba_data_files

New 5: select'ho copy'| | file_name | |'C:\ oracleback' from dba_data_files'

Enter value for dir: C:\ oracleback

Old 7: select'ho copy'| | vd.name | |'& dir\'| | vp.name as command from v$datafile vd join v$pdbs vp using (con_id)

New 7: select'ho copy'| | vd.name | |'C:\ oracleback\'| | vp.name as command from v$datafile vd join v$pdbs vp using (con_id)

Enter value for dir: C:\ oracleback

Old 9: select'ho copy'| | vt.name | |'& dir\'| | vp.name as command from v$tempfile vt join v$pdbs vp using (con_id)

New 9: select'ho copy'| | vt.name | |'C:\ oracleback\'| | vp.name as command from v$tempfile vt join v$pdbs vp using (con_id)

'HOCOPY' | | NAME | |'C:\ ORACLEBACK'

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CONTROL01.CTL C:\ oracleback

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CONTROL02.CTL C:\ oracleback

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ REDO03.LOG C:\ oracleback

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ REDO02.LOG C:\ oracleback

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ REDO01.LOG C:\ oracleback

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ SYSTEM01.DBF C:\ oracleback

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ SYSAUX01.DBF C:\ oracleback

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ UNDOTBS01.DBF C:\ oracleback

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ USERS01.DBF C:\ oracleback

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBSEED\ SYSTEM01.DBF C:\ oracleback\ PDB$SEED

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBSEED\ SYSAUX01.DBF C:\ oracleback\ PDB$SEED

'HOCOPY' | | NAME | |'C:\ ORACLEBACK'

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBSEED\ UNDOTBS01.DBF C:\ oracleback\ PDB$SEED

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBTEST\ SYSTEM01.DBF C:\ oracleback\ PDBTEST

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBTEST\ SYSAUX01.DBF C:\ oracleback\ PDBTEST

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBTEST\ UNDOTBS01.DBF C:\ oracleback\ PDBTEST

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBTEST\ USERS01.DBF C:\ oracleback\ PDBTEST

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CLONEPDB_PLUG\ SYSTEM01.DBF C:\ oracleback\ CLONEPDB_PLUG

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CLONEPDB_PLUG\ SYSAUX01.DBF C:\ oracleback\ CLONEPDB_PLUG

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CLONEPDB_PLUG\ UNDOTBS01.DBF C:\ oracleback\ CLONEPDB_PLUG

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CLONEPDB_PLUG\ USERS01.DBF C:\ oracleback\ CLONEPDB_PLUG

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBSEED\ TEMP012017-12-13 October 17-23-31-944-PM.DBF C:\ oracleback\ PDB$SEED

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ PDBTEST\ TEMP012017-12-13 October 17-23-31-944-PM.DBF C:\ oracleback\ PDBTEST

'HOCOPY' | | NAME | |'C:\ ORACLEBACK'

Ho copy C:\ APP\ ADMINISTRATOR\ VIRTUAL\ ORADATA\ NEWTEST\ CLONEPDB_PLUG\ TEMP012017-12-13 October 17-23-31-944-PM.DBF C:\ oracleback\ CLONEPDB_PLUG

23 rows selected.

9)。 Write related scripts

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