Solved

SQL Server 2012 Backup Script

Posted on 2014-01-19
3
487 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
[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 Comments
 
LVL 16

Assisted Solution

by:Surendra Nath
Surendra Nath earned 100 total points
ID: 39793061
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
ID: 39793072
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
ID: 39799369
>>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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

724 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