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!
Related
What is the best way to backup SQL server schema ??
My schema contains (file-groups ,file streams,tables,relations between tables,constraints,users,...)
I want to backup the schema and its related objects, so I can restore it later to the same database or to a different database that has another schema and objects.
I tried using the file-group backup because it has some restrictions (database must be FULL recovery mode, must backup primary file-group and log), but I want to backup only one schema at a time.
Has anyone any idea to backup schema to file (access or any format) or any way.
You may want to review this document from when Microsoft introduced schemas into SQL Server.
The shortest answer is that databases are the unit for backup and recovery. Schemas are the unit for security.
You should back up the entire database, not just one schema.
Unless you have a really large schema, you can just script it.
In SSMS right-click on your database, then select Tasks - Generate Scripts...
There are some dialogue windows to go through, you can select only certain db objects if you prefer. I'm not sure if this covers file-groups or file streams but all the other db objects you mention are covered. You could try it with just one table to see what happens.
Be careful, on the "Set Scripting Options" dialogue, click Advanced and scroll down to "Types of data to script" in the modal window and ensure that "Schema Only" is selected.
You can script the schema, the data or both. If you db contains a lot of data and you try to script that, it will almost certainly cause SSMS to crash. You've said in your comment that you also want to back up data. This is the only way I know to achieve this without backing up all the other schemas in the db.
Most of the other options are self explanatory. The tool will generate a SQL script. You can run it on a empty db to build up the data structure that you scripted (or just one schema if you prefer)
I hope this helps.
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';
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...
I need to copy about 40 databases from one server to another. The new databases should have new names, but all the same tables, data and indexes as the original databases. So far I've been:
1) creating each destination database
2) using the "Tasks->Export Data" command to create and populate tables for each database individually
3) rebuilding all of the indexes for each database with a SQL script
Only three steps per database, but I'll bet there's an easier way. Do any MS SQL Server experts out there have any advice?
Given that you're performing this on multiple databases -- you want a simple scripted solution, not a point and click solution.
This is a backup script that i keep around.
Get it working for one file and then modify it for many.
(on source server...)
BACKUP DATABASE Northwind
TO DISK = 'c:\Northwind.bak'
(target server...)
RESTORE FILELISTONLY
FROM DISK = 'c:\Northwind.bak'
(look at the device names... and determine where you want the mdf and
ldf files to go on this target server)
RESTORE DATABASE TestDB
FROM DISK = 'c:\Northwind.bak'
WITH MOVE 'Northwind' TO 'c:\test\testdb.mdf',
MOVE 'Northwind_log' TO 'c:\test\testdb.ldf'
GO
Maybe the easiest is to detach/reattach. Right-click in the server manager on the DB, tasks --> detach. Then copy the MDF/LDF files to the new server and then reattach by clicking on the server icon and tasks-->attach. It will ask you for the MDF file - make sure the name etc is accurate.
In order of ease
stop server/fcopy/attach is probably easiest.
backup/restore - can be done disconnected pretty simple and easy
transfer DTS task - needs file copy permissions
replication - furthest from simple to setup
Things to think about permissions, users and groups at the destination server esp. if you're transferring or restoring.
There are better answers already but this is an 'also ran' because it is just another option.
For the low low price of free you could look at the Microsoft SQL Server Database Publishing Wizard. This tool allows you to script the schema, data or data and schema. Plus is can be run from a UI or command line <- think CI process.
Backup -> Restore is the simplest, if not to use the replication.
If you use the Backup/Restore solution you're likely to have orphaned users so be sure to check out this article<microsoft> on how to fix them.
Another one to check out that is quick and simple:
Simple SQL BULK Copy
http://projects.c3o.com/files/3/plugins/entry11.aspx
Backup the databases using the standard SQL backup tool in Enterprise Manager, then when you restore on the second server you can specify the name of the new database.
This is the best way to maintain the schema in its entirety.
use backups to restore the databases to the new server with the new names.
Redgate SQL Compare and SQL Data Compare. The Comparison Bundle was by far the best investment a company I worked for ever made. Moving e-training content was a breeze with it.
Check those links:
For multiple db's backup
and single db restore