User-managed backup and recovery for Oracle databases

Source: Internet
Author: User

OracleIn the database,Backup and recoveryThere are many ways to achieve this. This article introducesUser Management. User-managed backup refers to the use of OS commands to back up physical database files.

Back up database

Database Consistency backup: After the database is closed, the physical files of the database are backed up. At this time, the scn values of the data files are exactly the same. Therefore, it is called Database Consistency backup or cold backup, which is suitable for archive mode and non-archive mode.

Temporary understanding of user-managed cold backup: Use the OS command to directly copy physical database files in the database shutdown state.

Database non-consistent backup: backs up the physical files of the database in the open state, and the database content may change, resulting in inconsistent data file scn. Therefore, it is called the database's non-consistent backup or hot backup, only applicable to archive mode.

Full recovery archive mode based on user management)

1. Back up the physical files of the database in the open state, non-consistent backup of the database, hot backup, without affecting business operations)

2. deleting data files to simulate file loss only deletes all data files. Other files such as control files are in normal state)

3. Restore data files

4. Application archiving logs

5. Check whether the data is completely restored.

 
 
  1. SQL> conn evan/evan
  2.  
  3. Connected.
  4.  
  5. SQL> insert into t_evan values ('oracle ');
  6.  
  7. 1 row created.
  8.  
  9. SQL> insert into t_evan values ('java ');
  10.  
  11. 1 row created.
  12.  
  13. SQL> commit;
  14.  
  15. Commit complete.
  16.  
  17. SQL> select * from t_evan;
  18.  
  19. TEXT
  20.  
  21. --------------------------------------------------------------------------------
  22.  
  23. Oracle
  24.  
  25. Java
  26.  
  27. -- Sysdba backup
  28.  
  29. SQL> conn/as sysdba
  30.  
  31. Connected.
  32.  
  33. SQL> select name from v $ datafile;
  34.  
  35. NAME
  36.  
  37. --------------------------------------------------------------------------------
  38.  
  39. /Oracle/10g/oracle/product/10.2.0/oradata/oralife/system01.dbf
  40.  
  41. /Oracle/10g/oracle/product/10.2.0/oradata/oralife/undotbs01.dbf
  42.  
  43. /Oracle/10g/oracle/product/10.2.0/oradata/oralife/sysaux01.dbf
  44.  
  45. /Oracle/10g/oracle/product/10.2.0/oradata/oralife/users01.dbf
  46.  
  47. /Oracle/10g/oracle/product/10.2.0/oradata/oralife/example01.dbf
  48.  
  49. SQL> alter database begin backup;
  50.  
  51. Database altered.
  52.  
  53. SQL> host cp/oracle/10g/oracle/product/10.2.0/oradata/oralife/*. dbf/oracle/10g/oracle/bakup/database/-- back up all data files
  54.  
  55. SQL> alter database backup controlfile to '/oracle/10g/oracle/bakup/database/oralife. ctl'; -- backup control file
  56.  
  57. Database altered.
  58.  
  59. Certificate -----------------------------------------------------------------------------------------------------------------------------------------
  60.  
  61. Forget alter database end backup;
  62.  
  63. Certificate -----------------------------------------------------------------------------------------------------------------------------------------
  64.  
  65. SQL> alter system archive log current; -- archive the current log Group
  66.  
  67. System altered.

Use rm to delete all data files (*. dbf );

 
 
  1. SQL> conn evan/evan
  2.  
  3. Connected.
  4.  
  5. SQL> select * from t_evan;
  6.  
  7. TEXT
  8.  
  9. --------------------------------------------------------------------------------
  10.  
  11. Oracle
  12.  
  13. Java
  14.  
  15. SQL> insert into t_evan values ('spring ');
  16.  
  17. 1 row created.
  18.  
  19. SQL> commit;
  20.  
  21. Commit complete.
  22.  
  23. SQL> ALTER SYSTEM CHECKPOINT; -- refreshes modified data from the cache to the disk, and updates control files and data files.
  24.  
  25. System altered.
  26.  
  27. SQL> ALTER SYSTEM SWITCH LOGFILE; -- log SWITCH
  28.  
  29. System altered.

View alter_oralife.log error message: some files do not exist

Complete recovery

Copy the backup data file to the specified destination location for restoration:

 
 
  1. SQL> recover database -- open status
  2.  
  3. ORA-00283: recovery session canceled due to errors
  4.  
  5. ORA-01124: cannot recover data file 1-file is in use or recovery
  6.  
  7. ORA-01110: data file 1:
  8.  
  9. '/Oracle/10g/oracle/product/10.2.0/oradata/oralife/system01.dbf'
  10.  
  11. SQL> shutdown immediate -- open status
  12.  
  13. ORA-01122: database file 1 failed verification check
  14.  
  15. ORA-01110: data file 1: '/oracle/10g/oracle/product/10.2.0/oradata/oralife/system01.dbf'
  16.  
  17. ORA-01208: data file is an old version-not accessing current version
  18.  
  19. SQL> startup force mount; -- enters the mount State to restore
  20.  
  21. ORACLE instance started.
  22.  
  23. Total System Global Area 528482304 bytes
  24.  
  25. Fixed Size 1220360 bytes
  26.  
  27. Variable Size 163578104 bytes
  28.  
  29. Database Buffers 356515840 bytes
  30.  
  31. Redo Buffers 7168000 bytes
  32.  
  33. Database mounted.
  34.  
  35. SQL> recover database
  36.  
  37. Media recovery complete.
  38.  
  39. SQL> alter database open;
  40.  
  41. Database altered.
  42.  
  43. SQL> conn evan/evan -- use evan to log on to view the recovery status
  44.  
  45. Connected.
  46.  
  47. SQL> select * from t_evan;
  48.  
  49. TEXT
  50.  
  51. --------------------------------------------------------------------------------
  52.  
  53. Oracle
  54.  
  55. Java
  56.  
  57. Spring

There are no application archiving logs. There are several ways to archive application logs:

Specify log: {<RET> = suggested | filename | AUTO | CANCEL}

When restoring a data file in the open state, you should offline it and restore it online. All the recovery should be completed in the open state as much as possible.

To understand checkpoint, alter system archive log current;, alter system switch logfile.

We will introduce Oracle database backup and recovery based on user management. We hope this introduction will bring you some benefits.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.