I am upsizing the back end of a client’s Access app tomorrow and need to be ready with a plan for a particular problem with this client. The boss needs to be able to take the data file away from the office where the SQL Server is on a regular basis (usually monthly) and run statistical analyses on the data.
I’ve looked at Easiest way to copy an entire SQL server Database from a server to local SQL Express, and the solutions there don’t work in this scenario because:
-
can’t use a one-time solution (Database Publishing Wizard), as this needs to be scriptable.
-
can’t use any method that depends on the two computers being networked, as that is not an option — data has to be transferred via USB thumb drive (so, no replication).
-
can’t use any method that depends on running SQL Server management tools from the server console or from the workstation for the backup.
-
can’t connect to the SQL Server database directly for the analysis because the data has to be portable to other locations.
What I think I need is some way to call a script that creates a backup file, then copy the result to the USB drive. I then need a second script to copy the backup file from the USB drive and restore it onto the other SQL Server.
The data being transported is read-only (or, any changes made don’t need to get back to the main server), and data won’t be updated in the second location. It’s currently scripted with a plain old batch file to copy the back-end MDB file, and I need something that is as simple for the user.
It can’t have any dependencies on, say, Powershell (of SQL Server Management Studio), because I don’t want it to have to be installed on the computer the user is running the script from (there are a half dozen workstations the script needs to be runnable from, and I don’t want to have to install something on all of those).
I’m going to be setting up the backup agent to create a backup every night, so I could perhaps copy that file without needing to initiate the backup before copying. Thus I might only need to script the restore on the target computer.
Thoughts, suggestions, pointers?
You should definitely be able to create something like that.
One part would be a T-SQL
CREATE BACKUPscript as a.sqlscript, and execute that from a standard Windows batch (*.bat) or command (*.cmd) file using thesqlcmdcommand line tool.That would be something like this:
backup.sql
The second part would be a .sql file with a T-SQL
RESTOREscript, basically reading the data from a given location on disk and restoring it to that SQL Server instance there.restore.sql
Of course, you need to adapt those names and paths to your own actual requirements – but that should just give you a hint how to get started with this endeavor.
To execute one of those .sql script using
sqlcmd, you need something like:e.g.
Resources: