|
(1)创建存储过程
use database_name
go
create proc [dbo].[BackupDatabase]
as
begin
--数据库备份脚本
--申明变量参数(‘备份全路径’、‘备份路径’、‘文件件名’)
declare @backup_fullpath nvarchar(255),
@backup_path nvarchar(50),
@str_date nvarchar(50)
--设置路径
set @backup_path = N'F:\DataBackup\'
--设置文件名
-- make date string in backup filename
set @str_date = convert(varchar(50), getdate(), 121)
set @str_date = replace(@str_date, N'-', N'')
set @str_date = replace(@str_date, N':', N'')
set @str_date = replace(@str_date, N'.', N'')
set @str_date = replace(@str_date, N' ', N'')
--备份数据库
-- backup DMS database
set @backup_fullpath = @backup_path + N'DMS-' + @str_date + N'.full.bak'
backup database DMS to disk = @backup_fullpath
end
GO
(2)创建bat执行存储过程
sqlcmd -S 127.0.0.1 -U sa -P Sunlight123 -Q "use DMS; exec CreateReturnVisitTask"
|
|