Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)?

share|improve this question
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

4 Answers 4

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

SQL Server 2008 powershell has a cmdlet invoke-sqlcmd.

share|improve this answer

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.

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

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

See this example.

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

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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