Batch processing automates daily backup and purge of database files

Source: Internet
Author: User

Description

Use task scheduling to execute batch files at specified times per day;

1. Implement automatic copy database backup file to a different host

2, automatically delete the specified number of days of backup files


1. Batch processing file code Copydb2lan (factory). bat

Code starts at *************************

@echo off

Color 0e

Cls


Title Copy DB to The Mirror host (by [email protected]) ...


Set Desthost=\\172.32.4.252\sfisbackup

Set Lc=y:

Set Work_path=d:\sfisbackup

Set Stg_name=d:\sfisbackup\stg_123456.txt


Set pskip=4


NET use%lc%%desthost% "[email protected]"/user:administrator


FOR/R%work_path%%%i in (Sfis*.bak) do echo%%i >>%stg_name%

for/f "skip=%pskip%"%%i in (%stg_name%) do set cpfilename=%%i


Copy%cpfilename%%lc%/y


If exist%stg_name% del/q%stg_name%


NET use%lc%/del


At the end of the code *************************


2. Batch processing file code Cleanolddb.bat

At the end of the code *************************

@echo off

Lolor @e

Cls

Title Delete files N days ago (by [email protected]) ...


Set Work_path=d:\sfisbackup

Set Stg_name=d:\sfisbackup\stg_123456.txt

Set dd=10

forfiles/p "%work_path%"/s/m */d-%dd%/C "cmd/c del/q @path"

Pause

At the end of the code *************************

This article is from the "Imagine the Sky" blog, please be sure to keep this source http://kinwar.blog.51cto.com/3723399/1421526

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.