Oracle 10 Gb database automatic backup, bat batch processing code

Source: Internet
Author: User

Batch File [backup. bat] p.s: Never name this batch file exp. bat smartly; otherwise ......, If you are interested, try it.

@ Echo off
REM ============================================== ====================
REM backup data under the rsdlouter account of the server
REM ============================================== ====================

Set BACKUP_DIR = D: \ DATABACKUP
Set BACKUP_WAREHOUSE = D: \ DATABACKUP \ DATABACKUP_LOG_DMP
Set ORACLE_USERNAME = rsdlouter
Set ORACLE_PASSWORD = rsdlouter
Set ORACLE_DB = orcl
Set BACK_OPTION = "TABLES = (LOG, NEWS )"
Set RAR_CMD = "D: \ Program Files \ HaoZip \ Rar.exe"

If not exist "DATABACKUP" md DATABACKUP
If not exist "DATABACKUP \ DATABACKUP_LOG_DMP \" md DATABACKUP \ DATABACKUP_LOG_DMP \

For/f "tokens = 1, 2" % a in ('date/t') do set TODAY = %
REM if the file name takes hours and minutes, use the first line of the following statement.
Set BACK_NAME = % ORACLE_DB % _ % ORACLE_USERNAME % _ % TODAY % (% time :~ 0, 2% hour % time :~ 3,2% min % time :~ 6, 2% seconds )_
REM set BACK_NAME = % ORACLE_DB % _ % ORACLE_USERNAME % _ % TODAY %
Set BACK_FULL_NAME = % BACKUP_DIR % \ % BACK_NAME %


REM logs the operation to the batch processing log % BACK_FULL_NAME % _ bat. log.

Echo ========================== data under the rsdlouter account of the backup server ============== ==>>> % BACK_FULL_NAME % _ bat. log
Echo backup starts...> % BACK_FULL_NAME % _ bat. log
Echo current time: % DATE % time %> % BACK_FULL_NAME % _ bat. log


REM calls exp Tool
Exp % ORACLE_USERNAME %/% ORACLE_PASSWORD % @ % ORACLE_DB % grants = Y % BACK_OPTION % file = "% BACK_FULL_NAME %. dmp" log = "% BACK_FULL_NAME % _ exp. log"

If not exist % BACKUP_WAREHOUSE % \ % BACK_NAME % _ DMP md % BACKUP_WAREHOUSE % \ % BACK_NAME % _ DMP

Echo compresses and deletes the original dmp file...> % BACK_FULL_NAME % _ bat. log
Echo current time: % DATE % time %> % BACK_FULL_NAME % _ bat. log

% RAR_CMD % a-df "% BACKUP_DIR % \ % back_name1__dmp.rar" "% BACK_FULL_NAME %. dmp"
REM "% BACK_FULL_NAME % exp. log"
Echo compresses and deletes the original dmp file! >>% BACK_FULL_NAME % _ bat. log
Echo current time: % DATE % time %> % BACK_FULL_NAME % _ bat. log

Echo starts to move the file...> % BACK_FULL_NAME % _ bat. log
Echo current time: % DATE % time %> % BACK_FULL_NAME % _ bat. log

Move % BACKUP_DIR % \ *. rar % BACKUP_WAREHOUSE % \ % BACK_NAME % _ DMP \

Echo file moved! >>% BACK_FULL_NAME % _ bat. log
Echo current time: % DATE % time %> % BACK_FULL_NAME % _ bat. log

REM net send % userdomain % "logical database backup completed at: % DATE % time %! "

Echo.
Echo backup complete !!! >>% BACK_FULL_NAME % _ bat. log
Echo current time: % DATE % time %> % BACK_FULL_NAME % _ bat. log
Echo =================== the backup server rsdlouter account has completed the data !!! ==================>> % BACK_FULL_NAME % _ bat. log

If not exist % BACKUP_WAREHOUSE % \ % BACK_NAME % _ LOG md % BACKUP_WAREHOUSE % \ % BACK_NAME % _ LOG

Move % BACKUP_DIR % \ *. log % BACKUP_WAREHOUSE % \ % BACK_NAME % _ LOG \
Echo.

Note: place the backup. bat file in the root directory of the d disk and modify the set parameter configuration as needed.

After the backup. bat configuration is complete, you can use the Windows built-in task plan to configure the execution of this batch of files at the specified time. The task plan configuration is very simple and will not be repeated here.

If an exception occurs during Task Scheduling configuration, see my previous article.

Hope to help friends!

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.