Automating Defrag.exe | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Automating Defrag.exe

Isn’t there any way to automate Windows defrag? Isn’t there any undocumented parameters for DEFRAG.EXE? CanadaDBA
I found these and am going to test the second one. http://searchwincomputing.techtarget.com/originalContent/0,289142,sid68_gci1097119,00.html http://snippets.dzone.com/posts/show/3925 CanadaDBA
This is very difficlut to do.
There is a 3rd party tool for this
http://www.sql-server-performance.com/software_spotlights/da_diskeeper_2007.asp —————————————-
Contributing Editor, Writer & Forums Moderator
http://www.SQL-Server-Performance.Com Visit my Blog at
http://dineshasanka.spaces.live.com/

The autodefrag.py in the second option does not run under Windows and needs another program to be installed. But using the first solution, I created the following batch file that can be scheduled and run.
@Echo off
SET DestPath=C:UtilsDefrag.out.txt
Date /T >> %DestPath%
Time /T >> %DestPath%
Echo ——————————- >> %DestPath%
Defrag C: -f -v >> %DestPath%
Echo ***Finished*** >> %DestPath%
Time /T >> %DestPath%
Echo ——————————- >> %DestPath%
Echo * * * * * * * * * * * * * * * * >> %DestPath%
Echo ——————————- >> %DestPath%
SET DestPath= CanadaDBA
Similar info…check the following… http://searchwincomputing.techtarget.com/originalContent/0,289142,sid68_gci1097119,00.html
http://support.microsoft.com/kb/555098
http://support.microsoft.com/kb/179306
MohammedU.
Microsoft SQL Server MVP
Moderator
SQL-Server-Performance.com All postings are provided “AS IS” with no warranties for accuracy.

Are you trying to schedule the Windows defrag using SQL Server agent jobs?
Not a good practice based on my experience, you could make use of Windows scheduler in this case but if the SQL SErver is accessed 24/7 then you wouldn’t have much benefit with defrag tool, as suggested by Dinesh you could take up such third party tools. Satya SKJ
Microsoft SQL Server MVP
Writer, Contributing Editor & Moderator
http://www.SQL-Server-Performance.Com
@http://www.askasqlguru.com/ This posting is provided AS IS with no rights for the sake of knowledge sharing. Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it.
You are right Satya. I had Diskeeper in previous work place but in my new job, we don’t have. Most of SQL Servers in our environment are not accessed 24/7. I am trying to schedule the batch file under Windows for these servers until company purchases a tool. Thanks, CanadaDBA
Go ahead as long as you are not running during busy times, but in all cases diskkeeper is the best tool. Satya SKJ
Microsoft SQL Server MVP
Writer, Contributing Editor & Moderator
http://www.SQL-Server-Performance.Com
@http://www.askasqlguru.com/ This posting is provided AS IS with no rights for the sake of knowledge sharing. Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it.
I would also strongly suggest the use of a third party tool instead of relying on windows defrag for this job . And, again, Diskeeper 2k7 is also my recommendation because it does its intended job well and is easy to use.
]]>