Is there a PowerShell command that will execute a backup of all databases on a server?

Alternatively, can I call a stored proc from PowerShell (that will execute the backup)?

link|improve this question

56% accept rate
1  
It will be nice to know how the scripts will perform in this scenario. Any reason why would you prefer this than the native way of backing up a SQL Server DB? – MarlonRibunal May 5 '09 at 21:42
What is the native way of backing up a SQL Server DB? Currently I open up SSMS and run a stored proc that backs up all the DB's into a directory. Then I run a powershell script that moves all of this to a backup location. My intention is to do this in one step from Powershell instead of 2 steps. – Guy May 14 '09 at 3:30
feedback

4 Answers

if you are running sql server 2008 you have powershell bindings. See this link

SQL Server 2008 powershell has a cmdlet invoke-sqlcmd.

link|improve this answer
feedback

It is possible, there are some pre-requisites you need to have installed (namely the Microsoft SQL Server 2005 Management Objects Collection) and theres quite alot of powersehll code needed to do it, however there are a number of articles out there that have it allready done for you. I have used this method successfully in the past.

link|improve this answer
+1 for SMO ..... – Sung May 6 '09 at 14:19
feedback

You can use ADO.NET from PowerShell to execute a stored proc..

See this example.

link|improve this answer
Good alternative. – Sung May 6 '09 at 14:18
feedback

There's functions for PowerShell-based SQL Server database backups included in the CodePlex project SQL Server PowerShell Extensions (SQLPSX). Take look at Invoke-SqlBackup or if you want to implement a full backup and maintenance routine take a look at the SQLMaint module.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.