Perform SQL Server database backup via Windows Batch command _mssql

Source: Internet
Author: User
Tags datetime getdate microsoft sql server

Create a Mybackup.bat, enter the following to run the script directly, you can start to automatically back up the database or the script to join 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. txt
date/t >> E:\DataBaseBAK\ Task Schedule completion of the
. txt time/t >> E:\DataBaseBAK\ Task Schedule completion of a
. txt isql.exe-s 127.0.0.1-u SA- P sa-i mybackup.sql
Echo Database backup completion >> E:\DataBaseBAK\ task schedule complete records. txt
date/t >> E:\DataBaseBAK\ Task scheduled to complete the
. txt time/t >> E:\DataBaseBAK\ task scheduled completion
. txt echo.
Echo.
Echo. Database backup completes
echo.
Echo.
REM Pause

In the same folder, create a SQL script: Mybackup.sql
The contents are as follows:
----------------------------------------------------------------------------

DECLARE @name varchar ()
DECLARE @datetime char (a)
DECLARE @path varchar (255)
DECLARE @bakfile varchar ( 255)
Set @name = ' V5hqs '
set @datetime =convert (char (8), GETDATE (), 112) + REPLACE (CONVERT (char (8), GETDATE (), 108), ': ', '
set @path = ' E:\DataBaseBAK '
set @bakfile = @path + ' + @name + ' _ ' + ' bak_ ' + @datetime + '. BAK '
backup database @name to disk= @bakfile and name= @name
go

The above is a small part of the introduction to the Windows Batch command to perform SQL Server database backup related content, I hope that the above help!

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.