When I run defrag in command prompt is there any way to gracefully stop the process before it finishes?
Does killing the task in TM cause any problems if it is in the middle of moving a file?
Windows 7 Pro 64bit
In theory, it should be safe to just terminate the program (in your case you can use CTRL-C) because an effort is made in the design of the Microsoft Disk Defragmenter application to prevent data loss in the event of an unexpected interruption. This is documented on Microsoft's web site as follows:
The following steps are the processes by which Disk Defragmenter and file system defragment an NTFS volume and update the MFT. 1. Locate the fragments of each file throughout the disk. 2. Copy the fragments to contiguous locations on the disk. 3. Verify that the copy is an exact duplicate of the original file. 4. Update the MFT in NTFS with the new location of the beginning of the file. 5. Free up the space previously used by the file.
Microsoft - How Disk Defragmenter Works
(the above text can be found under "Updating the Master File Table")
Essentially, the data is copied to new sectors, the pointers to the data that was moved are updated to point to these new sectors, and then the old sectors are freed as a result. This is a very safe approach to use in case there is a crash because in a worst-case-scenario (like a crash into a blue screen) you'd have two copies of the same data, one on unallocated sectors, and the other on allocated sectors. From the perspective of reading the data, it will appear the same either way.
Additionally, there are many improvements that can be made to the Disk Defragmentation techniques that Microsoft uses (which are already more than adequate for many people), and a variety of alternative products are examined and compared in great detail here:
Defragger (from Roedy Green's Java Glossary)
This thread has a lot of helpful information about whether there are dangers to disks that were defragmenting during power failure (while not identical to your situation, you'd still be abruptly halting the program -- as the commenter kindly pointed out, if the system can recover from a hardware interruption, a software interruption probably won't hurt).
It's seems as though
defrag is following through with the journaling that occurs during normal use.