SQL SERVER 備份命令
ref: 網路白日夢:SQL Server自動備份通用語法SQL代碼
- declare @datestr nvarchar(255), @dbname nvarchar(255), @path nvarchar(255), @cmd_backup_log nvarchar(255), @cmd_backup_data nvarchar(255)
- select @datestr = convert(nvarchar, getdate(), 112)
- select @path = 'c:\sqlbackup\' declare db_cur cursor for
- select name from master..sysdatabases where dbid > 4
- open db_cur
- fetch next from db_cur into @dbname
- WHILE @@FETCH_STATUS = 0
- BEGIN
- select @cmd_backup_log = 'backup log '+@dbname+' to disk='''+@path + @dbname + @datestr + '_log.bak'''
- select @cmd_backup_data = 'backup database '+@dbname+' to disk='''+@path + @dbname + @datestr + '_data.bak'''
- --print @cmd_backup_log
- --print @cmd_backup_data
- exec sp_executesql @cmd_backup_log
- exec sp_executesql @cmd_backup_data
- fetch next from db_cur into @dbname
- END
- close db_cur
- deallocate db_cur
sqlcmd -i XXXXX.sql
0 意見:
張貼留言