Computer Nightly Maintenance Command File Sample
02/03/09
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.
::=========================================================
::== 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
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:
Categories
- All
- Web Technologies (2)
- PHP (1)
- Windows Scripting (37)
- Batch Scripts (13)
- Wsh Scripts (23)
Archives
- December 2009 (2)
- March 2009 (2)
- February 2009 (3)
- January 2009 (2)
- December 2008 (4)
- November 2008 (1)
- October 2008 (1)
- February 2008 (1)
- December 2007 (3)
- July 2007 (1)
- April 2007 (1)
- February 2007 (2)
- More...
Misc
Who's Online?
- Guest Users: 2




