Set regular Oracle Database Backup in Linux

Source: Internet
Author: User

I installed Oracle yesterday and tried automatic backup today. I installed Linux and Oracle these two days for this purpose.

For SQL Server, you can use SQL Server Management studio for regular backup, which is convenient. But to regularly back up ORACLE data, we need to write export commands and set scheduled tasks for Linux.

First, create a database for testing.

  1. -- Create a data table space
  2. CreateTablespace test_data
  3. Logging
  4. Datafile'/U01/APP/oradata/test. DBF'
  5. Size32 m
  6. Autoextend on
  7. Next32 m maxsize 2048 m
  8. Extent management local;
  9.  
  10. -- Create a user and specify a tablespace
  11. Create
    User test identified by 123
  12. DefaultTablespace test_data
  13. TemporaryTablespace temp;
  14.  
  15. -- Grant permissions to users
  16. Grant
    Connect, resource to test;

Log On with the test user, create a table, and insert two pieces of data:

    1. Create
      Table T1 (
    2. Id varchar (50) primary
      Key,
    3. Title varchar (50)
    4. );
    5.  
    6. Insert
      Into T1 values (sys_guid (),'T1');
    7. Insert
      Into T1 values (sys_guid (),'T2');
    8. Commit;

First, write an exported script file:

    1. Export oracle_base =/u01/APP
    2. Export ORACLE_HOME =/u01/APP/Oracle
    3. Export oracle_sid = test
    4. Export Path = $ ORACLE_HOME/bin: $ path
    5. D = $ (date '+ % Y % m % D ')
    6. Exp test/123 @ test file =/home/Oracle/backup/$ D. dmp log =/home/Oracle/backup/$ D. Log owner = test
    7. Zip-M/home/Oracle/backup/mongod.zip/home/Oracle/backup/$ D. DMP/home/Oracle/backup/$ D. Log

The first four sentences are environment variables. Because crontab does not use the environment variables of oracle users during scheduled calls, you must import them first. Row 6th uses the current date as the exported file name, such as 20120626. DMP and 20120626.log. In line 3, compress the two files into a zip package and delete them.

Use the CHMOD command to mark this sh as executable:

    1. Chmod + x backup. Sh

 

Run the crontab-e command to edit the task plan of an Oracle user:

    1. [Oracle @ localhost backup] $ crontab-e
    2. 42 13 ***/home/Oracle/backup. Sh

In this way, a plan is added to run/home/Oracle/backup. Sh at every day.

 

In addition, after running every day, you will receive a mail Notification, you can see in the mail whether the operation is correct.

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.