Computer Nightly Maintenance Command File Sample

02/03/09

Permalink 07:09:23 pm, by dave Email , 399 words, 2791 views   English (US)
Categories: Windows Scripting, Batch Scripts

Computer Nightly Maintenance Command File Sample

One of the things that is very important to do if you are a computer user, is to take care of your computer and protect your data. This sample command file uses two Windows XP built-in commands XCOPY and DEFRAG to do this. XCOPY is used to backup folders / files that are specified and DEFRAG is used to clean up any fragments in the file system on your hard drive.

[More:]

::=========================================================
::== Nightly Maintenance Command File Sample
::==
::== Copyright © 2009, Dave Moats
::==
::== This sample is provided 'AS-IS', without any
::== express or implied warranty. In no event will the
::== authors be held liable for any damages arising from
::== the use of this sample code.
::==
::== Permission is granted to anyone to use this sample
::== code for any purpose, including commercial applications,
::== subject to the following restrictions:
::==
::== The origin of this code must not be misrepresented;
::== you must not claim that you wrote the original code.
::==
::== If you use this code, an acknowledgment in the
::== documentation is requested - shown below:
::==
::== Portions Copyright © 2009,
::== Dave Moats (http://www.davemoats.com/).
::==
::=========================================================

@echo off
::=========================================================
:: only back up the files that don't exist in the target
:: location or are newer
::
:: NOTE: replace the stuff between the [] with what ever is
::            appropriate for your environment
::=========================================================
xcopy [source drive]:\[source folder]\*.* [target drive]:\[target folder] /S /D /Y

::=========================================================
:: now defrag the drive that was just backed up
::
:: NOTE: replace the stuff between the [] with what ever is
::            appropriate for your environment
::=========================================================
defrag [source drive]:\ -v > defrag.txt

The easiest way to use this type of process is to create a batch (.bat) or command (.cmd) file containing the command to run and then schedule it to run nightly when you are not using your computer. To add a scheduled task go to the command line and use the AT command. Replace anything between the [] with your specific information.

at [time] /every:Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday [path to cmd file]

Pay close attention to the lines wrapping in this sample, the sample code in this post does not have any multi-line statements.

I hope this post helped out. If it didn't, I am always looking for new scripts to add so submit a request for your question or need and I will see if I can answer it.

Dave



Did you like this post? If so, Share it!  del.icio.us digg reddit slashdot this article Facebook Twitter MySpace Email



Pingbacks:

No Pingbacks for this post yet...

This post has 14 feedbacks awaiting moderation...

Scripts

This is somewhere I can post interesting snippets as I come across them. Hopefully some folks out there will find this helpful.

Search

Follow Me:

Misc

Who's Online?

  • Guest Users: 2

powered by b2evolution free blog software