SQLserver??y???????????
???????????? ???????[ 2016/1/11 13:20:50 ] ?????????????
??????SQLserver????????????????????????????????:
????1.????????????????ж?д?????
????2.??????????????????????????????????????????
-- =============================================
-- Author: <????????>
-- Blog: <http://www.cnblogs.com/OliverQin/>
-- Create date: <2015/01/04>
-- Description: <????????????>
-- =============================================
DECLARE
@FileName VARCHAR(200)??
@CurrentTime VARCHAR(50)??
@DBName VARCHAR(100)??
@SQL VARCHAR(1000)
BEGIN
SET @CurrentTime = CONVERT(CHAR(8)??GETDATE()??112) + CAST(DATEPART(hh?? GETDATE()) AS VARCHAR) + CAST(DATEPART(mi?? GETDATE()) AS VARCHAR)
SET @DBName='test'---------???????????????
SET @FileName = 'C:ackup' + @DBName + '_' + @CurrentTime
SET @SQL = 'BACKUP DATABASE ['+ @DBName +'] TO DISK = ''' + @FileName + '.bak' +
''' WITH NOINIT?? NOUNLOAD?? NAME = N''' + @DBName + '_backup''?? NOSKIP?? STATS = 10?? NOFORMAT'
PRINT @SQL
EXEC(@SQL)
END
--*************************************************************************************************
-- =============================================
-- Author: <????????>
-- Blog: <http://www.cnblogs.com/OliverQin/>
-- Create date: <2015/01/04>
-- Description: <?????????????>
-- =============================================
----------------------------------------------------????????
DECLARE
@FileName VARCHAR(200)??
@CurrentTime VARCHAR(50)??
@DBName VARCHAR(100)??
@SQL VARCHAR(1000)
---------------------------------------------------?????????
SET @CurrentTime = CONVERT(CHAR(8)??GETDATE()??112) + CAST(DATEPART(hh?? GETDATE()) AS VARCHAR) + CAST(DATEPART(mi?? GETDATE()) AS VARCHAR)
---------------------------------------------------?????α?
DECLARE CurDBName CURSOR FOR
SELECT NAME FROM Master..SysDatabases where dbid>4
---------------------------------------------------???α?
OPEN CurDBName
-----------------------------------------------------????α???????????????????????????????????
FETCH NEXT FROM CurDBName INTO @DBName
-----------------------------------------------------???????β??????????????
WHILE @@FETCH_STATUS = 0
BEGIN
--Execute Backup
SET @FileName = 'C:ackup' + @DBName + '_' + @CurrentTime
SET @SQL = 'BACKUP DATABASE ['+ @DBName +'] TO DISK = ''' + @FileName + '.bak' +
''' WITH NOINIT?? NOUNLOAD?? NAME = N''' + @DBName + '_backup''?? NOSKIP?? STATS = 10?? NOFORMAT'
EXEC(@SQL)
--print @SQL
-----------------------------------------------------???????????????
FETCH NEXT FROM CurDBName INTO @DBName
END
---------------------------------------------????α?
CLOSE CurDBName
---------------------------------------------????α?
DEALLOCATE CurDBName
--*************************************************************************************************
DECLARE @SQL VARCHAR(MAX)
SELECT @SQL = COALESCE(@SQL??'') + '
BACKUP DATABASE '+ QUOTENAME(name??'[]')
+ ' TO DISK = ''C:ackup'+ name + '_' + CONVERT(CHAR(8)??GETDATE()??112) + CAST(DATEPART(hh?? GETDATE()) AS VARCHAR) + CAST(DATEPART(mi?? GETDATE()) AS VARCHAR) + '.bak'
+ ''' WITH NOINIT?? NOUNLOAD?? NAME = N''' + name + '_backup''?? NOSKIP?? STATS = 10?? NOFORMAT'
FROM sys.databases WHERE database_id >4 AND name like '%%' AND state =0
PRINT(@SQL)
EXECUTE(@SQL)
????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11