Db2 database backup Bat script (implements backup, compression, and deletion of backup data before compression)

Source: Internet
Author: User

I have always wanted to share with you my experiences and experiences on how to automate O & M of business systems in windows, but I have never been able to do so due to time and work. Now we have posted a simple automated and timed script for online hot-standby db2 data to learn and make progress together. @ Echo offREM Create by fengzhanhai on 2010.12.23 Used by backup database db2
REM --- tasks: Run at 24 o'clock every night
REM scheduled task command reference format: "C: \ Program Files \ IBM \ SQLLIB \ BIN \ db2cmd.exe" "F: \ db2-backup-bbs \ script \ dbbackup. bat" REM --- environment configuration -------------
Set Backup_Log = F: \ db2-backup-bbs \ script \ db2back. log
Add a carriage return at the end of REM ---DBlist.txt to list the databases to be backed up.
Set DBList = F: \ db2-backup-bbs \ script \ dblist.txt
Set User = db2admin
Set Pwd = your db2 password
Set TargetPath = F: \ db2-backup \
For/f "tokens = 1, 2, 3 delims =-" % A in ('date/t') do set FileNameDate = % A % B % C
For/f "tokens = 1, 2 delims =:" % A in ('time/t') do set FileNameTime = % A % B
Set FilePath = % FileNameDate % FileNameTime %
Set slave header = db2 backup db
Set tailtail = user % User % using % Pwd % online toREM rar.exegreen compression software package users can download the attached rar.txt content and change it to files suffixed with exe
Set ProgramRar = % ~ Dp0 \ rar.exe REM --- check the database configuration file ------
If not exist % DBList % (
Echo % date % time % DBList % not found> % Backup_Log %
Exit
) REM --- folder created on the current day ------
If not exist % TargetPath % FilePath % (
Md % TargetPath % FilePath %> nul
Echo % date % time % create % TargetPath % FilePath % folder> % Backup_Log %
) Else (
Echo % date % time % TargetPath % FilePath % exist> % Backup_Log %
) REM --- backup data -------------
For/f "tokens = *" % j in (% DBList %) do (
% Expose header % j % tailtail % TargetPath % FilePath %> % Backup_Log %
Echo % date % time % j backup done> % Backup_Log %
) REM --- compress data -------------
% ProgramRar % a % TargetPath % FilePath %> nul
Echo % date % time % compress % TargetPath % FilePath % done> % Backup_Log % REM --- delete data before compression -------------
RD/Q/S % TargetPath % FilePath %
Echo % date % time % delete % TargetPath % FilePath % done> % Backup_Log % exit parameters Note: you must first enable the database configuration parameters that support online backup:
Db2 update db cfg for sample using userexit on Enable User exit
Db2 update db cfg for sample using logretain on after enabling the archive log to enable these parameters, the database is in the backup pending state. Remember to make full offline backup of the database!
If you do not enable the above parameter settings, your database does not support hot standby mode. Therefore, when you use this script, Database Backup will be suspended temporarily and even affect the normal operation of your business.

The accessories above dblist.txtrar.txt are the list of databases to be backed up and the compression-free installation software.

Related Article

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.