Click here to Skip to main content
15,890,123 members
Articles / Programming Languages / Visual Basic
Article

Utility to backup your folders fast

Rate me:
Please Sign up or sign in to vote.
4.59/5 (23 votes)
31 Jul 20052 min read 160.5K   2.4K   70   33
I use a procedure based on batch files to copy various versions of my project. I was a bit fed up to wait for the batch file to copy hundreads of files and wrote this small utility to speed up the process. I hope some of you will find it useful.

Sample Image - sync.png

Introduction

This utility is designed to backup a folder to another folder. It is not rocket science and not that interesting in terms of coding. However it can be useful if you want to copy your source from a machine to another or to make a quick backup. It will run a lot faster than a batch file if you repeat the command regularly.

How does this work

The program is very simple, it will copy only the files that were modified since the previous copy. It will always copy the subfolders and never ask any question. Any file or folder deleted from the source folder will also be deleted in the destination folder.

How to install

Just have to copy sync.exe into your windows\system32 folder.

How to run?

Just type SYNC <source folder> <destination folder> in your DOS command prompt window or batch file.

WARNING

This program despite being very simple is potentially lethal. Used with bad parameters, you can probably manage to erase your hard disk in no time at all. Use it only at your own risks.

Points of interest

Nothing very interesting in this program, this is a DOS utility not a code exploit. For each folder in the source tree, the utility gets a list of files and folders to copy to the destination. To avoid multiple lookups, the list of files in the destination folder are read once as well into a hash table. The program uses the FileSystemInfo.LastWriteTimeUtc to compare the source and destination files. It then copies the new or modified files and deletes the files that were deleted since the last backup. Again be careful how you use this utility, the deletion does not ask any questions.

Revisions

  • 31st July 2005
    • First release.
  • 1st August 2005
    • Force the copy when the files are read-only.
    • Move to .NET framework 1 (was 2 so far).

Questions to readers

When I use the IO.File.Copy method, the FileSystemInfo.LastWriteTimeUtc is modified one or two seconds forward. Anyone knows how to make the date of last write to stay consistent from source to destination?

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
France France
I am a French programmer.
These days I spend most of my time with the .NET framework, JavaScript and html.

Comments and Discussions

 
GeneralConverted the code to C# and changed the date comparison to SHA CheckSum Pin
David Kittell23-Apr-13 6:55
David Kittell23-Apr-13 6:55 
GeneralRe: Converted the code to C# and changed the date comparison to SHA CheckSum Pin
Pascal Ganaye26-Apr-16 7:42
Pascal Ganaye26-Apr-16 7:42 
GeneralMicrosoft's SyncToy Pin
Jalapeno Bob9-Sep-10 11:54
professionalJalapeno Bob9-Sep-10 11:54 
GeneralMy vote of 1 Pin
Yury300024-Aug-09 14:59
Yury300024-Aug-09 14:59 
GeneralRe: My vote of 1 Pin
Pascal Ganaye15-Sep-11 2:16
Pascal Ganaye15-Sep-11 2:16 
GeneralThanks! Pin
Tonny Vaes24-Aug-08 2:45
Tonny Vaes24-Aug-08 2:45 
QuestionConverting to c# Pin
chrisclarke1122-Mar-08 3:07
chrisclarke1122-Mar-08 3:07 
AnswerRe: Converting to c# Pin
Pascal Ganaye15-Sep-11 2:20
Pascal Ganaye15-Sep-11 2:20 
Generalpeogram to copy to cd_we or usb Pin
syriast29-Jul-06 22:46
syriast29-Jul-06 22:46 
GeneralRe: peogram to copy to cd_we or usb Pin
Pascal Ganaye30-Jul-06 7:58
Pascal Ganaye30-Jul-06 7:58 
GeneralRobocopy not so good Pin
Manuel JD Alves26-Feb-06 22:54
Manuel JD Alves26-Feb-06 22:54 
GeneralRobocopy seems faster Pin
anadem5-Aug-05 14:15
anadem5-Aug-05 14:15 
GeneralRe: Robocopy seems faster Pin
Pascal Ganaye6-Aug-05 4:46
Pascal Ganaye6-Aug-05 4:46 
QuestionNice, but is this any better than &quot;robocopy&quot;? Pin
mikestrat3-Aug-05 3:10
mikestrat3-Aug-05 3:10 
AnswerRe: Nice, but is this any better than &quot;robocopy&quot;? Pin
david.price.dev3-Aug-05 8:48
david.price.dev3-Aug-05 8:48 
GeneralRe: Nice, but is this any better than &quot;robocopy&quot;? Pin
Terence Wallace10-Aug-05 9:16
Terence Wallace10-Aug-05 9:16 
GeneralRe: Nice, but is this any better than &quot;robocopy&quot;? Pin
david.price.dev10-Aug-05 10:15
david.price.dev10-Aug-05 10:15 
GeneralRe: Nice, but is this any better than &quot;robocopy&quot;? Pin
cornejoserrano12-Sep-05 22:14
cornejoserrano12-Sep-05 22:14 
GeneralRe: Nice, but is this any better than &quot;robocopy&quot;? Pin
raviaw23-Feb-06 9:40
raviaw23-Feb-06 9:40 
GeneralDestination issues with +/-RW media. Pin
Mike Whitenton2-Aug-05 21:56
Mike Whitenton2-Aug-05 21:56 
I'm glad to see any improvements to the XCOPY command. I sure will be experimenting with SYNC. Thanks

