Collaboration-2-Go


Lösungen und Software-Entwicklung im Collaboration Umfeld, insbesondere Microsoft SharePoint, Microsoft Exchange und Microsoft Office.

Support


Mobil: +49 (152) 53 97 78 79
Mail: service@collaboration-2-go.de
Weitere Kontaktmöglichkeiten: Kontaktseite
Dekoration: Köln



SQL Server - Backup all Databases except System Databases
Created: 19.03.2012
Categories: SQL Server

      Backup all databases except system databases using the
      following script:
      
      declare @dbname sysname
      declare @basepath sysname
      declare @filename sysname
      declare @filedate varchar(8)

      set @basepath = 'c:\Backup\'
      select @filedate = convert(varchar(8), getdate(), 112)

      declare db_cursor  cursor for
      select name from master.dbo.sysdatabases
      where name not in ('tempdb', 'model', 'msdb', 'master')
        open db_cursor
        fetch next from db_cursor into @dbname

        while @@fetch_status = 0
        begin
          set @filename = @basepath + @filedate + '-' + @dbname + '.bak'
          print @filename
          backup database @dbname to disk = @filename with compression
          fetch next from db_cursor into @dbname
        end

        close db_cursor
      deallocate db_cursor

      

      Ensure folder permissions for your service account!
    

Send us a Comment!