Solved

SQL Server 2012 Backup Script

Posted on 2014-01-19
3
478 Views
Last Modified: 2014-02-04
Hello,

How to construct a script which configures SQL Server to make backup to a database every hour and if the backup fails send an email to the admin.


Thanks.
0
Comment
Question by:TabEst
3 Comments
 
LVL 16

Assisted Solution

by:Surendra Nath
Surendra Nath earned 100 total points
Comment Utility
every hour are you looking for a full backup or differential backup...

I am think you want to make a full backup every hour (although this will not be the case with the DBA's)

backup database <YourDatabase> to disk = <location>

Open in new window


Now, place this code in SQL agent job and schedule this job for every hour

While creating the job, also select what happens when the error....
0
 
LVL 3

Assisted Solution

by:Conner Turner
Conner Turner earned 200 total points
Comment Utility
Hello There,

If you have access to SSMS then the following steps will create a backup every hour:

1. Create the New Job


From within SSMS Navigate to SQL Server agent > Right Click Jobs Folder > New Job

From within their a new dialog window should popup.

2. Job Settings



You can configure the following:

Step Name = A memorisable name to call the job
Type = T-SQL
Run As = Leave Blank
Database = Select the database to run command on

Command:
BACKUP DATABASE
TO DISK = '(path of backup directory)'
   WITH FORMAT,
      MEDIANAME = 'Z_SQLServerBackups',
      NAME = 'Full Backup of Database';
GO

Open in new window

Replace the path directory with the directory you would like to store it in

Then click ok

3. Recurring the Command


You should be brought to another dialog this dialog you can setup to what and when you want your database to backup

Then click ok and you have successfully made an hourly backup of your server !

HTH,
Conner
0
 
LVL 13

Accepted Solution

by:
geek_vj earned 200 total points
Comment Utility
>>How to construct a script which configures SQL Server to make backup to a database every hour and if the backup fails send an email to the admin.

Create a job from Management Studio and use the below script for taking backup

use master
go
backup database <Yourdbname> to disk = '<File location>' with stats = 10
go

Schedule this job to run daily - every 1 hour

For alerting on the job failure, you need to configure DB mail and ensure that you select the required fieds (email/page etc) under notifications in Job properties

DB mail configuration can be done using the steps in the below link (screenshots included):

http://blog.sqlauthority.com/2008/08/23/sql-server-2008-configure-database-mail-send-email-from-sql-database/

Hope this helps!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now