473,395 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Snapshot of databases = Hourly job

MPD
Hi

How can I create a job in sql agent to create a new snapshot every hour?

I have, for eg a T-SQL that does it manually.

create database Snapshotter_snap_20070418_1821 on
( name = Snapshotter, filename =
'c:\temp\Snapshotter_snap_20070418_1821.ss')
as snapshot of Snapshotter

Now, what I do NOT want, is to only have one copy, but rather to do this
every hour or two through out the day - and keep the old copies for some
time. (In that case, a DROP database, and a CREATE database <generic name>
is easy).

Any help appreciated,
M

Apr 18 '07 #1
4 4408
MPD (mp*****@gmail.com) writes:
How can I create a job in sql agent to create a new snapshot every hour?

I have, for eg a T-SQL that does it manually.

create database Snapshotter_snap_20070418_1821 on
( name = Snapshotter, filename =
'c:\temp\Snapshotter_snap_20070418_1821.ss')
as snapshot of Snapshotter

Now, what I do NOT want, is to only have one copy, but rather to do this
every hour or two through out the day - and keep the old copies for some
time. (In that case, a DROP database, and a CREATE database <generic name>
is easy).
Looks likely you could do this with some dynamic SQL:

DECLARE @datestr char(13),
@sql nvarchar(MAX)
SELECT @datestr = convert(char(8), getdate(), 112) + '_' +
convert(char(5), getdate(), 108)
SELECT @datestr = replace (@datestr, ':', '')
SELECT @sql =
'create database Snapshotter_snap_ ' + @datestr + ' on
' ( name = Snapshotter, filename =
''c:\temp\Snapshotter_snap_' + @datestr + '.ss'')
as snapshot of Snapshotter'
EXEC(@sql)


--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 18 '07 #2
MPD
Thanks Erland - worked a dream!

I am working through my 70-431 course, and this was mentioned a number of
times. However, I see no point in doing this.

Consider:
I take snapshots hourly, on the hour.
At 1.10pm, someone admits a major blunder, and tells me they dropped a table
at 11am.
I can now restore the 11am snapshot to a new DB and recover the table.
But, to do this, I need to delete the other snapshots.
This means that any other "blunders" cannot be recovered from snapshots.

Surely this is not an effective solution?
In fact, the only real use for snapshots I can see, is
To make a snapshot of a mirrored / log shipped database so it can be used as
a static report DB, OR
To make a quick "backup" where a DBA needs to do some work quick and might
risk dataloss through an error.

M

"MPD" <mp*****@gmail.comwrote in message
news:11***************@vasbyt.isdsl.net...
Hi

How can I create a job in sql agent to create a new snapshot every hour?

I have, for eg a T-SQL that does it manually.

create database Snapshotter_snap_20070418_1821 on
( name = Snapshotter, filename =
'c:\temp\Snapshotter_snap_20070418_1821.ss')
as snapshot of Snapshotter

Now, what I do NOT want, is to only have one copy, but rather to do this
every hour or two through out the day - and keep the old copies for some
time. (In that case, a DROP database, and a CREATE database <generic name>
is easy).

Any help appreciated,
M



Apr 19 '07 #3
MPD (mp*****@gmail.com) writes:
I am working through my 70-431 course, and this was mentioned a number of
times. However, I see no point in doing this.

Consider:
I take snapshots hourly, on the hour. At 1.10pm, someone admits a major
blunder, and tells me they dropped a table at 11am.
I can now restore the 11am snapshot to a new DB and recover the table.
But, to do this, I need to delete the other snapshots.
I haven't used snapshots much at all, but I did a quick read in Books
Online, and I don't think this is right.

What is correct is that if you decided to revert a snapshot, then all
other snapshots must be deleted. But in that case, at least newer
snapshots would be completely pointless.

But in the case of the big blunder, all you need to do is recreate the
table, possibly scripting it from the snapshot before the blunder, and the
insert the data over. Only the data after that shapshot was taken would
be lost.

The advantage with using snapshots for this sort of recovery is that
you can repair the blunder very quickly, as all data are online. There are
two important drawbacks:
1) Not up-to-the-point recovery.
2) There is an overhead for maintaining the shapshots. (Intially, the
snapshot is an almost empty sparse file. As pages are modified in
the source, pages are copied to the snapshot file.)

The tested and tried method for up-to-the-point recovery is of course
backing up the database and the transaction log regularly. But for a
huge database, making a full restore and apply logs could take quite
some time. And if you don't have the backup on local storage, the cost
for getting it onto the machine is also considerable.
In fact, the only real use for snapshots I can see, is
To make a snapshot of a mirrored / log shipped database so it can be
used as a static report DB, OR
To make a quick "backup" where a DBA needs to do some work quick and might
risk dataloss through an error.
Yes, I think you got it right there. Snapshot is not a good solution
for recovery in general.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 19 '07 #4
Erland Sommarskog (es****@sommarskog.se) writes:
Yes, I think you got it right there. Snapshot is not a good solution
for recovery in general.
I should make that last point more strongly. While snapshots could be
used to make it possible to quickly repair user errors, snapshots can
*never* be a replacement for BACKUP. Keep in mind that a snapshot shares
pages with the source database, so if the source database goes up in
flames because of hardware problems, the snapshot burns with it.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bernhard Krautschneider | last post by:
hello group, is it possible to do a storage snapshot of a running ms-sql database without losing transactions? What tasks must be done before such a snapshot. thanks in advance, Bernhard
0
by: deepakjgupta | last post by:
Hello all, We are using SQL Server 2000 (Enterprise Edition) Merge Replication to synchronize databases between a main server database and about 200 local MSDE databases. Recently, we upgraded...
8
by: Jean-Marc Blaise | last post by:
Dear all, It seems there is a problem with some snapshot table functions, if you try to divide by some element that is unset or equal to 0. This generates a trap file with the db2fmp.exe...
4
by: Civilian_Target | last post by:
Is there any way in DB2 to automate the taking of a snapshot, for example, a function that will cause a db2 snapshot to be taken every 5 minutes and written to a uniquely named file? Am I better...
2
by: Chuck Grimsby | last post by:
For all of you who were looking for the free Snapshot viewer and were wondering what the heck happened to it.... It's back! ...
5
by: tom | last post by:
Hey All- I've exported a report to Access's "snapshot" format and want to put it on a website for users to view. However, when I click on the link to the snapshot file, I notice that my browser...
0
by: sara | last post by:
I am new to Access and especially to forms and code. I have a form in each of 5 databases that allows the user to enter the date and then automatically run all the reports for that date. The user...
7
by: Compliance | last post by:
Apologies for the simplicity of the question, but it reflects my capabilities! I have the following sample fields coming from different tables: Location TimeDate (timestamp) Data I need to...
8
by: grant | last post by:
Hi I've copied Stephens code into my db, and can get it to work, but only on "plain Jane" reports with no images. Most of my reports has an unbound image obluect in them that I set to an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.