Rebuilding the Development Database Every Week: Can It Be Automated?
· DataMint · 7 min read
Every Monday morning the same question comes from the development team. "When does the dev database get refreshed?" And the work is usually done by one person. On Friday night or over the weekend they take a production dump, load it onto the development server, run the script that scrubs personal data, and grant the permissions again.
If the question is whether this can be automated, the answer is yes. But hanging a script on cron soon reaches its limits. This post covers why the manual approach does not last, and what needs to be decided in advance when automating.
Why a manual refresh does not last
It works well at first. The problems appear about six months in.
- It is tied to one person. When the person who wrote the script goes on vacation, the dev database is not refreshed that week. When that person moves to another department, nobody can fix the script.
- The intermediate stage is dangerous. Between loading the dump and scrubbing the personal data, the development server holds production data as is. If the script stops midway, Monday arrives in that state.
- Nobody notices that tables were added. When a new personal data column appears in production, the scrubbing script stays as it was. The new column comes across unmasked.
- Failures are noticed late. A failure in the early hours is only known when someone says "this is last week's data" at ten on Monday morning.
- There is no record. When an audit asks "when did you take which production data," the only evidence is a few lines of script output.
The second item deserves separate emphasis. Loading the dump first and scrubbing later means that, one way or another, production data lands in the development environment once. Where possible, it is better to convert while moving, so that only converted values ever enter the dev database.
What to decide before automating
Answer the questions below before choosing a tool. Once the answers are set, the implementation is simpler than you might expect.
Reload everything, or only what changed?
For a test database, emptying it entirely and reloading is usually better. Applying only the changes is faster, but they mix with data that testers modified last week, and you can no longer tell "whether this value came from production or someone changed it." If a table is very large, bringing only the last few months with a filter condition is another option.
When to run, and when not to run
As important as the run time is the time when it must not run. Overlapping with the production database's nightly batch or backup window puts load on production. There are also periods when nothing should be touched at all, such as month-end closing week. Once you start putting these exceptions into the script as if statements, it becomes unmanageable. Schedules and exceptions are better managed separately.
If the previous run has not finished
As data grows, sooner or later the next run's start time arrives before the previous one ends. If they overlap, two jobs empty and fill the same tables at the same time. You need to decide whether to skip or wait when the earlier one is still running.
If only part of it fails
When 2 out of 300 tables fail, you also need to decide whether to treat the whole run as failed or let the rest be used. And the fact that it failed has to be visible to the person in charge first thing the next morning. Being recorded somewhere in a log file is not enough.
If the server was down
If the server that runs the schedule was down in the early hours, whether to run the missed job when the server comes back in the morning is also a policy. It is a problem if the job runs late during business hours and empties the dev database while it is in full use.
Automation checklist
In summary, these are the items to check, whether you build it yourself or use a product.
| Item | What to check |
|---|---|
| Personal data | Is it converted while moving (does the original never land in the dev database)? |
| New columns | Will you know when the production table structure changes? |
| Schedule | Are the times when it must not run managed separately, along with the cycle? |
| Overlap | What happens when the previous run has not finished? |
| Failure | Are results recorded per table, and are failures known right away? |
| Missed runs | Does it avoid running late after the server stops and comes back? |
| Records | Is it recorded who registered it and when it ran? |
| Disposal | When is used test data deleted? |
Schedules in DataMint Core
DataMint Core converts values read from the production database while moving them. Only converted values enter the dev database, so there is no "load, then scrub" intermediate stage. You then put a job built this way on a schedule.

Here is how the product handles the decisions listed above.
- The cycle is chosen from once, hourly, daily, weekly, every two weeks and monthly, with an optional start date and end date. The next run time is shown before you save.
- Blackout windows are registered by every day, day of the week, or specific date. A run that falls in such a window does not run and is recorded as "skipped."
- If the previous run of the same job is still in progress, this run is skipped.
- A run that passes the allowed delay (60 minutes by default) because the server was stopped is not run late. It is only recorded as "missed."
- To pause a schedule for a while, you put it on hold instead of deleting it.
A result is kept for every run, and the run detail records the rows read and rows loaded per table. If some rows could not be loaded because of their values, the whole run is not failed. It reports "this many succeeded and this many failed out of this many," with the reasons.

What happens to the data after use has to be considered too. Once a retention period is set, test tables past that period are emptied automatically, and if they are needed longer, an extension is requested and approved before expiry. If only the refresh is automated and disposal is left to people, forgotten test databases pile up in the end.

Closing
Refreshing the development database looks easy to automate. The hard part is not the run itself but the exceptions: times when it must not run, overlapping runs, partial failures, and a stopped server. Decide the answers to these four and the Monday morning question goes away.
If you are curious about how the values themselves are changed, we recommend first reading why joins break after masking.
- #development database refresh
- #test database automation
- #test data
- #scheduling
- #DBA
- #database refresh