Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


11 Tips to Backup databases with SMO, VB, C# Powershell, Command lines


11 Tips to Backup databases with SMO, VB, C# Powershell, Command lines

Author
Message
calbimonte.daniel
calbimonte.daniel
SSC Veteran
SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)

Group: General Forum Members
Points: 200 Visits: 416
Comments posted to this topic are about the item 11 Tips to Backup databases with SMO, VB, C# Powershell, Command lines
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)

Group: General Forum Members
Points: 51319 Visits: 40305
Nice summary of backup methods, Daniel. I also like that you took the time to demonstrate how you can schedule backups for SQL Express. Well done.

As an off subject sidebar, let's hope that SMO doesn't go the way of the Dodo bird as did DMO.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Aaron Nelson
Aaron Nelson
SSC Veteran
SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)

Group: General Forum Members
Points: 255 Visits: 172
Nice write-up Daniel. :-)

For the PowerShell portion, I would highly recommend using the Backup-SqlDatabase cmdlet that came with SQL Server 2012. It's much simpler to just backup your databases with a simple:

dir SQLSERVER:\SQL\LocalHost\Default\DATABASES\ | Backup-SqlDatabase

Cheers!

@SQLvariantI have a PowerShell script for you.
calbimonte.daniel
calbimonte.daniel
SSC Veteran
SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)

Group: General Forum Members
Points: 200 Visits: 416
Thanks a lot for the feedback is pretty cool to write in sqlservercentral ! Cool
Michael Meierruth
Michael Meierruth
Say Hey Kid
Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)

Group: General Forum Members
Points: 713 Visits: 2510
I do backups frequently from my computer which is different from the server on which the database resides. But I want the backup to end up on my computer. This requires making use of a special kind of net share. The BAT file below shows what I mean.


set backupdir=C:\Backup
set database=MYDATABASE
set sqlserver=SQLSERVER
set sqluser=SQLUSER
set sqlpassword=SQLPASSWORD

echo backup database %database% to disk='\\%computername%\backup\%database%.bak' with stats=1 > backup.sql
erase %backupdir%\%database%.bak
net share backup /d
net share backup=%backupdir%
sqlcmd -S %sqlserver% -U %sqluser% -P %sqlpassword% -d %database% -i backup.sql
net share backup /d
erase backup.sql



On occasion, I have to use my computer's IP address. A non-server's IP address can change (for various reasons) and getting the IP addess is just a little tricky - but not impossible.
quackhandle1975
quackhandle1975
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2835 Visits: 1234
Many ways to skin a cat! Empowering to know as many ways as possible to perform a set task or tasks then see which is the best fit.

Good article.

qh

Who looks outside, dreams; who looks inside, awakes. – Carl Jung.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search