I'm trying to rebuild a web server in a virtual pc. Installed required software and Microsoft SQL Server 2005. I've had full backups of my databases but it is not possible to restore from those backups in this new installation. By the way, backups are fine, i can restore from them on original server.
In summary, how can I copy whole database to another computer? How can I backup a database and restore is fully on another computer?
Regards,
Burak
PS: The database I'm trying to restore is called "Some_db" and it does not exist on new server. I also tried to create a new one with defaults and restore on it but that gave an error on new db. I don't know any details of the database.
You have 3 Choises:
1) Restore DB as you tried
This failed for you for some reason
Here a tutorial: http://msdn.microsoft.com/en-us/library/ms177429.aspx
2) Detach DB and Atach it to the new server
This is easy: Rightclick on the DB -> Detach.
Rightclick on the new Server -> Attach
Tutorial: http://www.databasedesign-resource.com/moving-the-database.html
3) Create Create-Scripts of the table schema and use insert into statements for the data.
For this, there are a bunch of tools, my favourit is "Redgate SQL Compare".
It creates you all nessecary scripts.
The link: http://www.red-gate.com/products/SQL_Compare/index.htm
Backup file
Copy .bak file to other server
Restore .bak file.
Works every time for me. You have to make sure the new instance of SQL is of a sufficient level to be able to host the database. You also have to recreate the users on the new server and remove and readd them to each database.
The alternative to the backup and restore approach is to detach the db, copy the mdf and ldf files over and then attach them on the new server
Or take offline, copy files, attach database, bring online..
open your current query browser window and run the query .The restore will happen automatically
BACKUP DATABASE AdventureWorks
TO DISK = 'C:\Backup\AdventureWorks.bak'
GO
for more details
This will create a .bak file after that copy the .bak to server.
restore the data base by right click on DataBase .Select restore database .Give the database name and location .And restore it .
Related
Is it possible to copy a database to a new server? I just want to have the database on a new server because I need to make some tests. I didn't have much experience with servers.
Follow this steps :
Run your SSMS
Right click on the database you want to copy
In the Popup menu , go to Taches , then click Offline
Right click on the Database again in the popup menu , Taches -> Detach
Open the folder ..\MSSQL\DATA , copy Yourdb.MDF and YourDB_log.LDF files to the folder of the new Instance.
Now you can Attach both Databases and work on it in both instance.
Another way:
Run Your SSMS
Right click on the Database you want to copy
In the popup menu , Taches -> Copy the database...
Follow the steps on the Wizard
You can select option if you want to keep the database ONLINE when it is being copied.
You can also select option of MOVE or COPY database as well.
When the process is over it will show the success message and database will be copied to another server.
Note:
1- The Copy Database Wizard is not available in the Express edition.
2- The Copy Database Wizard cannot be used to copy or move databases that are/have:
System.
marked for replication.
marked Inaccessible, Loading, Offline, Recovering, Suspect, or in Emergency Mode.
data or log files stored in Microsoft Azure storage.
Also , a database cannot be moved or copied to an earlier version of SQL Server.
Updtae:
If there is no Copy database option , then you can Copy Databases with Backup and Restore.
For more information about it MSDN.
No experience? No problem, backup the database.
Copy it into the target machine.
Restore DB from device >> open the DB backup file.
At this point you have the entire DB without missing any schema objects such as foreign keys.
Finally delete all sql logins that the DB came with and recreate them manually as you test access.
Once you are comfortable with this operation you can go ahead and get more experience using some of the techniques describe above which are recommended if you have a large DB to restore and so on.
How to restore the DB on SQL Server Management Studio
Steps:
1. On “Object Explorer” panel right-click on “Databases” and selected Restore Database
Select “Device” and browse database location.
note: Copy the .bak file locally before restoring.
The DB information will auto-populate the window, you can edit the name of the DB to be restored.
Go to the “Files” page and check the “Relocated all files…” box.
Select existing folder locations for Data and Log files.
HIT OK
I'm sorry that I put this question because I think that is simple but I don't know how to do this think because I am a beginner.
I made a database in sql server management studio 2008 express and now I need to send this database to somebody by email.Where is this database saved?
I need to send it with all tables I created and with the diagram.
Should I generate a script or the database is saved somewhere on my computer.
You can take backup of your database and you will get .bak file as a database backup copy then you can mail anyone and they can just restore it to use it.
In sql server management studio 2008 -> Right click on your database -> Task -> backup
To Restore the database right click on Databases then Restore database give the location
of .bak file.
Is there a facility in Azure to get a copy of the database? Or rather, detach the mdf and get it as file? On occasion I create a database in the cloud, it's up for a while, and then I want to take it down and archive it. My current rutine copies the database using SQL Azure Migration Wizard to a local Express instance, which I then detach and put in a safe place.
EDIT
Interestingly my method of choice throws an exception this time around. So it's far from ideal.
There is another way to do it:
"C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\SqlPackage.exe" /Action:Export /SourceServerName:"tcp:xxxxx.database.windows.net,1433" /SourceDatabaseName:DbName /SourceUser:user /SourcePassword:password /TargetFile:C:\backups\backup.bacpac
From SQL Server Management Studio 2014, connect to the destination database server, right click its Databases node, and click Import Data-tier Application. In the import wizard, select the option to import from Windows Azure.
Using Sql Managment Studio (I use 2012):
Create a new local database.
Right-click in the database -> Tasks -> Import Data
Then you need to select the azure database as the data source and you new local database as data destination.
At this point, you can create a sql server backup or generate a sql script file to get a local copy at that moment.
I created the Enzo Backup for SQL Azure utility for that very reason. You can create a full backup and get your hands on a file that you can restore later to either another SQL Azure database, or a SQL Server database.
Note that SQL Azure will offer a form of backup, cloud-only, in the future. That's another good option. Finally Red-Gate has a product to copy a SQL Azure database to a local SQL Server database, but I am not sure that it gives you a "backup file" per say.
There is a RedGate tool that will backup your database to a local server http://www.red-gate.com/products/dba/sql-azure-backup/
I have found this useful before I do any database upgrades, in case bad stuff happens.
Since I've asked this question, the Azure management console added an option to export the entire database to blob storage. You can keep your backups there, but if you prefer a hardcopy there are many blob explorer tools such as this one.
A good free option I've been using for past few years is Sql Backup and Ftp. It's 100% free if you backup to your local laptop.
External storage requires paid license though.
From the website:
No more multi-step SSMS configuration, just a single form to automate backups: select databases, backup (full, diff, tran log), encrypt, compress, send to a folder, FTP or cloud service:
schedule backups, receive confirmation emails and restore when needed.
Probably this is the lamest question ><
I am developing an ASP.net web app with SQL Server database. When the client asked me to develop the system, he provided a file for the database.
I thought the file was a dumpfile (if you familiar with oracle or mysql, you can replicate database with dumpfile, which is basically bunch of queries inside a text file).
To my horror, plus with my noobity in SQL Server, I found out that it was NOT a dumpfile. The file is rename to .bak which is not really the correct extension for SQL Server. I tried to rename it to .mdf, but no luck.
What should I do? The client is out for vacation on some island and cannot be contacted at the moment?
This is backup file, you need to restore database from backup.
How to: Restore a Database Backup (SQL Server Management Studio)
This is SQL Server backup database file. You can restore it by following these steps: http://msdn.microsoft.com/en-us/library/ms177429.aspx
Alex Aza has the right answer. But remember to create users for the database, before you restore the provided .bak file. A backup file only hold a user id -- the complete user definition is held in the server instance. Thus, it is better to create the users needed before restoring a backup from another server instance which is the case in your project.
I am working on a website that has access data from a database (sql server). It will also be adding, updating deleting records in the database. It seems like there is an MDF file that gets created containing the database schema and all the records I guess? Once development is complete and I want to move this database to a real server then all I need to do is move this MDF file to the real server and that is it? is it that simple? or not really?
Also, I hope the MDF file is not a read-only file and can be updated/modified or is it?
Yes, the MDF data file (and the associated *.LDF transaction log file) contains all the database objects that make up your system.
And yes, you can definitely detach a database (an .MDF/.LDF file pair) from your (dev) SQL Server, copy it onto another "real" Production SQL Server, and re-attach it there, without loss of data or information.
Yes, the MDF file is modifyable - through the SQL Server commands and methods. You should never tamper with the file yourself, directly (flipping bits). Use SQL Server and its official interfaces (T-SQL, ADO.NET etc.) to work with your data.
Yes you can do that. Right click the database and click "detach". Make sure you click the drop connections box and click ok (if you don't do this some errors could occur). You can now move the mdf and ldf files.
However, there is a better way imho. Instead, create a full backup of the database, copy the backup file, and restore from the backup on the new server. Now you have two copies of the database, a development version and a production version.
You will need to take .MDF file as well as .LDF file which will have your logs. You have to take both mdf and ldf files and attach on the real server.