0

I have a problem setting the BackupFile-attribute on the Backup-SqlDatabase command (in Powershell for Linux). It expects a Windows path.

What I did:

I've installed PowerShell on a centos Linux. I started Powershell with pwsh and installed the SqlServer module. I store my db-credentials in $cred.

I then run:

PS /> Backup-SqlDatabase -ServerInstance "-----" -Database "MyDatabase" -BackupFile "~/db-backup.bak" -Credential $cred

The output is:

Backup-SqlDatabase: System.Data.SqlClient.SqlError: Cannot open backup device 'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Backup\~\db-backup.bak'. Operating system error 3(The system cannot find the path specified.).     

If I omit the BackupFile attribute, it'll actually do a backup - but I have no idea, where it stored the .bak-file (if it even did?)

So, how can I make the BackupFile-attribute accept a Linux path?

SanSaurus
  • 63
  • 4
  • 1
    The file paths of backups and restores are relative to the target SQL Server. You can't backup/restore SQL Server database to/from files on client computers. If the SQL Server service is configured appropriately (e.g.: with an Active Directory account) you may be able to backup to a UNC Share which could be accessible from both the server and your client computer. – AlwaysLearning Mar 15 '21 at 09:26
  • @AlwaysLearning Ah! Makes perfect sense. I had the impression I was able to backup a remote sqlserver to the client computer from which I initiated Backup-SqlDatabase. Thanks for clarifying! – SanSaurus Mar 16 '21 at 21:36

0 Answers0