patternsqlMinor
Command line tool / script to backup a remote SQL Server database to local disk
Viewed 0 times
scriptlocallineserversqldiskdatabaseremotecommandtool
Problem
I've been researching and googling for 10 hours and couldn't find anything, so I decided to ask here. I'm looking for a command line tool or a script (running under windows) that can backup a remote SQL Server to a local file (.sql, SQL Server backup, even CSV, all formats are acceptable).
P.S. I can't use remote SMB share for backing up DB. Also no GUI, just command line or scripts
P.P.S. The DB is in remote location and I want to backup the data in Database to any format possible in my local machine (Windows server, no SMB share connection in between available/possible)
P.S. I can't use remote SMB share for backing up DB. Also no GUI, just command line or scripts
P.P.S. The DB is in remote location and I want to backup the data in Database to any format possible in my local machine (Windows server, no SMB share connection in between available/possible)
Solution
There are two common ways to do this:
Easy way - with "normal" database backups - when you run the BACKUP DATABASE command, the SQL Server service on the remote box needs to write the backup to a file. The service needs to be able to write to the destination path. To do this:
If you're doing it via T-SQL, it might look like:
Hard way - exporting the data - if the remote SQL Server can't write to your local machine for some reason, like network firewalls or permissions, then you can export the data. A couple of common tools are:
But be aware that those methods can be much slower and not transactionally consistent. They're best for smaller databases - say, under 10GB.
Updated requirements - you noted no GUI, no file system access, and no backups. Given those requirements, you'll be doing some manual work:
Easy way - with "normal" database backups - when you run the BACKUP DATABASE command, the SQL Server service on the remote box needs to write the backup to a file. The service needs to be able to write to the destination path. To do this:
- Set up a shared folder on your local machine
- Give the SQL Server service permissions to write to that share (either by specifically granting it, or by letting everyone write to it - this isn't a security lecture, obviously)
- Run the SQL Server backup, and use the UNC path to your local machine's share for the backup target, like:
If you're doing it via T-SQL, it might look like:
BACKUP DATABASE MyReallyImportantDB TO DISK = '\\MyDesktop\SharedFolderName\MyBackup.bak'Hard way - exporting the data - if the remote SQL Server can't write to your local machine for some reason, like network firewalls or permissions, then you can export the data. A couple of common tools are:
- Exporting a BACPAC file
- SQL Server Import and Export Wizard
But be aware that those methods can be much slower and not transactionally consistent. They're best for smaller databases - say, under 10GB.
Updated requirements - you noted no GUI, no file system access, and no backups. Given those requirements, you'll be doing some manual work:
- Use an ETL tool like SSIS to export the data
- Build a custom app (C#, Java, whatever) to export the data
- Use a data sync tool like Redgate SQL Data Compare
Code Snippets
BACKUP DATABASE MyReallyImportantDB TO DISK = '\\MyDesktop\SharedFolderName\MyBackup.bak'Context
StackExchange Database Administrators Q#212856, answer score: 4
Revisions (0)
No revisions yet.