Solved

Script to DEFRAG harddrive

Posted on 2007-11-15
9
1,567 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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