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