# Use of Xcopy to backup emails



## Telegraph Sam (Jun 12, 2009)

1. I am trying to create a batch file using *xcopy* to backup stored emails, having identified where the database hides in my C: drive. To save time I want to do this on an incremental or differential (difference?) basis rather than xcopy the whole lot every time. But I find the various switches or parameters that can be used with xcopy confusing. /A and /M affect the "attributes" (??) - is one of these what you use? Or am I limited to the /D date switch which would be less flexible? Or something else? I use Windows XP Home but would do this via the DOS command prompt window.

2. Ditto my Address Book except that I can't find where it lives. Instead I have "exported" it to a folder where I can find it / the copy. However this takes the form of just one file. I suspect that this contains just an alphabetical list of the contacts whilst I want to preserve the structure of the (sub) folders in my database. Can this be done - or do I have to take this problem to the email forum?


----------



## TheOutcaste (Aug 8, 2007)

Just use */D* without specifying a date. That will only copy a file if it's newer than the backup, meaning the modified date is newer.

*Xcopy /CDY* should do the trick. *C* continues if there is an error, *Y* suppresses the prompt to overwrite an existing file.

You didn't say what email program you are using, I'm guessing Outlook Express. The Address book is a *.wab* file (*W*indows *A*ddress *B*ook) stored here:

```
C:\Documents and Settings\<user name>\Application Data\Microsoft\Address Book
```


----------



## Telegraph Sam (Jun 12, 2009)

Thanks for helpful reply. You are correct, I forgot to say that I'm using OE.
I'll try the switches you suggested [can you run them together without repeating the /'s?]
Whilst on the subject what does the "archive" switch do / not do?

I couldn't find the Address Book where you thought it might be but I've got the exported version stored somewhere else. But I suspect without the directory structure which I am trying to preserve.


----------



## TheOutcaste (Aug 8, 2007)

With *Xcopy*, you can run the switches together.

The Archive flag is set on a file when it is created or modified. Backup programs (if using the archive flag to determine what to backup) should unset the flag when they do a full or incremental backup. The next time the backup is run, if the flag has not been set, the file has not been changed, so it can be skipped.

If you want to copy files to two locations for redundancy, that can be a problem; if the first backup unsets the flag, the second one sees nothing to copy. So some programs can be configured to not unset the Archive flag. If the last backup to run doesn't unset it however, it becomes useless for determining which files need to be backed up.

*Xcopy* by itself does not change the Archive flag, and ignores it for determining what to copy. With no switches, it copies everything except hidden and system files.
Using */A*, it will only copy files with the Archive flag set, but does not unset it. This allows you to run it again to copy to a different location.
Using */M*, it will copy files with the Archive flag set, then unsets it to indicate the file has been backed up.
In neither case will it copy hidden and system files unless the */H* switch is used.

For the address book, make sure you are looking in *Application Data\Microsoft* and not *Local Settings\Application Data\Microsoft*
Also, the *Application Data\Microsoft* folder usually has the System flag set, so if you don't have your view settings set to show System files, you won't see the folder. It's not the same setting as for Hidden files and folders.

*To change View Settings to show hidden and system files*:
In Windows Explorer, click on *Tools | Folder Options* -> *View* tab
*Check* the following:


 Display the contents of system folders
 Show hidden files and folders
*Uncheck* the following:


 Hide extensions for known file types
 Hide protected operating system files (Recommended)
You can also search the drive for **.wab* files, but be sure to enable searching hidden and system folders


----------



## Telegraph Sam (Jun 12, 2009)

Sorry I did not acknowledge your helpful explicit reply earlier. I "lost" the thread ...

I will get around to xcopying /CDY on my office PC sooner or later as you suggest including searching for the address book with system files revealed. I suspect I could achieve the same effect with "archives" but at the risk of greater complications if things go wrong.


----------



## Telegraph Sam (Jun 12, 2009)

TheOutcaste said:


> With *Xcopy*, you can run the switches together.
> 
> The Archive flag is set on a file when it is created or modified. Backup programs (if using the archive flag to determine what to backup) should unset the flag when they do a full or incremental backup. The next time the backup is run, if the flag has not been set, the file has not been changed, so it can be skipped.
> 
> ...


----------



## Telegraph Sam (Jun 12, 2009)

I thought I would be really clever and include my IE favo(u)rites in my batch driven backup routine in case of melt-down. But I can't figure out where the file hides on my C: drive. I know that you can export the file from IE to wherever you want but I want to copy the original by default. Is there a bookmark or something file lodged somewhere in Windows XP when you use IE 8?


----------



## Squashman (Apr 4, 2003)

C:\Documents and Settings\%username%\Favorites


----------



## Telegraph Sam (Jun 12, 2009)

Tks 4 instant reply. I wish all queries were as quick and easy to resolve!


----------



## Squashman (Apr 4, 2003)

Telegraph Sam said:


> Tks 4 instant reply. I wish all queries were as quick and easy to resolve!


Was a quick easy Google search. I couldn't remember myself because I have been using FireFox for the last 4 years.


----------



## TheOutcaste (Aug 8, 2007)

Use *"%UserProfile%\Favorites"* and it works on Vista and Win7 Too


----------



## Telegraph Sam (Jun 12, 2009)

Appetite whettened I decided to create batch files to back up selected other directories also. One of these contains programs that I have downloaded. Can you identify why..

c:
xcopy "C:\Program Files\*.*" H:\Iain\Backups\Programs\*.* /C /D /Y /E /F /W /EXCLUDE:"c:\Program Files\excludelist.txt"

