Solved

SQL Server 2012 Backup Script

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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 setup several different housekeeping processes for a SQL Server.

733 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