当前位置:网站首页>Oracle database backup and recovery

Oracle database backup and recovery

2022-07-07 23:21:00 Mr. Li, a genius

It is not the last blow that breaks the stone , It's the one in front 99 One hit
Articles are constantly updated , You can search by wechat 【 Xiaoqi JAVA interview 】 First time reading , reply 【 Information 】 Access to benefits , reply 【 project 】 Get the source code of the project , reply 【 The resume template 】 Get resume template , reply 【 Learning Roadmap 】 Get a learning roadmap .

 Insert picture description here


Data is a very important asset , However, there are certain security risks in the daily operation of any database , Especially like banks 、 Securities and other financial units , During daily operation , To prevent system failure 、 Data loss caused by virus or improper user operation , There must be a good preparatory plan , To recover the data . Database backup and recovery is a very effective means to prevent disasters , Database backup and recovery is an important management responsibility of database administrators , The success of database backup is crucial to data recovery .

One 、 Backup and recovery overview

In order to ensure the backup and high availability of the computer system , Many high-performance servers often adopt a variety of backup strategies , for example RAID technology 、 hot standby 、 Cluster technology, etc , These backup strategies are considered from the perspective of hardware , These strategies can partially solve the problem of database backup . If the disk media is damaged , You can quickly do simple recovery on the image . However , This kind of hardware backup cannot meet the needs of reality , For example, the data table is deleted by mistake .
Database backup and recovery are opposite operations . Backup is to save a copy of the data in the database , In fact, it is to copy the database to the dump device ( Disk or tape ) The process of ; Recovery refers to when various faults occur ( Hardware failure 、 Software failure 、 Network failure 、 System failure, etc ) Cause database paralysis or errors , Use backup to restore the database to the state at the time of failure , Rebuild the complete database . Database recovery can be divided into database repair and database recovery based on database repair .

1、 The type of backup
According to different data backup methods , Backup can be divided into physical backup and logical backup . Physical backup is the data file that will form the database 、 Redo log file 、 Control documents 、 Copy system files such as initialization parameter files , Save the formed copy to a disk or tape independent of the current system . Logical backup refers to the use of oracle The provided export tool extracts the data from the database , Stored in a binary file .

2、 Type of recovery
Depending on the backup used during database recovery , Recovery can be divided into physical recovery and logical recovery . Physical recovery refers to the use of physical backup to recover the database , That is, use physical backup files to restore damaged files , At the operating system level . And logical recovery is to use binary files of logical backup , Use oracle The import tool provided imports some or all of the information into the database , Recover lost data . According to the degree of database recovery, it can be divided into full recovery and incomplete recovery . After the database fails , If backup can be used to restore the database to the state of failure , Called full recovery , Otherwise, it is called incomplete recovery .

Two 、 Data export and import

When exporting, the selected objects in the database or logical copies of the data dictionary are stored in the operating system in the form of binary files ,dmp File format storage ; When you recover , from dmp Restore the format file to the database .

1、 Data export
oracle11g Database usage exp Tools realize logical backup of data , The tool has 3 Ways of working .
Command line mode : Specify parameter settings directly on the command line .
Parameter file mode : Store the parameter setting information in a parameter file , Use... On the command line parfile Parameter specifies the parameter file .
Interactive mode : Manage export jobs through interactive commands .
Exp The tool provides 4 Export mode .
Full library export mode : Export the entire database .
Mode export mode : Export all objects in the specified mode .
Table export mode : Export all tables specified in the specified schema 、 Partitions and their dependent objects and data .
Tablespace export mode : Export all tables and their dependent objects in the specified tablespace .
this 4 These modes are mainly set by selecting parameters .
The following mainly introduces the command line mode and interaction mode .

Command line mode :
export scott Under the user emp Table and dept surface , The name of the storage file is output.dmp, The log file is output.log
First, enter the directory where the specified files are stored , Suppose the directory name is C Discoid backup, Then execute the corresponding command .
cd backup
exp scott/tiger dumpfile=output.dmp logfile=output.log tables=scott.emp,scott.dept

export scott All objects under the user
cd backup
exp scott/tiger dumpfile=user.dmp

