I am using SQL server 2012 right, and I would like to know how can I take back up of all MS SQL server databases using a single script? or you can explain me a simple method.
You can take a look on this article's 3rd option to take back up of full database using SQL server
Another solution to take back up of all databases using SQL server is
Create PROCEDURE [dbo].[AllDataBasesBackUp] AS BEGIN SET NOCOUNT ON; 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 = 'D:\All_databases_Backup\' SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),104) DECLARE db_cursor CURSOR FOR SELECT name FROM MASTER.dbo.sysdatabases WHERE name NOT IN ('master','model','msdb','tempdb','ReportServer','ReportServerTempDB') 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 END
EXEC [AllDataBasesBackUp]?
Now, you can check D:\All_databases_Backup\ (Location, all database back up file is created there using above stroed procedures
You can also use powershell to take backup of all sql server database
Get-SqlDatabase -ServerInstance localhost |
Where { $_.Name -ne 'tempdb' } | foreach{$_ |
Backup-SqlDatabase -CompressionOption On -BackupFile "$($_.NAME)_db_$(Get-Date -UFormat %Y%m%d%H%M).bak"};
Source: How to back up SQL Server database ? (Various Ways explained)
Upvote if it helps, thanks.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly