Reputation: 21
This is my first question on StackOverflow, so please be kind ;); I have several computers to backup at different times, each computer has from 2 to 30 users, I want to backup Desktop, Documents and Favorites folders of a specific computer in the network.
Originally, I tried to use XCOPY
, but due to the length of folder paths it could not be done, so I used ROBOCOPY
instead, but I'm stuck. Here is what I have:
SET source=c:\testA\Users
SET dest=c:\testB
rem Desktop folder backup
for /D %%G in (%source%\*) DO (
if exist "%%G\Desktop" ROBOCOPY /e /s /MIR /copyall "%%G\Desktop" "%dest%\%%G\Desktop" )
This command can't create the destination folder %dest%\%%G\Desktop
at run time this is like : c:\testb\c:\testA\Users\"current username from for index %%G"\Desktop
.
It gives me error on destination folder: "syntax of file name, dir name or volume name is incorrect."
Theoretically the command itself works, apart from dest folder, but maybe I am missing something. Any ideas?
Upvotes: 0
Views: 1180
Reputation: 21
I wanted to answer my own question because of the length of the code. I managed to get things working except for excluding directories i wanted to be excluded...
Here i am getting source and destination from user input:
SET /p source="Hostname : "
SET /p dest="Destination path : "
SET /p _OS="a for XP b for W7 backup : "
echo "you chose %_OS%"
IF condition to get correct Windows7 folders path based on previous choice:
IF %_OS%==b (
SET source=%source%\c$\Users
pause
echo !source!
echo %dest%
pause
FOR condition to loop through User folders:
FOR /D %%G in (!source!\*) DO (
if exist %%G\Desktop ROBOCOPY %%G\Desktop %dest%\%%G\Desktop /XD !source!\admin /e /s /copy:datsou
)
PAUSE
when the code is executed !source!\admin gets the correct path to be excluded, but robocopy just copies it anyway. I also tried to specify the path : "\computer1\c$\Users\admin" with or without quotes, same effect, the path is not exlcuded.
Any ideas???
Upvotes: 1