Database install approach - attach MDF or restore BAK - sql-server

I have some pre-built databases that go with a base software release.
Previously we have released the MDFs and a little tool to copy/attach them, and just letting SQL Server rebuild the log file.
Is releasing the backup BAK files and modifying the tool to restore them a better approach?

Personally i like to backup and restore, but that is just personal preference.
Either method works and if you already have a tool to attach the data files, then i'd just go with what you already have.

Related

Restore marklogic database by extracting config from backup

I have been given a copy of a Marklogic v9 database backup which was taken from a Marklogic server running on linux.
I now need to restore the database from the backup dump, onto a windows 2016 server, but the MarkLogic database on the destination windows server doesnt exist.
Is it possible to somehow extract the MarkLogic database configuration from the backup dump , create a database on the destination server then restore over that database? In the backup dump I have a forests directory and all the XML/cfg/label files in the root directory of backup dump.
Or do I need a MarkLogic admin to extract the config of prod database that was backed up, then create an empty database on the destination server ( using the extracted prod database config ), then restore over that? I notice you cant restore without an existing database to restore over.
Or do I alternatively create a dummy database on my destination server of the same name as the prod database, then restore over that? The disk layout obviously will be different.
Any help appreciated.
You cannot restore a backup from a different architecture. If you need to move from Linux to Windows, I'd recommend using MLCP export/import, or maybe even copy. In any case you will need to have a target database up and running. You could export the configuration from one system, and import it in the other using our REST apis, like Configuration Management API or Management API. Our community tool ML-Gradle could be of help with that.
HTH!

Transporting a SQL Server database dump (of data and models) from one environment to another using Microsoft SQL Server Management Studio

Surprisingly, I did not find a concise way on Stackoverflow or elsewhere, so please allow me to ask.
I want transport a complete SQL Server database from one environment to another using the Microsoft SQL Server Management Studio (SSMS).
I guess I need a complete database dump (of model and data) e.g. from the production environment, which I then restore e.g. on the pre-production environment.
I am more the MongoDB guy, and it is straight forward there. But how do I quickly backup, transfer and restore a complete T-SQL database (context) using SSMS? The issue is that I should explain somebody else what to do since I do not have the rights to try it myself.
The official documentation on backup and restore is rather lengthy, but I get the concept, I hope. Except for the copy only backup, maybe. The definition reads:
Copy-only full backups (all recovery models)
A copy-only backup cannot serve as a differential base or differential backup and does not affect the differential base. Restoring a copy-only full backup is the same as restoring any other full backup.
Do I need a copy-only backup for my purpose? If so, why?
Recipe Draft
Within SSMS on the source server, open the Object Explorer (F8), right click on the DB you want to transport (e.g.myDB) and choose Tasks > Backup...
In the pop-up window, choose Backup Type: Full. Under Destination, choose Back up to: Disk and add a folder.
Navigate to the folder where the .bak file is stored, e.g. C:\Program Files\Microsoft SQL Server\MSSQL 14.MSSQLSERVER\MSSQL\Backups\, transfer it to the destination server onto a similar location.
On the destination server, open the Object Explorer (F8). Make sure you have no database context called myDB, then right click on another context, choose Task > Restore > Database... and then what?
I would also need help with the last step, please. The popup window shows on top No backup set selected to be restored. and keeps freezing if I want to choose the myDB.bak file.
References
SQL Server Management Studio: Backup and restore database without data
Import / Export database with SQL Server Server Management Studio - loads of hits, but rather old and not quite fool-proof recipes
Copy database from SQL server management to another instance Directely
Microsoft SQL DB to MySQL DB
restore sql backup with microsoft management studio
You should use COPY_ONLY if you don't want to mess with the potentially existing backup set. For example, if you have some backup solution that takes differential backups (log backups) in between full backups. You need to use COPY_ONLY if you're manually going to take a FULL backup, otherwise you will make the differential backups useless until the next FULL backup is performed by your backup solution (or you have to use that FULL backup of yours together with the diff backups in case of a point-in-time restore, but you risk having issues using that with your normal backup solution).

How to restore a database from a backup in installshield

I'm using MSI Project with InstallShield 2010.
I have a .bak file, a backup of a SQL database (I am using SQL Server 2008 R2). How can I restore it using InstallShield?
I was looking in SQL Scripts tab and I didn't find anything about restoring backups.
Thanks for your time!
Technically you could use a SQL script to restore the .BAK file but this isn't really the best practice. What you are supposed to do is "script out" the database into one or many SQL files and execute those files to create your database during the install.
say suppose you have xyz.bak as a bakup and you want to restore it on to your sqlserver 2008r2 try running following query in ssms
Restore database DatabaseName from disk='path of your bak file'
this will restore your database.
In hopes of getting an answer to this thread's original question, let's say that building up the database via the "script out" approach would take way too long to perform at install-time.
Scripted out, the database I am working with takes ~90 min to get built up. Restoring a 1.6 GB compressed .bak takes ~90 sec.
I am interested in restoring a .bak as part of my IS2010 msi project. Currently CAs are used but a more elegant solution (especially one that can provide progress back to the user) would be more ideal.

Restore a SQL Express database from a file backup

I'm using a SQL Express database on my development machine. Unfortunately, I had to re-install the operating system and all the software on the machine. Now I need help to restoring the database that I was using before the re-installation. I have a backup of all files on the computer from before re-installing, but how do I find and restore the database from it?
You say you have a backup, but I'm not convinced that you do. Do you have any *.BAK files on your machine?
If not, you need to locate the data file (and preferably the log file as well). Depending on how you created the database originally, the files /should/ be in the form of <database name>[_data].mdf (data file) and <database name>[_log].ldf (log file).
Once you've found the files, you can use CREATE DATABASE ... FOR ATTACH and if the log file is damaged you can use the option FOR ATTACH_REBUILD_LOG instead.
A couple of notes:
(a) if you have a backup of the database, the link Rick Liddle created will be useful. Depending on whether your new instance of SQLExpress is located in the same location, you may need to use WITH MOVE to move the data and/or log file to valid folders in order to restore your databases.
(b) depending on what happened to your old machine (e.g. did it crash and die, how was the backup obtained, etc.), the mdf and/or ldf files may not be restorable. This is what proper database backups are designed to insure against.
Are you sure you have an actual backup (.BAK)?
Create a new database.
Right click
Select Tasks
Restore
Files and FileGroups...
Select File

How to manage local sql server database files?

My system is for development, and I run a local copy of sql server 2005. I want to move all the database files out of program files, and put in a better location on another partition. To do this would you simply detach all the databases in SSMS, move the .mdf and .ldf files with windows explorer, then reattach?
That should work.
http://support.microsoft.com/kb/224071
Yes, detach and re-attach them. If you are going to move the system databases also, that will take some special effort. Instructions for that can be found on MSDN.
http://msdn.microsoft.com/en-us/library/ms345408(SQL.90).aspx
Probably this is what you are looking for. I would want to write my answer here but I am too lazy to do that, but I am sending you to my blog post regarding Moving Data File in SQL Server;
http://dbalink.wordpress.com/2008/11/06/how-to-moving-data-files/

Resources