-- Backup Script
DECLARE @name VARCHAR(50) -- database name
DECLARE @path VARCHAR(256) -- path for backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name
SET @path = 'C:\Backup\'
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) + '_' + REPLACE(CONVERT(VARCHAR(20),GETDATE(),108),':','')
DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb')
AND DATABASEPROPERTYEX(name, 'Recovery') IN ('FULL','BULK_LOGGED')
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.TRN'
BACKUP LOG @name TO DISK = @fileName
FETCH NEXT FROM db_cursor INTO @name
END
CLOSE db_cursor
DEALLOCATE db_cursor
'Database > SQL Server' 카테고리의 다른 글
SQL Server 쿼리가 느려졌을 때 (0) | 2021.01.20 |
---|---|
SQL Server 백업/복원 예상 완료시간 확인하기 (0) | 2021.01.20 |
free SSMS add-in for effective database performance tracing (0) | 2021.01.20 |
Tempdb 최적화 – tempdb 데이터파일 제거하기 (0) | 2020.10.27 |
SQL Server 임시 테이블 : 방법 레시피 (0) | 2020.10.23 |