Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2008-06-18 : 05:51:47
|
| Hi,I would like to run several checklists against each sql server 2005 instance.I can get a list of the sql server 2005 machines (Which are on the network) from a sql server table.There is a another table which holds the list of the checks that need to be carried out against each sql server 2005 machine called tblCheckList.The list of tasks in the table is briefly as follows:1) get the path where the .mdf file is placed.2) get the path where the .ldf file is placed3) get the path where .BAK or .TRN are placed4) get the path where the sql 2005 is installed5) get the servicepack version6) get the authentication7) remove sample databases i.e. northwind or pubs, etc...8) get the recovery model on UserDB9) get the size of each database.........The list goes onThanks |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2008-06-18 : 06:01:30
|
| And what is the question?Would you like to know how to do each task or the best way to do this as a whole?If the later, then is this a one off task or will it be on a schedule? |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2008-06-18 : 06:18:45
|
| sorry, i though I did write the question at the beginning...Anyway, yes, you are right, that is the question. Would you like to know how to do each task or the best way to do this as a whole.The list of checklist i.e. tasks can be added to. The name of the sql server 2005 machines can also be added as we get new sql server machines.p.s. I am not sure whether this is a one off or needs to be scheduled. At present I think it will be a one off for each server.Thanks |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2008-06-18 : 06:37:30
|
| Its going to be a bit of a mare to get all of this information, i'm sure there are 3rd party tools that will give you some of this information though. For a start you could have a server where each database has its files in different directories, so you would need to list the values per database per instance per server. You could go someway towards this by using sysdatabases and sysfiles in master and use dynamic SQL to get the results.I am not sure where the information on the backups would come from though as this information is held in the job itself or the maintenence plan if you are using them. |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2008-06-18 : 06:49:21
|
I'm actually designing the *exact* same thing at the moment and even though I haven't come very far (I do it when I find the time) I've played a little with OPENROWSET to be able to pull this off without adding all the servers as linked servers or something. But this requires that you have a valid sql server user for each of your servers with the required permissions. I have created two tables, one with a list of servers and anoter with queries in it and then this "master procedure" which will run all the queries on all the servers. I don't know yet if this is the right way to go and there are some missing pieces here but it might give you some ideas:DECLARE @sql NVARCHAR(2000), @sql_from_db NVARCHAR(2000), @ServerName VARCHAR(2000), @OutputColumns VARCHAR(MAX), @OutputTableName VARCHAR(200), @Counter INT, @MaxCounter INT DECLARE @table TABLE ( ID INT IDENTITY(1, 1), ServerName VARCHAR(500), Query VARCHAR(max), OutputColumns VARCHAR(2000), OutputTableName VARCHAR(200))INSERT INTO @table (ServerName, Query, OutputColumns, OutputTableName)SELECT ServerName, Query, OutputColumns, OutputTableNameFROM dbo.servers AS s INNER JOIN dbo.server_queries AS sq ON s.ServerID = sq.ServerID INNER JOIN dbo.queries AS q ON q.QueryID = sq.QueryID SET @MaxCounter = (SELECT COUNT(*) FROM @table)SET @Counter = 1WHILE @Counter <= @MaxCounter BEGIN SELECT @sql_from_db = Query, @ServerName = ServerName, @OutputColumns = OutputColumns, @OutputTableName = OutputTableName FROM @table WHERE ID = @Counter SET @sql = N' INSERT INTO ' + @OutputTableName + ' SELECT ''' + @ServerName + ''', ' + @OutputColumns + ' FROM OPENROWSET(''SQLNCLI'', ''' + @ServerName + '''; ''username''; ''password'', ''' + REPLACE(@sql_from_db, CHAR(39), CHAR(39)+CHAR(39)) + ' '')' --PRINT @sql EXEC sp_executesql @sql SET @Counter = @Counter + 1 END--Lumbago |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2008-06-18 : 06:53:04
|
quote: Originally posted by RickDI am not sure where the information on the backups would come from though as this information is held in the job itself or the maintenence plan if you are using them.
Backup information is in the msdb-database and the following query will give you the latest backups for all databases on a server:SELECT database_name, [TYPE], MAX(backup_finish_date) AS backup_finish_dateFROM msdb..backupsetGROUP BY database_name, [TYPE] --Lumbago |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2008-06-18 : 06:58:47
|
quote: Originally posted by Lumbago
quote: Originally posted by RickDI am not sure where the information on the backups would come from though as this information is held in the job itself or the maintenence plan if you are using them.
Backup information is in the msdb-database and the following query will give you the latest backups for all databases on a server:SELECT database_name, [TYPE], MAX(backup_finish_date) AS backup_finish_dateFROM msdb..backupsetGROUP BY database_name, [TYPE] --Lumbago
Yeah, but you do not get the backup path from backupset. |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2008-06-18 : 07:32:13
|
Hm, never really had the use for that information as all backups are stored in the same place here, but it seems like the physical name is in the backupmediafamily table:SELECT database_name, [TYPE], physical_device_name, MAX(backup_finish_date) AS backup_finish_dateFROM msdb..backupset a INNER JOIN msdb..backupmediafamily b ON a.media_set_id = b.media_set_idGROUP BY database_name, [TYPE], physical_device_name EDIT: don't really know what it says if the backup device is something other than a file, but at least physical_device_name has the physical path to the backup file. --Lumbago |
 |
|
|
|
|
|
|
|