Implement automatic oracle backup bat in windows

Source: Internet
Author: User

@ Echo off
Setlocal enabledelayedexpansion
Title % date % time :~, 8% by LiaoNing Sunray Software Technology
 
: Defines the database SID.
Set SID = sryx254
 
: Defines an array of user names (separated by spaces, for example, user1 user2 user3)
Set userArr = user1 user2 user3
Set pswdArr = password1 password2 password3
 
: Specified number of days to delete
Set daysAgo = 7
 
: Specifies the backup path.
Set filePath = E: \ dmp_beifen \
 
 
: Defines the internal variables of the script.
Set time _ = % time: = 0%
Set fileName = % date :~ 0, 4% % date :~ 5, 2% % date :~ 8, 2% _ % time _:~ 0, 2% % time _:~ 3, 2%. dmp
Set newDir = % date :~ 0, 10% \
 
: Create a folder named after the day
If not exist % filePath % md % filePath %
If not exist % filePath % newDir % md % filePath % newDir %
 
: Export data
Set/a n = 1
Call: sub userArr %
Call: sub pswdArr %
Set/a arrLength = nuserArr
: Loop
Exp! UserArr % n %! /! PswdArr % n %! @ % SID % file = % filePath % newDir %! UserArr % n %! _ % FileName %
: Echo test display! UserArr % n %! /! PswdArr % n %!
If % n % lss % arrLength % set/a "n + = 1" & goto loop
Goto next
: Sub
Set % 1% n % = % 2
If not "% 3" = "" (set/a n + = 1
Shift/2 & goto sub)
Set/a "n % 1 = n, n = 1" & goto: eof
: Next
 
 
: Delete data N days ago
Set d = % date :~ 0, 10%
Mshta vbscript: createobject ("scripting. filesystemobject "). opentextfile ("temp.txt", 2, true ). write (FormatDateTime (dateadd ("d",-% daysAgo % + 1, "% d %"), vb1_date) (window. close)
For/f "tokens = 1 delims =" % I in (temp.txt) do set t1 = % I
For/f "delims =" % I in ('dir/ad/B % filePath % ') do (
Set t2 = % I
Set t3 =! T2 :~ 0, 10!
If! T3! Lss! T1! Rd/s/q "% filePath % I ")
Del/f temp.txt
 
 
 
Note that you must also set the short date and long date format to "yyyy-mm-dd" in the control panel ", otherwise, the data that was last deleted N days ago may be faulty (the backup file was deleted several days later)

From a running pig

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.