Solved

How to use Powershell to backup SQL Database

Posted on 2014-09-03
6
393 Views
Last Modified: 2014-09-16
Hi, I have been referred to this article to use Powershell to backup my SQL database -

http://msdn.microsoft.com/en-us/library/ms187510.aspx

Notice the code is as follows
Backup-SqlDatabase -ServerInstance [b]Computer\Instance[/b] -Database [b]MyDB[/b] -BackupAction Database

Open in new window


Well I do not quite understand how to customise it for my server/database, so say my server is 'servername' and my instance is 'SQLEXPRESS' and my DB is 'database'.

I have put in bold what I think I need to change - is this correct?
0
Comment
Question by:fuzzyfreak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40301560
Backup-SqlDatabase -ServerInstance servername\SQLEXPRESS  -Database MyDB -BackupAction Database
0
 
LVL 29

Expert Comment

by:becraig
ID: 40309377
Do you have any additional questions on this issue ?
0
 
LVL 4

Author Comment

by:fuzzyfreak
ID: 40317023
Thank you very much, this works.
Yes, I'd like to specify a path for the backup to go to,
I would also like to schedule this in Task Scheduler, how do I put it in a script?

Thanks
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40318474
Yes, I'd like to specify a path for the backup to go t
o,
(Specify backupfile)
import-module sqlps
Backup-SqlDatabase -ServerInstance servername\SQLEXPRESS  -Database MyDB -BackupFile C:\folder\file.bak -BackupAction Database 

Open in new window



I would also like to schedule this in Task Scheduler, how do I put it in a script?
Here is a nice walkthrough on setting up a scheduled task.

http://clickhome.freshdesk.com/support/articles/107608-how-to-setup-windows-auto-scheduler-task-to-restart-clickhome-windows

Simply save your script and ensure you load the required module as a part of your script.
your script from the scheduled task should be called this way:
powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File <script_name.ps1>
0
 
LVL 4

Author Comment

by:fuzzyfreak
ID: 40325605
Thanks, this is all up and running now.
0
 
LVL 4

Author Closing Comment

by:fuzzyfreak
ID: 40325606
Excellent and comprehensive reply.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question