473,796 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_sna p_20070418_1821 on
( name = Snapshotter, filename =
'c:\temp\Snapsh otter_snap_2007 0418_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 4427
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_sna p_20070418_1821 on
( name = Snapshotter, filename =
'c:\temp\Snapsh otter_snap_2007 0418_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_sna p_ ' + @datestr + ' on
' ( name = Snapshotter, filename =
''c:\temp\Snaps hotter_snap_' + @datestr + '.ss'')
as snapshot of Snapshotter'
EXEC(@sql)


--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.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_sna p_20070418_1821 on
( name = Snapshotter, filename =
'c:\temp\Snapsh otter_snap_2007 0418_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****@sommarsk og.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****@sommars kog.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****@sommarsk og.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
948
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
1547
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 our QA server from build 8.00.928 to SP4. Since then, the Snapshot Agent fails to create files on our File Server. We have checked and double-checked all permissions, shares, etc. But we keep getting the following error randomly on any step:
8
2993
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 process, that keeps going on, until your disk is full. I'm on W2K, DB2 UDB 8.1 FP4. Test case: db2start
4
3230
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 off attempting to do this with my poor knowledge of dos batch files? I'm running UDB 8.2 on Windows 2000. Thanks.
2
3781
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! http://www.microsoft.com/downloads/details.aspx?familyid=B73DF33F-6D74-423D-8274-8B7E6313EDFB&displaylang=en or http://www.microsoft.com/accessdev/articles/snapshot.htm?&gssnb=1 (Watch the word wrap on the URLs!)
5
3486
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 (IE6) attempts to open it as if it were a regular html page, thereby displaying a bunch of gobbledygook. Any ideas on what has to be tweeked (in the link/on the website or server) to make the browser know it should either (a) try to launch...
0
1174
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 chooses daily, weeekly, or quarterly. This all works fine. The reports are presented in Print Preview mode so they can quickly review and then snap and email. I don't want to import all the objects, as then the objects (queries and reports)...
7
9806
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 return the average of Data per Location per HOUR.
8
5487
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 external image file using on_open code I've searched through this group and there are a few comments about snapshots not working with embedded images, and my testing seems to
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10174
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.