Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL Backup Database command for file path with spaces?

Tags:

file

tsql

backup

How do I write a T-SQL backup database command to specify a file containing spaces? Here is what I have:

BACKUP DATABASE AMDMetrics TO DISK = 'C:\Documents and Settings\daultrd\My Documents\DatabaseBackups\AMD_METRICS.DAT'

And this is the error I get:

Msg 3201, Level 16, State 1, Line 1 Cannot open backup device 'C:\Documents and Settings\daultrd\My Documents\DatabaseBackups\AMD_METRICS.DAT'. Operating system error 3(The system cannot find the path specified.). Msg 3013, Level 16, State 1, Line 1 BACKUP DATABASE is terminating abnormally.

like image 503
salvationishere Avatar asked Apr 22 '11 13:04

salvationishere


People also ask

How do I free up space in SQL?

To shrink a file in SQL Server, we always use DBCC SHRINKFILE() command. This DBCC SHRINKFILE() command will release the free space for the input parameter. The file will be shrunk by either file name or file id using the command above.

How do I change the backup path in SQL Server?

Right-click the SQL Server instance and select Properties. Select the Database Settings section. At the bottom of this window, you should see the Backup default location. Browse to the new Backup location and then close.


2 Answers

Try sharing your intended destination folder and using a UNC path to backup from the server to your local machine.

BACKUP DATABASE AMDMetrics 
    TO DISK = '\\YourMachineName\SharedFolderName\AMD_METRICS.DAT'
like image 176
Joe Stefanelli Avatar answered Oct 08 '22 21:10

Joe Stefanelli


This works for me, are you sure that the directory is correct?

backup database master to disk = 'c:\Test Me\master.bak'


Processed 41728 pages for database 'master', file 'master' on file 1.
Processed 5 pages for database 'master', file 'mastlog' on file 1.
BACKUP DATABASE successfully processed 41733 pages 
in 22.911 seconds (14.230 MB/sec).

copy and paste this into explorer and see if you can get there C:\Documents and Settings\daultrd\My Documents\DatabaseBackups

This of course has to be the same machine, otherwise you need to map a drive to the location or use UNC paths

like image 1
SQLMenace Avatar answered Oct 08 '22 19:10

SQLMenace