2
I know that to perform a backup in SQL Server just use:
BACKUP DATABASE nome_database
TO DISK = 'endereco\nome__arquivo.bak'
But does anyone know how to backup all Databases together? Each one in a file .bak
?
2
I know that to perform a backup in SQL Server just use:
BACKUP DATABASE nome_database
TO DISK = 'endereco\nome__arquivo.bak'
But does anyone know how to backup all Databases together? Each one in a file .bak
?
2
The script below generates a file per database in the format named_AAADDMM.BAK:
DECLARE @name VARCHAR(50) -- nome do database
DECLARE @path VARCHAR(256) -- caminho em disco para os arquivos
DECLARE @fileName VARCHAR(256) -- nome do arquivo para o backup
DECLARE @fileDate VARCHAR(20) -- data do arquivo, formato AAAADDMM
-- Especifique aqui o diretório onde os arquivos serão salvos.
SET @path = 'C:\Backup\'
-- Aqui você pode mudar o formato da data, caso AAAADDMM não seja do seu gosto.
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)
DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb') -- não faça backup de databases do sistema
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName
FETCH NEXT FROM db_cursor INTO @name
END
CLOSE db_cursor
DEALLOCATE db_cursor
Browser other questions tagged sql sql-server backup
You are not signed in. Login or sign up in order to post.
Douglas in this case requires an instruction for each database. But I recommend using SQL Agent to automatically schedule your backups in a defined routine.
– gmsantos