SQL Server database backup: Execute with Windows Batch command

Source: Internet
Author: User

Perform a SQL Server database backup with Windows batch commands

Set up Mybackup.bat, enter the following to run the script directly, you can start to automatically back up the database or add the script to the Windows task plan to execute.

----------------------------------------------------------------------------
@echo off

Set path=%path%; C:Program Files\Microsoft SQL Server\80\Tools\Binn

Echo Database backup start >> E:\DataBaseBAK\ task schedule completion record. txt
date/t >> E:\DataBaseBAK\ Task schedule completion record. txt
time/t >> E:\DataBaseBAK\ Task schedule completion record. txt

Isql.exe-s 127.0.0.1-u sa-p sa-i mybackup.sql

echo Database backup complete >> E:\DataBaseBAK\ task schedule completion record. txt
date/t >> E:\DataBaseBAK\ Task schedule completion record. txt
time/t >> E:\DataBaseBAK\ Task schedule completion record. txt

Echo.
Echo.
Echo. Database backup Complete
Echo.
Echo.

REM Pause
----------------------------------------------------------------------------

In the same folder, create a SQL script: Mybackup.sql
The contents are as follows:
----------------------------------------------------------------------------
DECLARE @name varchar (50)
DECLARE @datetime Char (14)
DECLARE @path varchar (255)
DECLARE @bakfile varchar (255)

Set @name = ' V5hqs '
Set @datetime =convert (char (8), GETDATE (), () + REPLACE (CONVERT (char (8), GETDATE (), 108), ': ', ')
Set @path = ' E:\DataBaseBAK '
Set @[email protected]+ ' [email protected]+ ' _ ' + ' bak_ ' [email protected]+ '. BAK '

Backup Database @name to [e-mail protected] with [email protected]

Go
----------------------------------------------------------------------------

SQL Server database backup: Execute with Windows Batch command

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.