Backup databases whose names includes spaces

Compresses, encrypts, secures and monitors SQL Server backups.

Moderators: JonathanWatts, Chris Auckland, eddie davis, Colin Millerchip, Brian Harris, james.billings, RBA, petey

Backup databases whose names includes spaces

Postby fredmut » Thu Jun 21, 2012 10:05 pm

I need to backup a set of databases (via SQL Agent job) with names that include spaces (yes I know that's not best practice). I'm using a command like EXECUTE master..sqlbackup ''-SQL "BACKUP DATABASES [Bad Database Name].... but it doesn't parse. I've tried surrounding the name in double quotes and square brackets without success. Any help would be greately appreciated.
fredmut
 
Posts: 5
Joined: Thu Jun 21, 2012 6:12 pm

Postby Marianne » Fri Jun 22, 2012 9:45 am

Hi,

Thanks for your post. When using the extended stored procedure, the parameters must be surrounded by one set of single quotes, so any variables inside the command must be surrounded by two sets of single quotes (or square brackets). If your database name includes spaces, you should surround it with square brackets, rather than two pairs of single quotes. Your command should look like this (replacing variables and WITH options as required):

Code: Select all
execute master..sqlbackup '-sql "BACKUP DATABASE [database name] TO DISK = ''C:\\Backups\\<AUTO>.sqb'' WITH CHECKSUM, THREADCOUNT = 3" '

(The disk location is surrounded by two sets of single quotes, whereas the BACKUP command is surrounded by one set of double quotes. The entire parameter is surrounded by one set of single quotes.)

There is more information about using the extended stored procedure here: http://www.red-gate.com/supportcenter/Content/SQL_Backup/help/7.1/SBU_UsingStoredProc and examples of SQL Backup syntax here: http://www.red-gate.com/supportcenter/Content/SQL_Backup/help/7.1/SBU_Toolkit_syntax_egs

If this doesn't help, can you post the exact command you are using?

Thanks,

Marianne
Marianne Crowder
Red Gate Software Limited
Marianne
 
Posts: 45
Joined: Mon Oct 03, 2011 3:24 pm

Postby fredmut » Fri Jun 22, 2012 2:08 pm

Thanks Marianne. I'll give that a try. One more question - can I pass in a TSQL like variable for the database name so I don't have to maintain a hard coded list of databases to backup or exclude? I'm not finding that addressed in the documentation.
fredmut
 
Posts: 5
Joined: Thu Jun 21, 2012 6:12 pm


Return to SQL Backup 7

Who is online

Users browsing this forum: No registered users and 2 guests