Page 1 of 1 1
Topic Options
#152178 - 2005-11-24 01:02 AM SOT: * Windows Defrag
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
* Sorta Off Topic?

Has anyone noticed a difference between running the Windows defrag utility via GUI vs the command line?

I ran the GUI defrag against a drive FOUR TIMES and it was still very fragmented. I ran the C/L tool ONCE and it cleaned up nicely. Fifth time the charm??

So, I go to some other machines, all with similar configs of the C: drive, similar age, similar use. Run the GUI on two, the CL util on 3.. the CL utility shows 0% fragmentation after one pass.. running the CL util on the two servers where I ran the GUI (analyze only mode) shows 15-20% fragmentation. Run the CL tool on those and it's down to 0%! Opening the GUI tool on all systems shows no red bars after running the CL tool on most, and just one or two on the others.

Just wondering if the C/L interface is somehow different? I wrapped a script around the CL tool to schedule nightly defrags on my servers at home.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#152179 - 2005-11-24 01:26 AM Re: SOT: * Windows Defrag
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Eh, share your script.

I use Diskeeper on all my servers and do periodic boot-time defragging. AFAIK, it is the only way to do a full defrag incuding page file.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#152180 - 2005-11-24 01:51 AM Re: SOT: * Windows Defrag
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Well did not do any extensive testing, but for my own system the command line and gui show almost the exact same report except a couple file count differences.


Quote:

COMMAND LINE version
C:\>defrag c: -a -v
Windows Disk Defragmenter
Copyright (c) 2001 Microsoft Corp. and Executive Software International, Inc.

Analysis Report

Volume size = 37.26 GB
Cluster size = 4 KB
Used space = 31.57 GB
Free space = 5.69 GB
Percent free space = 15 %

Volume fragmentation
Total fragmentation = 9 %
File fragmentation = 18 %
Free space fragmentation = 0 %

File fragmentation
Total files = 84,051
Average file size = 480 KB
Total fragmented files = 159
Total excess fragments = 786
Average fragments per file = 1.00

Pagefile fragmentation
Pagefile size = 1.50 GB
Total fragments = 1

Folder fragmentation
Total folders = 5,856
Fragmented folders = 6
Excess folder fragments = 22

Master File Table (MFT) fragmentation
Total MFT size = 92 MB
MFT record count = 90,315
Percent MFT in use = 95
Total MFT fragments = 2

You do not need to defragment this volume.


GUI version
You do not need to defragment this volume.

Volume (C:)
Volume size = 37.26 GB
Cluster size = 4 KB
Used space = 31.57 GB
Free space = 5.69 GB
Percent free space = 15 %

Volume fragmentation
Total fragmentation = 9 %
File fragmentation = 18 %
Free space fragmentation = 0 %

File fragmentation
Total files = 84,054
Average file size = 480 KB
Total fragmented files = 159
Total excess fragments = 786
Average fragments per file = 1.00

Pagefile fragmentation
Pagefile size = 1.50 GB
Total fragments = 1

Folder fragmentation
Total folders = 5,856
Fragmented folders = 6
Excess folder fragments = 22

Master File Table (MFT) fragmentation
Total MFT size = 92 MB
MFT record count = 90,318
Percent MFT in use = 95 %
Total MFT fragments = 2





 

Top
#152181 - 2005-11-24 02:29 AM Re: SOT: * Windows Defrag
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Here's the script (so far). Note that it requires a S_CONFIG and S_BIN environment var to be set. All the servers here at home have a "customize" script run on them that creates a /local folder (S_CONFIG) for config files, a /local/bin (S_BIN) for all the scripts and utilities, and adds the S_BIN folder to the path, and a few other tweaks.

The DEFRAG.INI file is simple:
[COMMON]
Services=UPS,spooler,etc... - services to stop during defrag
PRECMD=command to run before defragging
POSTCMD=command to run after defragging
[FileSys]
Path=C:\

Create as many unique FileSys definitions as needed to define your volumes. The COMMON section is completely optional. I only use it to stop the Exchange server services. It doesn't seem to be necessary, but seems to be a bit faster.

Code:
;; KixGenerated: 2005/11/23 - 13:36:03 
; Defrag.kix - Utility to manage scheduled defrag processes using the native Windows tools
; Glenn Barnas
; 2005/11/23

Break On

Dim $, $IFile, $Services, $Service, $PreCommand, $PostCommand, $Path, $LFile, $Cmd
Dim $Volumes, $Volume

$ = SetOption('Explicit', 'On')
$ = SetOption('WrapAtEOL', 'On')
$ = SetOption('NoVarsInStrings', 'On')

If %S_CONFIG% = ''
? 'System not customized! Aborting!' ? ?
Exit 1
EndIf

$IFile = %S_CONFIG% + '\defrag.ini'
$LFile = %S_CONFIG% + '\Logs\defrag.log'
Del $LFile

