Database oracle-----backup recovery (data file loss recovery)

Recovery of oracle data files lost

Background note:
   We often encounter such problems. For example, when I create a tablespace larmss and a data file larmss.dbf, the space contains our system users and data. Suddenly, the data file
larmss.dbf was lost that day without knowing the reason. And I don't have a backup of this file, how do we get the data back.
      Fortunately, the recovery mechanism of oracle data can help you accomplish this function. However, there are prerequisites for doing such a thing.
The premise is that you must first set the database to archive mode, and then create tablespaces and users. I won't describe the archive mode here. Let's talk about why the object is created first and then archived.
This situation cannot be recovered.
The reason is very simple: for example, if you are writing a novel now, every day after you finish writing, you will make a backup of today's novel in a backup folder. Only in this way will you be able to copy your novel from
your novel after being infected with a virus that day. Find the recovery in the backup file. If you only remembered to create a folder to backup your daily writing data after writing for a month, suddenly your novel disappeared that day, and you want to restore to the current state, you can restore it from your backup
file. Did you find all the data in the folder? The answer is no, because you have no backup for a month, and the data for that month will not be available. The archiving principle of the database is probably the same.
   Now in order to test the recovery effect and simulate the recovery environment, we need to do the following things:
   1. Set the database to archive mode
   2. Create tablespaces, data files, users and a table.
   3. Delete the data files of the tablespace.
   4. Recover data files
   5. Check if recovery is complete.

 

Task 1: Set
        up the archive. Generally speaking, setting the archive is generally divided into two steps: 1. Set the archive path (database parameter log_archive_dest_1="location='E;\oracle\arhcive'", archive format parameter log_archive_format)
 2. After the parameters are set , the
         specific process of starting the database is the archive mode :
         a. The method of checking whether the archive is started Command method: SQL "archive log list;
                                   view view: select dbid,name,log_mode from v$database
                                              select * from v$archive_dest//But set 10 An archive path
         b To set the archive, to modify the database parameter file, modify the two parameters
                      1.ARCHIVE DEST (archive destination)
                      log_archive_dest_1="location=E:\applicationTool\oracle\product\oradata\PRACTICE\archive"; set the archive file Place the location
                                
        where location means the archive will be copied to the local disk location
                      2.ARCHIVE MODE (archive format)
                       log_archive_format=%s.arc where %s is the serial number


       SQL> alter system set log_archive_dest_1="location=E:\applicationTool\oracle\product\oradata\PRACTICE\archive" scope=spfile;
            alter system set log_archive_format="ARC%S_%R.%T" scope=spfile;
       SQL > shutdown immediate
       SQL > startup mount;
       SQL > alter database archivelog;
       SQL > alter database open;
       SQL > archive log list;//Check if it is successful
    
      In order to check the effect, you can force the database log to switch SQL "alter system switch logfile; switch several times , go to the archive directory and see if any files are generated

Task 2: Create tablespaces, data files, users and tables
        SQL"create tablespace larmss datafile 'E:\oracle\data\larmss.dbf' size 20M;
        SQL> create user larmss identified by oracle default tablespace larmss;
        SQl> grant resource ,connect to larmss;
        SQL> conn larmss/oracle
        SQL> create table loan(loanno number,loanamt number(10,2));

       Insert some test data into it

Task 3: Drop tablespace datafiles to simulate a bad environment

        First close the database SQL"shutdown immdeidate;
        then delete the file E:\oracle\data\larmss.dbf in the system.
       
        When you start the database again, it will report the error that the file cannot be found.
        SQL"startup
        you can view the view select * from v $recover_file View the error file number, and query select * from v$datafile where FILE#=fileno to view the specific file error.

Task 4:
      
        General steps to restore data files, first create a new data file at the corresponding location, then repair the data file through the repair mechanism, mount the data file after repair, and finally open the database
        SQL "startup mount;
        SQL>alter database create datafile 'E :\oracle\data\larmss.dbf'
        SQL>set autorecovery on;
        SQL>recover datafile 'E:\oracle\data\larmss.dbf';
        SQL>alter database datafile 'E:\oracle\data\larmss.dbf' online;
        SQL>alter database open;
      so the database is restored and opened

Task 5 Check whether the recovery is successful
       . Use the user larmss/oracle to connect, and go in to see if the data is still there, indicating that the recovery is successful.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324734961&siteId=291194637