Domanda

I want to make a backup of my SQL Server database so I can send it to my vendor to help with diagnosis. However, I don't want to include the data from tables with customer information.

Here's what I tried: make a copy of the database, delete all the tables with customer information, then make a backup of the result.

However, when I view the backup in a text editor, I see plenty of private data sitting in the backup file. Any idea why?

È stato utile?

Soluzione

When you delete data in a SQL Server database, SQL Server just marks the pages as free, but does not overwrite the data. Just like any modern file system does not actually delete the files but instead just marks the disk blocks as free.

To clean out your database I would try the following:

  1. delete the data
  2. rebuild all indexes and heaps (rebuild, not reorganize)
  3. shrink each datafile with reorganization of the pages to the minimum possible size
  4. repeat 2 and 3 a few times
  5. execute a checkpoint
  6. detach the database and rename the logfile
  7. reattach the database forcing SQL Server to recreate a new empty log file (http://www.mssqltips.com/sqlservertip/1894/attach-a-sql-server-database-with-a-missing-transaction-log-file/)
  8. run a DBCC CHECKDB to make sure you did not break anything
  9. take the backup

Now this is a very destructive process, so be sure to never do this to a database you want to keep using yourself, but it should remove all the deleted data.

Rebuilding the indexes is necessary, because otherwise a single deleted row might survive amongst non-deleted rows within a page. Reorganizing and shrinking removes unused pages. However sometimes it does not completely clean up, therefore you need to repeat the steps 2 and 3. 4, 5 and 6 make sure that there is no trace of the data left in the log file that otherwise would, depending on your recovery model, still contain the deleted data, potentially several times.

Altri suggerimenti

Probably a good answer here:

https://serverfault.com/questions/33432/does-restoring-a-sql-database-from-backup-rebuild-its-indexes

keep in mind that a table (should) be a clustered index.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top