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
Solved

SQL Server 2012 Backup Script

Posted on 2014-01-19
3
482 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
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

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.

Question has a verified solution.

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

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

828 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