Interactive mode
First, you need to prepare a directory for data backup , Suppose now D:\backup Directory as backup path .
Need to enter into backup Directory ( Operate as a command line ).
cd backup;
Input exp Instructions , Derived data , Enter the user name and password ( for example scott/tiger);

2、 Data import

oracle11g Database usage imp The tool realizes the import of backup data , This tool and the export tool exp There are also 3 Working in : Command line mode 、 Interaction mode and parameter file mode .

Command line mode :
scott Under the user emp and dept Table data missing , Use the backup file exported above to restore .
First, enter the directory where the specified files are stored , Suppose the directory name is C Discoid backup, Then execute the corresponding command .
cd backup
imp scott/tiger dumpfile=output.dmp tables=scott.emp,scott.dept;

hypothesis scott The object under the user is missing , Restore with the previously backed up files scott All objects under the user .
cd backup
imp scott/tiger dumpfile=user.dmp

3、 ... and 、 Cold backup and recovery of database

The cold backup of database is strictly called archive backup , It means that the database needs to shut down the service , All transactions need to be committed . Practically speaking , If you want to back up, you need to back up the following .
Control documents : Control the whole oracle Example information of , have access to v c o n t r o l f i l e Count According to the word Dian look for To . heavy do Japan Records writing Pieces of : through too v controlfile Data dictionary found . Redo log file : adopt v controlfile Count According to the word Dian look for To . heavy do Japan Records writing Pieces of through too vlogfile Data dictionary found
Data files : adopt v d a t a f i l e Count According to the word Dian look for To . nucleus heart with Set up writing Pieces of ( p f i l e ) : send use “ s h o w p a r a m e t e r p f i l e ” look for To . cold To prepare Share fuck do Count According to the library Of To prepare Share fuck do from tube The reason is member Into the That's ok , because this The first First With tube The reason is member body Share deng record . 1 、 send use s y s deng record c o n n s y s / c h a n g e o n i n s t a l l a s s y s d b a ; 2 、 check look for control system writing Pieces of Of Letter Rest s e l e c t ∗ f r o m v datafile Data dictionary found . Core profile (pfile): Use “show parameter pfile” find . Cold backup operation The backup operation of the database is carried out by the administrator , So first log in as an administrator . 1、 Use sys Sign in conn sys/change_on_install as sysdba; 2、 Find information about the control file select * from v datafile Count According to the word Dian look for To . nucleus heart with Set up writing Pieces of pfile send use showparameterpfile look for To . cold To prepare Share fuck do Count According to the library Of To prepare Share fuck do from tube The reason is member Into the That's ok , because this The first First With tube The reason is member body Share deng record .1 send use sys deng record connsys/changeoninstallassysdba;2 check look for control system writing Pieces of Of Letter Rest selectfromvcontrolfile;
3、 Find redo log file information .
select * from v l o g f i l e ; 4 、 look for To the Yes Count According to the writing Pieces of Letter Rest s e l e c t ∗ f r o m v logfile; 4、 Find all data file information select * from v logfile;4 look for To the Yes Count According to the writing Pieces of Letter Rest selectfromvdatafile;
5、 find PFILE file
show parameter pfile;
6、 Keep a record 2、3、4、5 The file path displayed after the command is executed .
7、 close oracle service .
shutdown immediate
8、 Copy out all backup files .
9、 Restart the service ;
startup
This backup is a backup that allows you to shut down your computer .

Cold recovery
When there is an error in the database system , Cold backup files can be used for recovery .
Steps are as follows
1、 close oracle service .
shutdown immediate
2、 Copy all backup files copied during backup to the original directory .
3、 Restart the service .
startup

Four 、 summary

The relevant contents here have not been sorted out yet , The article continues to be updated later , Recommended collection .

The commands involved in the article must be typed several times each like me , Only in the process of knocking can you find out whether you really master the command .

You can search by wechat 【 Xiaoqi JAVA interview 】 First time reading , reply 【 Information 】 Access to benefits , reply 【 project 】 Get the source code of the project , reply 【 The resume template 】 Get resume template , reply 【 Learning Roadmap 】 Get a learning roadmap .

原网站

版权声明
本文为[Mr. Li, a genius]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207072028282154.html