only produces the result that DOS doesn't recognize the file "c:\Program Files\excludelist.txt"? I have experimented with different variations including removing the quotes without success. The exclude list.txt contains only \Goldmine\ which is the folder which I want to exclude.

At one point I got the program (without the exclude switch) to start copying but it seemed to stop after doing just one folder. 

The wonderful world of DOS.


----------



## TheOutcaste (Aug 8, 2007)

What program did you use to create the *excludelist.txt* file? It may have been saved as Unicode, which won't work.
Open the file in Notepad
Click *File | Save As*, and see if the *Encoding:* box is set to something other than *ANSI*


----------



## Telegraph Sam (Jun 12, 2009)

Unfortunately I can't get back to the office PC to check until next week but I wrote and saved both the bat and txt files in Notepad default. I put a pause in the batch file to see what happens and it _looks as if_ it is tripping up on the path and name of the text file and not the contents or format.


----------



## TheOutcaste (Aug 8, 2007)

Totally forgot about this one little bug with Xcopy, which still hasn't been fixed, even in Win 7
You can't use quotes around the exclude file name, so you have to use the short name for any paths with spaces, or put the file in a location with no spaces in the path:
*/EXCLUDE:C:\PROGRA~1\excludelist.txt*

If you keep the exclude file in the same folder as the batch file, or better yet, create it from the batch file when it is run, you can use this to specify the file name:
*/EXCLUDE:%~dps0excludelist.txt*
*%~dps0* uses *D*rive, *P*ath, *S*hortname of the batch file location (*%0*) without quotes (*~*).
Create the file with this:
>*%~dps0excludelist.txt Echo.\Goldmine\
*>>*%~dps0excludelist.txt Echo.\Another\*

And delete it when done.

You may want to include the */H* switch, there are a few files in the Program FIles tree that are hidden and/or system. Without /H, they will not be copied.


----------



## Telegraph Sam (Jun 12, 2009)

Pleased to report that with your modification I appear to have got the system to work (otherwise I would have given up). That is, using the simplified version involving abbreviating the path name. Unfortunately I couldn't quite follow the logic and mechanics of the advanced version - creating and deleting the excludelist, I'd have to resort to further DOS study for this ..

The task is quite a long one and I will have to do it in several bites. I am assuming that using the /D switch means that the program will effectively skip the previously backed up and unaltered files and just focus on the remainder. I don't suppose the process could be speeded up by using archive switches?

Tks.


----------



## TheOutcaste (Aug 8, 2007)

I've never tested to see if using the Archive flag would be significantly faster, and I don't know the actual mechanics of how Xcopy processes data to say for sure, but I suspect it you are right, it should be a bit faster.

To compare the dates, the Source and Destination info has to be read. To check the attribute, you only need to look at the Source info.
I believe Xcopy reads the Destination info to check for existing files so it can prompt to overwrite, rather than just trying to copy and letting the file system return an error. Seems that would be faster. If that's how it works, the Destination info is read in either case.
To check the Archive flag you have to extract and test one bit in the attribute byte of the Source file directory info.
To check the date, you have to find files with matching names, then you compare the date values, which are 64 bit (8 byte) numbers.


Get current file name
Search for match in list of destination files
Get dates for both
Compare
I'm sure this takes longer, but if Xcopy processes a directory at a time, and processes the next directory while the first is being copied, it won't make a difference, as the hard drive will be the slow link.
If Xcopy processes the entire list of files it will copy first, then there might be a performance advantage, especially if there are a lot of files in multiple folders.

One pitfall with using the Archive flag though, you have to be sure that you don't have any other programs running that modify the Archive flag, like a second backup program.
If somebody decides to test a new backup program, they could end up resetting the Archive flag on files that have been modified, and those modified versions will never get backed up until they are modified again. If you know this has happened, you can do a full backup, but if you don't know...
Or somebody could run the Attrib command and reset them. Windows doesn't have a built in tool to change the Modified date, so that's a bit harder to inadvertently change.
So to me it just seems a bit more reliable to use the date, even if it is slower.

To create the exclude file is easy.
Put the file name into a variable, using the *d*rive and *p*ath of the batch file. (*%~dp0*, See Call /? for the list of modifiers)


 Echo the list of files to be excluded, redirecting to the file.
(Group the echo statements in parentheses)
 Do the copy
 Delete the file


```
Set _ExFile=%~dp0Exclude.tmp
(Echo.FileName01
Echo.FileName02
Echo.FileName03
Echo.FileName04
Echo.FileName05
Echo.FileName06
Echo.FileName07
Echo.FileName08
Echo.FileName09
Echo.FileName10)>"%_ExFile%"
:: Do Xcopy
Del "%_ExFile%"
```


----------



## TerryNet (Mar 23, 2005)

Reopened per request.


----------



## Telegraph Sam (Jun 12, 2009)

I decided to use Xcopy to backup not just emails but all data and program files from my hard disc to external drive in case of melt-down. This appears to have worked for the pure data files but not with the program files. The problem might be that "for good measure" I included in the batch file just about all the switches "/CDYSWFHUR" and with the program files this caused some kind of gridlock: The message came up "0 files copied". I finally got it to work by reducing the switches to just /S. I would now like to modify the batch file so that it operates on an incremental / differential basis [only copies files that have been changed or added] but it is a bit confusing just what minimum combination of switches would achieve this. I could use trial and error but the number of possible permutations is exponential! May be someone knows a more rational approach.


----------

