备份数据库存储过程

时间:2021-08-08 04:47:22
--备份数据库  
CREATE PROC [dbo].[P_DBBACKUP2Path]
(
@dbPath NVARCHAR(200) , --备份文件存放路径,最后带/
@DbName VARCHAR(50) --要备份的数据库名称
)
AS
SELECT @dbPath = @dbPath + @DbName + '_' + CONVERT(VARCHAR(20), GETDATE(), 112)
+ REPLACE(CONVERT(VARCHAR(20), GETDATE(), 108), ':', '') + '.bak'
BACKUP DATABASE @DbName
TO DISK = @dbPath WITH NOINIT , NOUNLOAD , NOSKIP , STATS = 10, NOFORMAT


调用:exec P_DBBACKUP2Path 'x:\dbBackup\', 'dbname'