Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

My apologies if this has already been answered. I've searched SO and of course here on DBA, and am surprised to find no close matches. Specifically, I'm looking for a solution which survives schema differences.


I finally got a development server with which to shadow a production data warehouse server. I'll be testing schema and sproc changes here, eventually publishing such changes to the prod server. To do so, I'll need reasonably current data, but it need not be updated in real time. My plan is to copy end-state data from the main server to the dev server as the final step in overnight ETL. What's the best way to achieve this?

Parameters

All automatic copying will be from prod to dev. Any copying from dev to prod will be by hand, and generally will just be DDL.

Because the dev server's schema is expected to change independently of the production server, I don't want the copy process to fail when the target schema differs (it's OK if the specific tables in flux can't be kept in synch, of course). Otherwise I would just DROP DATABASE and restore last night's backup.

Keeping the schema, SPs, views, and UDFs in synch is not necessary, or even desirable. They should only change when I specifically change them.

Records can be changed retroactively in most tables, so incremental updates will probably not be practical.

The volume of data is 14 GB for the most critical tables, plus about 200 GB of less important data which can be updated weekly.

My goal is to finish the process within two hours. The servers are co-located, and should have high throughput. Copying (INSERT INTO..SELECT * FROM ProdServer..) a single table with 600 MB of data and 300 of indices took 7.5 minutes; not great. Of some concern, another table with 11 GB of data and 8 GB of indices did not finish in 130 minutes, when I cancelled it. I'll test this again without indices.

Taking the prod database offline is acceptable if it can be kept brief - no more than 30 minutes. The dev database can be offline for hours if necessary.

If I can temporarily exclude a specific table, keeping it static for a few days while testing, that would be valuable.

Options

1: Replication

I could create a daily snapshot after the end of ETL, and publish it to the dev server. I've not used replication before, but this seems to be the kind of scenario for which it is meant. Time for me to learn a new facet of the technology?

2: Bulk Copy and BULK INSERT

I could write a script which iterates through every table in the prod database and spits out the content to a uniquely-named file. On the dev side, I'd loop through these files and TRUNCATE/BULK INSERT into the target table, with a TRY..CATCH block in case the schema has changed. I'm not sure if this would perform acceptably, but it would be fairly simple to implement.

3: INSERT from Linked Server

I can run a TRUNCATE/INSERT..SELECT for each table, probably pulling from the dev side. This would be simple, and should be fast, especially if one drops and re-created the indices. To cope with schema changes, one could identify the intersection of the field lists for each pair of tables and only attempt to copy those fields; this would help if many fields were NULLable.


Are there other options? Is there an easier way that I'm overlooking? Are there any gotchas that you've hit when working on similar projects?

This question describes the export side, but the desired output was CSV, so the options are limited (and BCP works great, as answered).

This question talks about quickly copying a whole database, including schema. It specifically excludes replication.

This question discusses bi-directional synchronization, for which replication is suggested.

share|improve this question
add comment

4 Answers

up vote 1 down vote accepted

I'd consider backup/restore of a mix of full and differential backups from prod to dev. Then synch between this restored copy to your actual dev databases

SQL Server 2008 R2+ supports backup compression in Standard Edition (In SQL Server 2008 it was Enterprise Edition only) which makes this easier.

Reasons:

  • You test your backup integrity and restore capability
  • You can reset your dev database easily if some code monkey bollixes it
  • You can compare "before" and "after" DDL, performance etc
  • You can snapshot the restored database as needed to roll this back if you make changes

I've used this before and will use it again for these reasons

I suggested this in my answer to The smallest backup possible ... with SQL Server

share|improve this answer
    
Just so I'm clear, your talking about a two-step process, right? First copy the prod backup to dev and restore it there, then use another technique to synch the two databases while they're physically on the same box, with super-fast shared memory rather than reading over the network? Very nice! –  Jon of All Trades Jun 12 '12 at 15:29
    
@JonofAllTrades: yes and no. If you can use diff restores, then it becomes a lot lighter. If you need to do full restores daily, it could be cumbersome. YMMV etc –  gbn Jun 12 '12 at 18:47
add comment

I would recommend using SQL Server Integration Services (SSIS) for this type of requirement. The power in SSIS would be the ease of error handling (as required by your question), the ability to schedule it, and the flawless maintainability of a DTSX package. You won't have to worry about explicitly linking servers or any downtime.

SSIS nicely handles the separation of concerns. It's an independent package that, when used with SQL Server Agent, can be scheduled nightly or you can run it on demand.

share|improve this answer
    
I like the idea of having a wholly separate unit taking care of this process, but wouldn't that require creating 50 data flow tasks, one for each table, and also refreshing them after each schema change? "Flawless maintainability" is not normally the phrase that jumps to mind when I'm using SSIS... "unbelievable PITA" is a little closer. –  Jon of All Trades Jun 12 '12 at 15:37
add comment

Contiguous integration with migrations. Deployment of V. Next means running the upgrade scripts for V. Prev to v. Next. Scripts are source, checked in. Never consider the database binary files (MDF, LDF) as the true schema. consider the source (.sql) as the schema, always operate on the .sql files, test the .sql files until you're confident on the upgrade and then deploy the upgrade by running the .sql file.

Diff based deployment is riddled with problems as you are at the mercy of the diff tool (some are better than other, personally I would never trust my live deployment on any of them). Copy based deployment is not even worth mentioning.

No change occurs on liver server w/o going through this process. Ever.

How about copy of prod server to dev? Why would you ever need to do it, other than compromise data by exposing it to unauthorized eyes? Deploy a test/dev server using the same procedure, contiguous integration and migrations.

In some scenarios is acceptable to have a test replica of prod, or a dev replica of prod. Make it part of the contiguous integration build drop: the nightly drop starts with a prod backup, runs the migrations from v. prod to v. dev, the result is the dev variant of the prod database, freshly dropped. BTW, did you notice that the drop also just tested the migration from v. prod to v. dev? Does data has to be anonymized or some other transformation for the dev environment? Make it a dev specific deployment step, of course controlled by scripts checked into the source tree.

share|improve this answer
    
That sounds very much like what I have planned, but honestly I'm having a little trouble following your staccato sentences. What's "V"? –  Jon of All Trades Jun 12 '12 at 15:30
    
In this case, only one person (moi, the DW admin) has access to the dev server, so I'm not worried about unauthorized eyes. No need for anonymization, though that's a great point if it was going to be a more traditional broadly-used dev server. –  Jon of All Trades Jun 12 '12 at 15:31
    
V. Is for "version". Sometimes my office jargon makes it into the wild... –  Remus Rusanu Jun 12 '12 at 17:02
add comment

Snapshot replication would be the only kind of replication that might work. But it could prevent schema changes like the other versions do (transactional, merge/peer-to-peer). But you would just be better off with a backup and restore (Remus' ideas look spot-on) as you will gain nothing with replication for this scenario.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.