Solved

Script to DEFRAG harddrive

Posted on 2007-11-15
9
1,569 Views
Last Modified: 2008-02-01
I want to schedule a weekly DEFRAG on our server's harddrive. I don't have a problem with scheduling the task but need to know the best way to implement this. My last experience with batch files was with DOS 6. I have seen various types of batch jobs for Server 2003 (.BAT, .CMD, .VBS) but don't understand the differences between them and which is the best to use.

What I want to do is stop IIS, run the defrag and then restart IIS. What is the command for the DEFRAG? What reccommedations?
0
Comment
Question by:DerekWatling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 58

Expert Comment

by:tigermatt
ID: 20296707
Hi there

You would need to make a batch file (.BAT) with the following commands in it (see attached script)

I'm not quite sure why you want to stop and start the IIS service though.

Hope this helps
-tigermatt

net stop W3SVC
defrag C: /f
net start W3SVC

Open in new window

0
 
LVL 5

Accepted Solution

by:
pavaneeshkumar earned 90 total points
ID: 20296720
put following code in a batch file

REM Stop IIS Server
IISReset /stop

REM Do Defragmentation
defrag c: -v

REM START IIS Server
IISReset /stop
0
 
LVL 5

Expert Comment

by:pavaneeshkumar
ID: 20296727
IISReset is a command line utility shipped with IIS
 For more details on IISReset check this article

http://support.microsoft.com/kb/317584
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 5

Expert Comment

by:pavaneeshkumar
ID: 20296749
tigermatt:
as i understand W3SVC  (www) Service is a component of IIS stooping this is not going to stop the IIS Server.

Please correct if i m wrong.
0
 

Author Comment

by:DerekWatling
ID: 20296926
The site is using a GIS system and MySql. I want to stop IIS so these files can be properly defraged. I will try this over the weekend when the site is quiet.
0
 
LVL 25

Assisted Solution

by:imitchie
imitchie earned 90 total points
ID: 20297268
in that case (mysql+iis), use the code far below. stop iis before mysql, but start it after
(note: net stop w3svc alone won't work, nor will net stop iisadmin, unless you knew all the iisadmin subcomponents to stop in sequence)

also in answer to cmd vs bat vs vbs, cmd and bat are the same and use the command shell, which is NOT the old dos command.com, but close in ways.  .vbs, .js are newer windows scripts using vbscript, javascript languages which can interact with windows objects, like Outlook, Excel, SQL etc.  Windows 2008/Vista come with Monad, which is even more powerful.
REM Stop IIS Server
IISReset /stop
net stop mysql
 
REM Do Defragmentation
defrag c: -v
 
REM START IIS Server
net start mysql
IISReset /stop

Open in new window

0
 
LVL 2

Assisted Solution

by:pinkisthenewblue
pinkisthenewblue earned 20 total points
ID: 20303767
N.B Don't use "chkdsk c: /f" - since this is a boot volume it will just prompt you to schedule one.
0
 
LVL 5

Expert Comment

by:pavaneeshkumar
ID: 20307077
please change  /stop in last line to /start

REM Stop IIS Server
IISReset /stop

REM Do Defragmentation
defrag c: -v

REM START IIS Server
IISReset /start
0
 

Author Comment

by:DerekWatling
ID: 20310643
Hadn't noticed that ;-) but I typed it in rather than copying and pasting so I had it right.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question