I'm looking for a procedure which would help to restore my database from the backups. I have googled and couldn't find the extract one which I was looking for. Basically I have 2 kind backups files (some backups with .mdf and .log file and some backups around 30 logical files). Would like to pass 2 argument to the procedure during the execution, backup name and the old and/new database name. Could you please advise me putting up this procedure?
You don't need a stored procedure to restore a database and nothing exists within the product by default. You can certainly write one customized for you specific needs if you like.
Details on RESTORE statement is here https://learn.microsoft.com/en-us/sql/t-sql/statements/restore-statements-transact-sql Check it out, try it then come back if you have further questions.
Specific to your ask above, you don't need to specify old DB name if you want to use an existing backup to restore to a new DB name. This is basically a copy operation. The following is a sample of what the script might look like. You should fully understand how the RESTORE statement works (link above) and modify as appropriate for your needs.
-- Assuming your original backup was on Pubs database
RESTORE DATABASE Bars
FROM PubsBackups
WITH MOVE 'Pubs_Data' TO 'D:\SQLServer\bars.mdf',
MOVE 'Pubs_Log' TO 'L:\SQLServer\bars.ldf';
Related
I originally posted this question but it got removed for being a duplicate. I will try to be more clear in my question here, since I run into different problems when trying the solutions suggested.
I have set up a database using the tempdb and now I would like to duplicate this data to store as a more permanent database. However, all options I have found online do not allow me to do this. For example, the following link shows step by step how to duplicate/restore a database but I do not have the same options using the tempdb.
For example, my database setup looks like the following. I can right click on the model database as follows, and I have the option to restore the database.
However, when I do the same to the tempdb I don't have this same option.
So my question is, how can I make a backup of the tempdb to a more permanent database?
EDIT:
When I store the data into a new table, the tables obtain strange names, this does not occur when storing in the tempdb (i.e. some names are stored correctly, others obtain random character/number strings).
This is too long for a comment.
It doesn't make sense to backup and restore the temporary database. By definition, temporary tables are temporary. They go away when the server goes down.
If you have tables that you want to backup and restore, then you don't want them to be temporary tables. You probably need to fix your application so the use of temporary tables is appropriate.
I used the following command for restoring a database:
RESTORE DATABASE TorqueNet
FROM DISK = 'C:\Backup.bak';
GO
This command deletes the existing data and performs a complete data replacement.
Instead of that, I want to append new data and replace existing records if there are any changes but keep existing data.
If I understand you, no you cannot. A database restore will overwrite the destination.
It sounds like you are wanting to merge one database into another, which can be done with 3rd party tools.
You would need to
Restore the backup to another database
Merge the newly restored database into the current database.
If this is a task that you need to repeat, then you could probably create an SSIS package to help you automate the process.
If you have a search for SQL Merge tools, or look at this question
A restore is replacing the database, its not running any kinda of insert or update transact sql it really is just overwriting the database.
A developer has included a DB password within a stored procedure (rolls eyes). We include a backup of this database with our setup application for new customers. We've updated the stored procedure, but the password is still visible in plain text within the backup file as this includes both the current stored procedure and the original one.
We've cleared transaction history and recreated the log file, but these don't seem to affect historical stored procedure code. Is there some way of removing this from the DB backup?
Thanks very much in advance for any suggestions! We've hunted around and drawn a blank so far.
You could re-create the full db. SSMS will support you under Tasks -> Generate Scripts... But this can be quite a big work to do...
If you are developing with Visual Studio You could think about a data base project to set your database under Source Control and get a scripted master. This makes it easier to re-create the full database and offers many other benefits. Other IDEs will support this too - probably.
You could try to set the db to single-user-mode, set its backup mode to simple, shrink the log file to smallest, shrink database files to smallest and drive a full backup. I've never had this problem, but I'd assume, that doing so, all residues should disappear...
Good luck!
Hi by mistake I've altered one stored procedure and is there any chance to get that old procedure?
Thank you
There is no reason whatsoever to not put your database in source control and treat it like any other code. You should NEVER make a change to a database without a source control script. This means never ever using the GUI to make database changes.
The only way to get back what you replaced is to restore a backup or if you have the other version on a another server, then script it and re-run on the server you you changed.
Yes fixing your source control problem is an emergency, you and your team should not write anymore code of any kind until this is done.
Restore a backup of the affected database onto another server to get the old procedure's code, then copy just that code over.
If you don't have a spare server, you can restore the database to a different database on the same server. (create a new database, then restore the backup to that - just pay attention that you're restoring onto your new/temporary database, then delete that database when you're finished)
Red-Gate has SQL log rescue which might have helped (it's for SQL2000), but there might be other solutions available.
Is there any way (3rd party product or other method) to do a partial restore to ms crm?
Say a user accidentially deleted an account. Is there anyway to restore just that single account and corresponding notes, activities etc?
We limit users' permissions but inevitably they will have permission to delete some things and will want to get that item from a backup.
Right now the only method I can think of is to restore the .bak file to another db and write a bunch of code using the sdk to re-create the items. Are there any other options?
Red Gate has a tool which will let you restore just certain objects from a database.
Idera has this new virtual database tool where you basically mount the backup as a SQL Server database.
Full disclosure - I haven't used either for this kind of thing - I've always either used audit trails or restored the database and extracted the data manually.
You are correct in that you can only restore to a different database and work from there.
You could then use something like Red Gate data compare to extract the desired rows (14 day trial, but it's worth it's weight in SO Rep anyway)
To be honest, I'd go with
Right now the only method I can think of is to restore the .bak file to another db and write a bunch of code using the sdk to re-create the items.
After all, 'Its the only way to be sure....', not to mention the (extremely) vague chance of another record being created with the same GUID, which would cause assorted 'bad stuff' to happen.
Yes, a small number, but still more than 0...