Monday, February 25, 2008

Backup Monitoring Across Multiple Servers

Here is a simple back verification solution. "back verification " I am basically looking to answer following question(s)


1 > When was the last FULL backup was done?
2 > When was the last T.LOG backup was done?.


This solution is very handy if you are monitoring lot of SQL Server(s) in your environment. The solution is split into 3 files as follows,


1 > Batch file
2 > SQL Query file
3 > Server list file


What is in Batch file?


In this batch file I am just calling OSQL with required parameters. The dos "FOR" loop is very fantastic and I found that from the web (thanks to the author).



Cls
for /f "tokens=1,2,3" %%i in (SrvList.txt) do OSQL.exe -E -S"%%i" -q -i"BkpDetails.sql" -n -w 2000 >> %random%log.txt


BkpDetails.sql - T-SQL Query



SET NOCOUNT ON
PRINT ' DB Backup details for server ... ['+@@ServerName+'] as on '+ CONVERT(VARCHAR(30), GETDATE())
PRINT ''
SELECT A.NAME [DB_Name], MAX(backup_finish_date) [Bkp Date], MAX(type) [Bkp Type] INTO #Tmp1
FROM master..sysdatabases A
LEFT JOIN msdb..backupset ON a.NAME = database_name
WHERE type = 'L'
GROUP BY A.NAME
ORDER BY [Bkp Date] ASC

SELECT A.NAME [DB_Name], MAX(backup_finish_date) [Bkp Date], MAX(type) [Bkp Type] INTO #Tmp2
FROM master..sysdatabases A
LEFT JOIN msdb..backupset ON a.NAME = database_name
WHERE type = 'D'
GROUP BY A.NAME
ORDER BY [Bkp Date] ASC

select LEFT(#Tmp2.[DB_Name], 30), LEFT(#Tmp2.[Bkp Date], 30) AS [Last Full Bkp Done At],
LEFT(#Tmp1.[Bkp Date], 30) AS [Last T.Log Bkp Done At]
from #Tmp2
LEFT JOIN #Tmp1 ON #Tmp2.[DB_Name] = #Tmp1.[DB_Name]
ORDER BY #Tmp1.[Bkp Date] ASC

DROP TABLE #Tmp1
DROP TABLE #Tmp2
PRINT ' ------------------------------ ------------------------------ ------------------------------ '
PRINT ''





What is in SrvList.txt ?


In this txt file I am just listing all my servers that I want to monitor. One server name per line only. In this case I have repeated same server name multiple times to show sample output



LVEPL3KC824\LOCAL
LVEPL3KC824\LOCAL
LVEPL3KC824\LOCAL



Sample Output..



DB Backup details for server ... [MSSQL_2K5] as on Feb 25 2008 9:37AM

Last Full Bkp Done At Last T.Log Bkp Done At
------------------------------ ------------------------------ ------------------------------
msdb Feb 25 2008 9:33AM NULL
master Feb 25 2008 9:33AM NULL
model Feb 25 2008 9:33AM Feb 25 2008 9:34AM
TestDB Feb 25 2008 9:33AM Feb 25 2008 9:34AM
TestDB_Prod Feb 25 2008 9:33AM Feb 25 2008 9:35AM
InboxDB Feb 25 2008 9:33AM Feb 25 2008 9:35AM

------------------------------ ------------------------------ ------------------------------

DB Backup details for server ... [MSSQL_2K5] as on Feb 25 2008 9:37AM

Last Full Bkp Done At Last T.Log Bkp Done At
------------------------------ ------------------------------ ------------------------------
msdb Feb 25 2008 9:33AM NULL
master Feb 25 2008 9:33AM NULL
model Feb 25 2008 9:33AM Feb 25 2008 9:34AM
TestDB Feb 25 2008 9:33AM Feb 25 2008 9:34AM
TestDB_Prod Feb 25 2008 9:33AM Feb 25 2008 9:35AM
InboxDB Feb 25 2008 9:33AM Feb 25 2008 9:35AM

------------------------------ ------------------------------ ------------------------------

DB Backup details for server ... [MSSQL_2K5] as on Feb 25 2008 9:37AM

Last Full Bkp Done At Last T.Log Bkp Done At
------------------------------ ------------------------------ ------------------------------
msdb Feb 25 2008 9:33AM NULL
master Feb 25 2008 9:33AM NULL
model Feb 25 2008 9:33AM Feb 25 2008 9:34AM
TestDB Feb 25 2008 9:33AM Feb 25 2008 9:34AM
TestDB_Prod Feb 25 2008 9:33AM Feb 25 2008 9:35AM
InboxDB Feb 25 2008 9:33AM Feb 25 2008 9:35AM

------------------------------ ------------------------------ ------------------------------



Friday, February 22, 2008

SQL Express for Absolute Beginners!


Lesson 1: What is a database?
This introduction covers the questions and terminology SQL Server beginners need to create and manage databases, such as: What is a SQL Server database? How is a SQL Server database different from an Excel spreadsheet? What do SQL Server databases do in my Web site or software applications? What's SQL Server Express' relation to Visual Studio Express? What do terms like "ADO.NET" mean? Download the Video

Lesson 2: Understanding Database Tables and Records
SQL Server beginners will learn about tables and definitions of data types, properties, keys, etc. in this second video. Find out how table rows, columns, and fields interrelate and whether columns can be empty. Download the Video

Lesson 3: More about Column Data Types and Other Properties
SQL Server beginners will explore data integrity, learn which data types to use for what, and avoid common data type pitfalls. Download the Video

Lesson 4: Designing Relational Database Tables
Why are relational databases the most popular? SQL Server beginners will learn to differentiate between primary and foreign keys, design relational database tables, and learn about normalization rules and de-normalization.Download the Video

Lesson 5: Manipulating Database Data
SQL Server beginners will learn about ADO.NET objects and execution of SQL statement from ADO.NET. Explore SQL and learn about insert, update, and delete statements.Download the Video and Project

Lesson 6: More Structured Query Language
SQL Server beginners will discover more SQL statements like sub-select and learn stored procedures and their counterparts in C# and VB methods.Download the Video


SQL Express for Absolute Beginners !


Nice video(s) for absolute beginners, these videos introduce to couple of SQL Terms and Microsoft's Express Edition of SQL Server. SQL Server Express Edition is freely downloadble from Microsoft's website.

Lesson 1: What is a database?

This introduction covers the questions and terminology SQL Server beginners need to create and manage databases, such as: What is a SQL Server database? How is a SQL Server database different from an Excel spreadsheet? What do SQL Server databases do in my Web site or software applications? What's SQL Server Express' relation to Visual Studio Express? What do terms like "ADO.NET" mean?
Download the Video

Lesson 2: Understanding Database Tables and Records

SQL Server beginners will learn about tables and definitions of data types, properties, keys, etc. in this second video. Find out how table rows, columns, and fields interrelate and whether columns can be empty. Download the Video

About Me

By profession I am a Database Administrator (DBA) with total 13 yrs. of experience in the field of Information Technology, out of that 9 yrs as SQL DBA and last 3 years in IBM System i/iSeries and DB2 LUW 9. I have handled Developer, plus production support roles, and I like both the roles. I love and live information technology hence the name "Techonologyyogi" Apart from that I am a small, retail investor, with small investments in India and United States in the form of Equity holdings via common stocks. Don't ask me if I have made money, I have been loosing money in stocks.