I know this isn't exactly on topic but it is very closely related so I thought I'd pass my experience along.
I have several customers that wanted to use CD and DVD +/-RW media for backup purposes on their entry level fileservers. Most drive companies claim you can do exactly that in their documentation. Well, it depends on how you are doing your backups.
XCOPY is touted as being the first choice in backing up folders to safeguard your data. The concept is something like this. Write a batch file containing a series of XCOPY commands that will copy your data to the destination media. Setup a scheduled task to launch the batch file at the appropriate time. Pop in a formatted CD or DVD +/-RW disk in the drive and you are good to go.
Sounds easy enough until your customers start complaining about unusable disks after a few weeks that have been used only a few times. Upon examining the disk you may see a white band burned into the media near the hub of the disk. What's going on here? Well, it's the choice of format and media that is causing the damaged disks to be over burned and worn-out.
The RW format/media is only good for 1000 writes (a fact not expressed with great effort by drive manufacturers). XCOPY updates the directory/FAT countless times during a backup of containing tens of thousands of files and subfolders. The result is the area of the disk containing the directory structure will get written so many times that it exceeds the design limits of the RW media and the disk becomes unusable. Flash Pen drives also suffer from limited write ability so you are not out of the woods with these either.
What are some solutions? One way is use a backup utility that will copy the files all-at-once thus reducing the writes to the directory structure. PKZIP and other will allow entire folder structures to be compressed into a single file.
The other method is to choose a media that was designed specifically for large numbers of writes. Removable hard disks are one obvious choice. The problem here is the cost of the media is the cost of an entire hard drive plus caddy. (15 or 20 hard drives for entire backup cycle of daily, weekly and monthly full backups). The next more practical choice is DVD-RAM media. DVD-RAM is spec'ed for 100,000 writes and was originally designed for use in the national archives as backup/archive media. Current prices are $5-$10 each for DVD-RAM but when you consider that the RW media may be failing within a few backups, the DVD-RAM media becomes easier to justify.
I know what some of you are thinking about now. "Why haven't I heard about this before?" Just like me early on, I hadn't tried it and assumed what I was hearing was the truth. But having seen rapidly increasing stacks of damaged media I got to the truth.
I now recommend removable hard drives or NAS if the budget allows. But the best tradeoff for price vs. reliability is DVD-RAM. Tape drives are another choice but the media can be much more costly and from my experience not reliable enough.
The next time you go to your local store and try to buy DVD-RAM media, you will likely be surprised how few are stocked as compared to RW media. This in part is a reflection of how few people are actually backing up with XCOPY and RAM media. It is more likely a reflection of how few people are actually backing up their data. Some of course are using programs designed to write all-at-once to do backups. But scheduled backup utilities almost never come with RW drives.
Hope you find this useful and save yourself some grief.
QuestionAnyone understand this bug ? Pin
Pascal Ganaye1-Aug-05 1:09
Pascal Ganaye1-Aug-05 1:09 
AnswerRe: Anyone understand this bug ? Pin
umeca741-Aug-05 7:22
umeca741-Aug-05 7:22 
GeneralRe: Anyone understand this bug ? Pin
Pascal Ganaye1-Aug-05 7:46
Pascal Ganaye1-Aug-05 7:46 
GeneralRe: Anyone understand this bug ? Pin
John M. Drescher1-Aug-05 10:58
John M. Drescher1-Aug-05 10:58 
AnswerRe: Anyone understand this bug ? Pin
John M. Drescher1-Aug-05 7:34
John M. Drescher1-Aug-05 7:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.