?
Solved

SQL Server 2012 Backup Script

Posted on 2014-01-19
3
Medium Priority
?
489 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 300 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 600 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 600 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

777 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