Is there a way to attach a SQL Server mdf/ldf files such that the database is in Restoring mode and we can restore log backups on top of it.
I have a hardware array snapshot (crash consistent) that contains the mdf/ldf files. I need to attach these files to another SQL Server instance and then do log restores for a point in time recovery(using stopat)
The CREATE DATABASE .. FOR ATTACH command brings the database online. Log restore cannot be done on an online database.
Is there a way to accomplish this?
No. Unfortunately. Vote for the feature here:
DCR - Attach database with NORECOVERY
Related
How do I export a SQL Server 2000/2005 database to MDF/LDF files? I do not have access to detach the database nor do I have access to login to the database server to copy the files directly.
Can you run commands against the database from a query window? Do you know of a network path accessible to both you and the SQL Server instance? If so then you can issue the following query (instead of trying to coax some backup through the UI):
BACKUP DATABASE dbname TO DISK = '\\some_network_path_you\have_access_to\db.bak'
WITH COPY_ONLY, INIT;
COPY_ONLY is important so that you don't disrupt the production server's log chain.
Then you can copy that file and run RESTORE DATABASE wherever you like.
You don't want to somehow get access to the MDF / LDF files. For one, in order to copy those, you need to shut down the source SQL Server and detach them. This can lead to many bad things, but most importantly downtime on the production server, and the risk that if something should go wrong, you now have ZERO copies of your database.
Then you request that your dba provide the data to you.
I have a database in SQL Server 2008, which I want to copy to another computer.
How do I make such a copy?
Once this is done, what should I do at the other computer to build the database once again from my copy?
Using SQL Server Management Studio, here are the steps:
1.Right-click the database and select Tasks | Backup
2.Make sure that the Backup type is Full
3.Click Add and specify the location and backup name
4.Copy the created backup file to another computer
5.In SQL Server Management Studio on another computer, right-click the SQL Server instance and select Restore Database
6.Select Device and click the elipsis button to navigate to the copied backup file
Simple Answer: Back it up, then restore it on the other computer.
Have a look here: http://technet.microsoft.com/en-us/library/cc966495.aspx
There's a lot of stuff there, but essentially, right click on the database, Tasks > Backup. Fill in the options to perform a full backup to somewhere.
Once it has created the backup (one big file, by convention with a BAK extension), on the second computer, right click the Databases folder, Restore Database and follow the prompts.
You can do it as well in SQL if you wish:
Backup: http://msdn.microsoft.com/en-us/library/ms186865.aspx
Restore: http://msdn.microsoft.com/en-us/library/ms186858.aspx
There might be times when it's better to detach and move, but this approach always feels a bit safer!
This will copy both structure and the data in the database.
Use TSQL backup and restore. This should help http://www.sqlmag.com/article/tsql3/use-t-sql-to-back-up-and-restore-sql-server-user-databases
One of the easiest ways to do this is back up and restore.
http://msdn.microsoft.com/en-us/library/ms187048.aspx
Another option you have is detaching your database from SQL Server, copying the MDF and LDF files to the target machine, and re-attaching there. Note, if you want to keep a copy of the database on the original server, you will also need to attach there too.
http://msdn.microsoft.com/en-us/library/ms190794.aspx
You can dump the content of your database and restore it on another machine. The same mechanism can be used also for backup purposes. Check the backup&restore functionality of MS SQL.
I have been reading a LOT of google posts and StackOverflow questions about how to restore a database in SQL Server from a .bak file.
But none of them states how to just READ the tables in the database-backup.
(None that I could find anyway?)
I just want to check out some old information which now has been deleted, without actually restoring the full database.
Is this possible?
.
EDIT:
I just wanted to post my T-SQL solution to the problem, so others may use it and I can go back and look it up ;)
First I created a new database called backup_lookup and took it offline.
After this I could restore my old database mydb to the new one, without ever touching my original.
USE master
GO
RESTORE DATABASE backup_lookup
FROM DISK = 'D:\backup\mydb.bak'
WITH REPLACE,
MOVE 'mydb' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\backup_lookup.mdf',
MOVE 'mydb_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\backup_lookup_log.ldf'
GO
I hope this helps :)
From SQL Server 2008 SSMS (SQL Server Management Studio), simply:
Connect to your database instance (for example, "localhost\sqlexpress")
Either:
a) Select the database you want to restore to; or, alternatively
b) Just create a new, empty database to restore to.
Right-click, Tasks, Restore, Database
Device, [...], Add, Browse to your .bak file
Select the backup.
Choose "overwrite=Y" under options.
Restore the database
It should say "100% complete", and your database should be on-line.
PS: Again, I emphasize: you can easily do this on a "scratch database" - you do not need to overwrite your current database. But you do need to RESTORE.
PPS: You can also accomplish the same thing with T-SQL commands, if you wished to script it.
The only workable solution is to restore the .bak file. The contents and the structure of those files are not documented and therefore, there's really no way (other than an awful hack) to get this to work - definitely not worth your time and the effort!
The only tool I'm aware of that can make sense of .bak files without restoring them is Red-Gate SQL Compare Professional (and the accompanying SQL Data Compare) which allow you to compare your database structure against the contents of a .bak file. Red-Gate tools are absolutely marvelous - highly recommended and well worth every penny they cost!
And I just checked their web site - it does seem that you can indeed restore a single table from out of a .bak file with SQL Compare Pro ! :-)
There is no standard way to do this. You need to use 3rd party tools such as ApexSQL Restore or SQL Virtual Restore. These tools don’t really read the backup file directly. They get SQL Server to “think” of backup files as if these were live databases.
Just to add my TSQL-scripted solution:
First of all; add a new database named backup_lookup.
Then just run this script, inserting your own databases' root path and backup filepath
USE [master]
GO
RESTORE DATABASE backup_lookup
FROM DISK = 'C:\backup.bak'
WITH REPLACE,
MOVE 'Old Database Name' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\backup_lookup.mdf',
MOVE 'Old Database Name_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\backup_lookup_log.ldf'
GO
It doesn't seem possible with SQL Server 2008 alone. You're going to need a third-party tool's help.
It will help you make your .bak act like a live database:
http://www.red-gate.com/products/dba/sql-virtual-restore/
I'm trying to backup a live database to my computer and I can't find the option to do it. I'm connecting to it using Microsoft SQL Server Management Studio 2008 R2. I'm a MySQL monkey, so I'm used to being able to backup to .sql files and move them around.
Anyone have any idea how I can create a file backup of the database? I've found the backup option which only backs up on the server, or the export, which seems to only allow a single table, or code an SQL query, which I'm not too sure on, short of putting in something like SHOW TABLES;
Anyone have any ideas? I'm limited to readonly access for various reasons, nothing bad, promise!
You will only be able to backup the database to a location the service account for SQL has access to. If you have access to a central share on the server/network that you can access and the service can, you might backup to that location and then browse from your computer to pull it down.
If you are just wanting the database structure you could script the database out to a file. This would let you save it locally. If you also want the data though doing a full backup is the quickest way I know of.
EDIT
I would use the T-SQL BACKUP comand and include WITH COPY_ONLY to backup the database, since you stated this is a "live" database. If a scheduled job is performing backups against the database and you break in to do an additional one you will effect the backup recovery chain of the database. Using the COPY_ONLY will allow you to get a backup of the database without requiring it in the event of a recovery need.
You can also create sql dumps with Management Studio.
Right-click the database and select Tasks - Generate Scripts. This will open a wizard that allows you to select what the dump should include (e.g. tables, indices, views, ...).
Make sure you set "Script Data" to true if you want your dump to include inserts.
You can enter a valid UNC path in the Backup option.
I have a demo site where anyone can login and test a management interface.
Every hour I would like to flush all the data in the SQL 2008 Database and restore it from the original.
Red Gate Software has some awesome tools for this, however they are beyond my budget right now.
Could I simply make a backup copy of the database's data file, then have a c# console app that deletes it and copies over the original. Then I can have a windows schedule task to run the .exe every hour.
It's simple and free... would this work?
I'm using SQL Server 2008 R2 Web edition
I understand that Red Gate Software is technically better because I can set it to analyze the db and only update the records that were altered, and the approach I have above is like a "sledge hammer".
It's simple and free... would this work?
Yes, you could do it like that, just remember to put the DB in single user mode before restoring it otherwise your restore will fail
example script
USE master
GO
ALTER DATABASE YourDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE YourDB FROM DISK=N'D:\Backup\Pristine.BAK' WITH FILE = 1,
NOUNLOAD, REPLACE, STATS = 10
GO
ALTER DATABASE YourDB SET MULTI_USER
GO
This can be scripted using SQL and scheduled as a job on the server to execute once an hour. Since you have a backup copy, I assume, that is pristine, then all you need to do is take the database offline, restore from the backup, bring the database back online. All of this can be scripted. Do you need the scripts?
You could also detach the database, overwrite the data and log files from your template (previously detached) and then re-attach.