首页 > 代码库 > 自动备份sqlexpress 数据库脚本
自动备份sqlexpress 数据库脚本
Create PROCEDURE [dbo].[usp_BackupDatabase] @databaseName sysname,@backupPath nvarchar(255), @backupType CHAR(1) AS BEGIN SET NOCOUNT ON; DECLARE @sqlCommand NVARCHAR(1000) DECLARE @dateTime NVARCHAR(20) SELECT @dateTime = REPLACE(CONVERT(VARCHAR, GETDATE(),111),‘/‘,‘‘) + REPLACE(CONVERT(VARCHAR, GETDATE(),108),‘:‘,‘‘) IF @backupType = ‘F‘ SET @sqlCommand = ‘BACKUP DATABASE [‘ + @databaseName + ‘] TO DISK = ‘‘‘+@backupPath+‘\‘ + @databaseName + ‘_Full_‘ + @dateTime + ‘.BAK‘‘‘ IF @backupType = ‘D‘ SET @sqlCommand = ‘BACKUP DATABASE [‘ + @databaseName + ‘[ TO DISK = ‘‘‘+@backupPath+‘\‘+ @databaseName + ‘_Diff_‘ + @dateTime + ‘.BAK‘‘ WITH DIFFERENTIAL‘ IF @backupType = ‘L‘ SET @sqlCommand = ‘BACKUP LOG [‘ + @databaseName + ‘[ TO DISK = ‘‘‘+@backupPath+‘\‘ + @databaseName + ‘_Log_‘ + @dateTime + ‘.TRN‘‘‘ EXECUTE sp_executesql @sqlCommand END
Backup.sql
批处理文件
SQLCMD.EXE -S .\SQLEXPRESS -E -i Backup.sql@echo offfor /f "tokens=2 delims==" %%a in (‘wmic path win32_operatingsystem get LocalDateTime /value‘) do ( set t=%%a ) set Today=%t:~0,4%%t:~4,2%%t:~6,2%set DBName=CRM_Testrar a %DBName%_db_%Today%.rar %DBName%_Full_%Today%*.BAKping 127.0.0.1 -n 5del %DBName%_Full_%Today%*.BAK
自动备份sqlexpress 数据库脚本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。