-- 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' 카테고리의 다른 글

DB 주의대상  (0) 2020.08.28
In-Memory OLTP  (0) 2020.08.28
sp_cursorfetch 및 FETCH API_CURSOR에서 사용되는 쿼리는 무엇입니까?  (0) 2020.08.28
index dmv  (0) 2020.08.27
운영 데이터 저장소 Vs 데이터 웨어하우스  (0) 2020.08.27

+ Recent posts