SHARE
TWEET

Untitled

a guest Dec 11th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DECLARE @name VARCHAR(50) -- database name  
  2. DECLARE @path VARCHAR(256) -- path for backup files  
  3. DECLARE @fileName VARCHAR(256) -- filename for backup  
  4. DECLARE @fileDate VARCHAR(20) -- used for file name
  5.  
  6. -- specify database backup directory
  7. SET @path = 'C:\Game-Backup-20191211\'  
  8.  
  9. -- specify filename format
  10. SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)
  11.  
  12. DECLARE db_cursor CURSOR READ_ONLY FOR  
  13. SELECT name
  14. FROM master.sys.databases
  15. WHERE name NOT IN ('master','model','msdb','tempdb')  -- exclude these databases
  16. AND state = 0 -- database is online
  17. AND is_in_standby = 0 -- database is not read only for log shipping
  18.  
  19. OPEN db_cursor  
  20. FETCH NEXT FROM db_cursor INTO @name  
  21.  
  22. WHILE @@FETCH_STATUS = 0  
  23. BEGIN  
  24.    SET @fileName = @path + @name + '_' + @fileDate + '.BAK'  
  25.    BACKUP DATABASE @name TO DISK = @fileName  
  26.  
  27.    FETCH NEXT FROM db_cursor INTO @name  
  28. END  
  29.  
  30.  
  31. CLOSE db_cursor  
  32. DEALLOCATE db_cursor
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top