Database backup script for N consecutive times

Source: Internet
Author: User

----------------------------------------------------------------------------

---- This is andkylee's personal originality. Please repost it with respect to the author's Labor achievements;

---- The original output must be specified for reprinting.Location
:
Http://blog.csdn.net/andkylee

---- Keywords: ASE database backup Automatic Continuous backup delete old backup

----------------------------------------------------------------------------

 

We know the Backup Frequency Based on the business data of the production database, such as monthly, weekly, daily, and sometimes even hourly. To back up the Sybase Database, you must manually write the command. In this way, the next backup file may be overwritten. Different backup file names generated by the script during the next backup will not overwrite the previous backup file. In this way, multiple database backup files of the database can be automatically retained, which effectively guarantees the security of the database.

Copy the following script to notepad and save it as BAT. Add the task to windows,
========================================================== ========================================================== ================

Echo off
CLS
: By default, database backup for the last seven days is retained. You can change 7 to the number of consecutive days you want.
: Where D:/Sybase/data is the database backup address, you can specify it again
: The Master is the default backup database name, which can be changed to another user database name.
Set databak_path = D:/Sybase/Data
Set databasename = Master
Echo dt = Date ()-7> % Temp %/olddate. vbs
Echo S = right (Year (DT), 4) ^ & "-" ^ & right ("0" ^ & month (DT), 2) ^ & "-" ^ & right ("0" ^ & Day (DT), 2) >>% TEMP %/olddate. vbs
Echo wscript. Echo S> % Temp %/olddate. vbs
For/F % F in ('cscript/nologo % Temp %/olddate. vbs ') Do @ set delflag = % F
: Delete the database backup file seven days ago
If exist "% databak_path %/% databasename % _ % delflag %. Dump" Del "% databak_path %/% databasename % _ % delflag %. Dump"
Del % Temp %/olddate. vbs
If exist % Temp %/dump_db.txt (DEL % Temp %/dump_db.txt)
Echo dump database % databasename % to "% databak_path %/% databasename % _ % Date :~ 0, 10%. Dump "> % Temp %/dump_db.txt
Echo go> % Temp %/dump_db.txt
ISQL-USA-p-syour_servername <"% Temp %/dump_db.txt"> % databak_path %/dump_log.txt
Del "% Temp %/dump_db.txt"

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.