Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch File Back Up

Status
Not open for further replies.

Keyboy

Technical User
Aug 22, 2003
193
US
Greetings,

I am running W7 Home Premium on a Dell Laptop. I have used the following bat file to back up my computer for years, however, when I tried to run it today (as a user and administrator) I got the errors below.

@Echo Off
Echo.
If exist E:\ (Echo. External USB HD ready for BackUp) else (Echo. No External USB HD detected & Goto :EOF)
Echo.
pause
Echo.
Set ToDay=%Date:~-4,4%-%Date:~-10,2%-%Date:~-7,2%
XCopy "C:\Users\%UserName%\Documents" E:\Ray_BackUp_%ToDay%\"My Documents" /I /E /S /V
XCopy "C:\Users\%UserName%\Favorites" E:\Ray_BackUp_%ToDay%\Favorites /I /E /S /V
XCopy "C:\Users\%UserName%\Desktop\*.bat" E:\Ray_BackUp_%ToDay%\Desktop /I /E /S /V
XCopy "C:\Users\%UserName%\AppData\Local\Microsoft\Windows Mail" E:\Ray_BackUp_%ToDay%\"Windows Mail" /I /E /S /V
XCopy "C:\Xnews_test 2006.06.28\*.*" E:\Ray_BackUp_%ToDay%\xNEWS /I /E /S /V
Set ToDay=
::END_OF_BATCH
Echo.
Echo.
Echo. All Done
pause

I apologize that the long lines wrapped. There are no spaces between the wrapped lines.

Here are the errors:

Invalid Switch - /\"My Documents"
Invalid Switch - /\Favorites
Invalid Switch - /\Desktop
Invalid Switch - /\"Windows Mail"
Invalid Switch - /\xNews

Any idea how to get this file to run?

Thanks for your help!
 
Your old system, I guess it was XP, stored user files on paths differently to those now in Vista and Win 7.

Much of this is due to the use of symbolic links called Junctions instead of old-fashioned directories -


You will need to work out the paths to the various directories without falling foul of some non-traversable link, and put those in the batch file.
 
Hi flyboytim,

This batch file was written for XP, however, for over a year it worked on my W7 laptop. I have installed all the updates so maybe a recent one of them changed something?

I will read through your links and see if I can make changes.

Thanks for your help!
 
Check the value of ToDay. It probably contains a space, as January only has 1 digit in it's numeric value. Quote just the entire destination path, not only the parts that you think contain spaces, something like:
Code:
XCopy "C:\Users\%UserName%\Documents" "E:\Ray_BackUp_%ToDay%\My Documents" /I /E /S /V
 
You should be able to get around the errors by wrapping the whole of the destination parameter in quotes like you've done with the source paramaters, i.e.:
Code:
XCopy "C:\Users\%UserName%\Documents" "E:\Ray_BackUp_%ToDay%\My Documents" /I /E /S /V
XCopy "C:\Users\%UserName%\Favorites" "E:\Ray_BackUp_%ToDay%\Favorites" /I /E /S /V
XCopy "C:\Users\%UserName%\Desktop\*.bat" "E:\Ray_BackUp_%ToDay%\Desktop" /I /E /S /V
XCopy "C:\Users\%UserName%\AppData\Local\Microsoft\Windows Mail" "E:\Ray_BackUp_%ToDay%\Windows Mail" /I /E /S /V
XCopy "C:\Xnews_test 2006.06.28\*.*" "E:\Ray_BackUp_%ToDay%\xNEWS" /I /E /S /V

Nelviticus
 
Actually you can shorten those a bit by using some different environment variables:
Code:
XCopy "%UserProfile%\Documents" "E:\Ray_BackUp_%ToDay%\My Documents" /I /E /S /V
XCopy "%UserProfile%\Favorites" "E:\Ray_BackUp_%ToDay%\Favorites" /I /E /S /V
XCopy "%UserProfile%\Desktop\*.bat" "E:\Ray_BackUp_%ToDay%\Desktop" /I /E /S /V
XCopy "%LocalAppData%\Microsoft\Windows Mail" "E:\Ray_BackUp_%ToDay%\Windows Mail" /I /E /S /V
Then it'll still work if you ever move your user profile.

Nelviticus
 
Thanks to all!

I tried it all and same thing. I believe it must be some sort of new security thing. I gave up and moved to robocopy.
 
Check your quotes again, you must have missed one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top