Sql-server – Excluding Read only databases using Ola Hallengren script

ola-hallengrensql server

Is there a way to exclude Standby or Read only databases from Index maintenance and also from backups using Ola Hallengren scripts.

Best Answer

It's available for backups.

NUTS

Though it's a somewhat recent addition, so you may need to upgrade your scripts.

For index maintenance, database status is checked so commands don't actually run on databases that aren't fully accessible.

IF DATABASEPROPERTYEX(@CurrentDatabaseName,'Status') = 'ONLINE'
AND (@CurrentIsDatabaseAccessible = 1 OR @CurrentIsDatabaseAccessible IS NULL)
AND DATABASEPROPERTYEX(@CurrentDatabaseName,'Updateability') = 'READ_WRITE'
BEGIN

Hope this helps!