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.
-
- -- Create a data table space
-
- CreateTablespace test_data
-
- Logging
-
- Datafile'/U01/APP/oradata/test. DBF'
-
- Size32 m
-
- Autoextend on
-
- Next32 m maxsize 2048 m
- Extent management local;
-
-
-
- -- Create a user and specify a tablespace
-
- Create
User test identified by 123
-
- DefaultTablespace test_data
-
- TemporaryTablespace temp;
-
-
-
- -- Grant permissions to users
-
- Grant
Connect, resource to test;
Log On with the test user, create a table, and insert two pieces of data:
- Create
Table T1 (
- Id varchar (50) primary
Key,
- Title varchar (50)
- );
-
- Insert
Into T1 values (sys_guid (),'T1');
- Insert
Into T1 values (sys_guid (),'T2');
- Commit;
First, write an exported script file:
- Export oracle_base =/u01/APP
- Export ORACLE_HOME =/u01/APP/Oracle
- Export oracle_sid = test
- Export Path = $ ORACLE_HOME/bin: $ path
- D = $ (date '+ % Y % m % D ')
- Exp test/123 @ test file =/home/Oracle/backup/$ D. dmp log =/home/Oracle/backup/$ D. Log owner = test
- 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:
- Chmod + x backup. Sh
Run the crontab-e command to edit the task plan of an Oracle user:
- [Oracle @ localhost backup] $ crontab-e
- 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.