; Get the COMMON parameters from the ini file
$Services = ReadProfileString($IFile, 'COMMON', 'Services')
$PreCommand = ReadProfileString($IFile, 'COMMON', 'PreCmd')
$PostCommand = ReadProfileString($IFile, 'COMMON', 'PostCmd')

; Stop the defined services
If $Services
'Stopping services' ?
For Each Trim($Service) in Split($Services, ',')
Shell 'Net Stop "' + $Service + '"'
Next ; service
EndIf ; services

; Run the PreCmd if defined
If $PreCommand
'Running pre-init command.' ?
Shell $PreCommand
EndIf

; Enumerate the INI file to determine which volumes to defragment - ignore the COMMON section
$Volumes = EnumIni($IFile)
For Each $Volume in $Volumes
If $Volume <> 'COMMON'
$Path = ReadProfileString($IFile, $Volume, 'Path')
$Cmd = %COMSPEC% + ' /c ' + %SYSTEMROOT% + '\System32\defrag.exe ' + $Path + ' >> ' + $LFile
;$Cmd = %SYSTEMROOT% + '\System32\defrag.exe ' + $Path
' ' $Cmd ?
$ = RedirectOutput($LFile)
@DATE ' ' @TIME ' Starting defrag of ' $PATH ?
$ = RedirectOutput('')
Shell $Cmd
$ = RedirectOutput($LFile)
@DATE ' ' @TIME ' Complete - ' @SERROR ? ?
$ = RedirectOutput('')
EndIF

Next ; volume

; Run the PostCmd if defined
If $PreCommand
Shell $PostCommand
EndIf


; Start the defined services
If $Services
For Each Trim($Service) in Split($Services, ',')
Shell 'Net Start "' + $Service + '"'
Next ; service
EndIf ; services


$ = RedirectOutput($LFile)
? @DATE ' ' @TIME ' Defrag of @WKSTA is complete!' ?
'============================================================' ? ?
$ = RedirectOutput('')


;;
;;======================================================================
;;
;;FUNCTION EnumIni()
;;
;;ACTION Enumerates sections or keys of an INI file
;;
;;AUTHOR Glenn Barnas
;;
;;VERSION 2.0
;;
;;DATE CREATED 2003/11/17
;;
;;DATE MODIFIED 2004/10/16
;;
;;SYNTAX EnumIni($File [, $Section])
;;
;;PARAMETERS $File - REQUIRED, path/name of INI file to examine
;;
;; $Section - OPTIONAL, Section name to parse
;;
;;REMARKS Returns an array containing the sections in an INI file, or
;; an array of key names in a specified section. Errors are returned
;; for non-existant files or INI file reads. If the specified file
;; contains no sections, or the specified section contains no keys,
;; the UDF exits with error 13 and returns a null array. Thus, a For-Each loop
;; will properly perform no iterations if no data is returned.
;;
;; CAUTION - Error 13 is returned for empty files, or nonexistant sections.
;; This is not necessarily a "failure".
;;
;;RETURNS Array of sections or keys in a section
;;
;;DEPENDENCIES none
;;
;;TESTED WITH Kix 4.2+, NT4, W2K, WXP, W2K3
;;
;;EXAMPLES $Sections = EnumIni('.\config.ini')
;; $Keys = EnumIni('.\config.ini', 'Common')
;
Function EnumIni($_fSrcFile, OPTIONAL $_fSectName)

Dim $_fSectList

; die if the file doesn't exist
If Exist($_fSrcFile) = 0
Exit 2
EndIf

; Get the list of sections or keys
$_fSectList = ReadProfileString($_fSrcFile, $_fSectName, '')
; Return if error occurred
If @ERROR
Exit @ERROR
EndIf

; If len is >0, return an array of sections
; If len is 0, either no sections or keys exist, or an invalid section name was specified. Return nothing.
If Len($_fSectList) > 0
$EnumIni = Split(Left($_fSectList,len($_fSectList)-1), Chr(10))
Exit 0
EndIF

; return an error here for value not found (no sections or no keys in section)
Exit 13

EndFunction

_________________________
Actually I am a Rocket Scientist! \:D

Top
#152182 - 2005-11-24 02:33 AM Re: SOT: * Windows Defrag
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
BTW - the differences I first described were when I was experimenting with the command line tool & the gooey tool.. not related at all to the Kix script.

We use Diskeeper at work, but I don't have the budget for 10 licenses at home. So... I'm using the built-in defrag. My PageFile is on a dedicated spindle on all my servers, and set to a fixed size, so fragmentation of the PFile isn't likely. In fact, it usually shows up as either one huge file or two large (with an odd split in the middle) files when I examine it with the GUI Defrag tool.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1376 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.11 seconds in which 0.082 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org