| Author |
Message |
gscdba
Joined: 24 Jan 2012 Posts: 4
|
Posted: Tue Jan 24, 2012 12:52 pm Post subject: Backup online databases only... |
|
|
Answered my own question!

Last edited by gscdba on Tue Jan 24, 2012 1:22 pm; edited 4 times in total |
|
| Back to top |
|
 |
gscdba
Joined: 24 Jan 2012 Posts: 4
|
Posted: Tue Jan 24, 2012 1:16 pm Post subject: |
|
|
ok - seems dynamic SQL is the answer...
EXEC sp_executesql @dSQL |
|
| Back to top |
|
 |
gscdba
Joined: 24 Jan 2012 Posts: 4
|
Posted: Tue Jan 24, 2012 1:27 pm Post subject: Re: |
|
|
| gscdba wrote: |
ok - seems dynamic SQL is the answer...
EXEC sp_executesql @dSQL |
For those interested in a dynamic solution, I used this to generate the comma separated list of databases which are online and in full recovery model, then wrapped the SQLAgent job step generated by Red-Gate backup:
| Code: |
DECLARE @sql NVARCHAR(MAX)
DECLARE @listOfDatabasesForBackup NVARCHAR(MAX)
SET @listOfDatabasesForBackup = (
SELECT DISTINCT
STUFF((SELECT
[name] + ','
FROM
sys.[databases] AS D
WHERE
[state] = 0
AND [recovery_model] = 1
FOR
XML PATH('')
), 1, 0, '') AS 'OnlineDatabases'
FROM
sys.[databases] AS D
WHERE
[state] = 0
AND [recovery_model] = 1
)
SET @listOfDatabasesForBackup = LEFT(@listOfDatabasesForBackup, LEN(@listOfDatabasesForBackup) - 1)
|
|
|
| Back to top |
|
 |
petey
Joined: 24 Apr 2005 Posts: 2216
|
Posted: Tue Jan 24, 2012 4:20 pm Post subject: |
|
|
What sort of databases was SQL Backup picking up when you used the wildcard backup i.e.
| Code: |
| EXEC master..sqlbackup '-sql "BACKUP DATABASES [*] TO ... " ' |
Thanks. _________________ Peter Yeoh
SQL Backup Consultant Developer
Associate, Yohz Software
Beyond compression - SQL Backup goodies under the hood, updated for version 7 |
|
| Back to top |
|
 |
gscdba
Joined: 24 Jan 2012 Posts: 4
|
Posted: Wed Jan 25, 2012 11:49 am Post subject: Re: |
|
|
| petey wrote: |
What sort of databases was SQL Backup picking up when you used the wildcard backup i.e.
| Code: |
| EXEC master..sqlbackup '-sql "BACKUP DATABASES [*] TO ... " ' |
Thanks. |
Was unaware of this wildcard feature - in any case, I needed a specific filter (online and full recovery model) so querying sys.databases gave me the flexibility. |
|
| Back to top |
|
 |
|
|
All times are GMT + 1 Hour
|
| Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group