Linux – Is it possible to make a backup of a MS SQL database from a linux command line

command-line-interfacedatabase-backuplinuxsql server

Is it possible to create a local backup file of a remote Microsoft SQL Server database, from a linux command line?

I know I can use SQLCMD from a Windows command line, but is the same possible from a linux box?

Best Answer

When you issue a backup command with sqlcmd from a windows command line, you are telling the server to backup a database. sqlcmd just relays the command; it doesn't really know what you have asked SQL Server to do. I would be surprised if any other tool worked in any other way.

SQL Server expects to write (and read, if required) backups to either local storage (something with a drive letter, like c:\temp\mybackupdir) or a UNC path (something that looks like \hal9000\mybackupshare).

A local path could be an iSCSI device as long as Windows can deceive SQL Server into thinking it is a "real" local drive. There is no built-in support in SQL Server for nfs, ftp, scp or anything like that. I know and/or presume that there is software that can make an nfs or ftp "share" look like a local path. I'nm not so sure about scp. There is no raw data output that you could netcat into a file, either.

Another common problem is that, on windows, drive mappings are per-user. This means that you could log into that windows machine, permanently map the R drive (or whatever drive) with stored credentials and the SQL Server will not see the mapping because the SQL Server service is probably running under a different account.

A UNC path could be a share on a Samba server, which could be on the same host that you are running that *nix command tool from.