Batch File to Restore data

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kwesmc1
Posts: 4
Joined: 05 Aug 2016 15:49

Batch File to Restore data

#1 Post by kwesmc1 » 05 Aug 2016 15:57

My batch file to restore data backup from a Windows 7 to a Windows 10 environment results in "Can't find specified path" Error.
Can someone please help, thanks.

Code: Select all

:: Version 3 includes Word and Excel MRU Documments and the Templates folder backup and restoration.

@echo on

cd \

:: Configure Wallpaper

@ECHO OFF

:choice
set /P c=Are you migrating data "from" a Windows 7 computer[Y/N]?
if /I "%c%" EQU "Y" goto :7
if /I "%c%" EQU "N" goto :XP
goto :choice
:XP
xcopy "%cd%\%username%\wallpaper\wallpaper1.bmp" "%userprofile%\AppData\Roaming\Microsoft\Windows\Themes\" /E /Y
reg add "HKCU\Control Panel\Desktop" /v Wallpaper /f /t REG_SZ /d %userprofile%\AppData\Roaming\Microsoft\Windows\Themes\wallpaper1.bmp
RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True

goto :Continue

:7

xcopy "%cd%\%username%\background\*.*" "%userprofile%\AppData\Roaming\Microsoft\Windows\Themes\" /E /Y

regedit.exe /s "%cd%\%username%\background.reg"

RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True

:Continue


xcopy "%cd%\%username%\Desktop\*.*" "%userprofile%\Desktop\" /E /Y
xcopy "%cd%\%username%\Favorites\*.*" "%userprofile%\Favorites\" /E /Y

:: Windows 7

xcopy "%cd%\%username%\My Documents\*.*" "%userprofile%\Documents\" /E /Y
xcopy "%cd%\%username%\My Pictures\*.*" "%userprofile%\Pictures\" /E /Y
xcopy "%cd%\%username%\My Music\*.*" "%userprofile%\Music\" /E /Y
xcopy "%cd%\%username%\My Videos\*.*" "%userprofile%\Videos\" /E /Y
xcopy "%cd%\%username%\UProof" "%userprofile%\AppData\Roaming\Microsoft\UProof\" /E /Y
xcopy "%cd%\%username%\Signatures" "%userprofile%\AppData\Roaming\Microsoft\Signatures\" /E /Y
xcopy "%cd%\%username%\Templates" "%userprofile%\AppData\Roaming\Microsoft\Templates\" /E /Y
xcopy "%cd%\%username%\*.nk2" "%userprofile%\AppData\Roaming\Microsoft\Outlook\" /Y

:: GC C: Drive Directories

xcopy "%cd%\%username%\exchange\*.*" "c:\exchange\" /E /Y
xcopy "%cd%\%username%\123data\*.*" "C:\123data\" /E /Y
xcopy "%cd%\%username%\exceldata\*.*" "C:\exceldata\" /E /Y
xcopy "%cd%\%username%\ppdata\*.*" "C:\ppdata\" /E /Y
xcopy "%cd%\%username%\worddata\*.*" "C:\worddata\" /E /Y
xcopy "%cd%\%username%\wpdata\*.*" "C:\wpdata\" /E /Y
xcopy "%cd%\%username%\dbdata\*.*" "C:\dbdata\" /E /Y

:: Restore Drivemappings

regedit.exe /s "%cd%\%username%\Drivemappings.reg"
RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True

:: Restore IE Homepage

regedit.exe /s "%cd%\%username%\homepage.reg"

:: Restore Word & Excel MRU document history

regedit.exe /s "%cd%\%username%\word2007MRU.reg"
regedit.exe /s "%cd%\%username%\word2010MRU.reg"
regedit.exe /s "%cd%\%username%\excel2007MRU.reg"
regedit.exe /s "%cd%\%username%\excel2010MRU.reg"

:: Gathers System Info and Patches and places file in the backup folder

@echo off

systeminfo >"%cd%\%username%\%Computername%SysInfo.txt"

wmic systemenclosure get serialnumber >>"%cd%\%username%\%Computername%SysInfo.txt"

ipconfig /all >>"%cd%\%username%\%Computername%SysInfo.txt"

wmic qfe get Hotfixid >"%cd%\%username%\%Computername%MSPatches.txt"


START CMD /C "ECHO Restore now complete.  It is recommended that you verify your data was restored successfully. Please watch for customized folder names on C:\ for this batch only copies standard GC folders.  You may need to log off and back on for the wallpaper and drive mappings to update.  && PAUSE"

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch File to Restore data

#2 Post by aGerman » 05 Aug 2016 17:05

Code: Select all

cd \

... changes the working directory to the root folder of the current drive.
%cd%\%username% does probably not exist. Try %userprofile% instead.

Regards
aGerman

kwesmc1
Posts: 4
Joined: 05 Aug 2016 15:49

Re: Batch File to Restore data

#3 Post by kwesmc1 » 06 Aug 2016 10:43

Thank you, I will give that a try.

kwesmc1
Posts: 4
Joined: 05 Aug 2016 15:49

Re: Batch File to Restore data

#4 Post by kwesmc1 » 06 Aug 2016 17:50

No, sorry that did not work. Any other ideas?
Thanks,

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch File to Restore data

#5 Post by foxidrive » 06 Aug 2016 22:02

kwesmc1 wrote:Any other ideas?
Thanks,


Your description of the error doesn't show us where it is happening and you can help to resolve it for yourself with a simple debugging step.
1) Place a pause command after the first line that copies files and then run your batch script

If there is no error message and the files copy fine, then put another pause command lower down after another line that copies files. Repeat this until you can isolate where the error first occurs. The lines above the pause command is where a problem is.

If you can let the forum know which line is causing an error then people can give you more targeted advice.

Another debugging step you can help with:
2) When you isolate the line that causes errors then place a echo at the very beginning of that line and rerun your batch script. It will show you exactly what is being run in that line when the pause stops the script: then you can carefully read the paths and commands to help show you where the problem is.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch File to Restore data

#6 Post by aGerman » 07 Aug 2016 05:32

Run...

Code: Select all

@echo off &setlocal
cd \
echo "%cd%\%username%"
if exist "%cd%\%username%\" (echo exists.) else echo does not exist.
pause

Regards
aGerman

kwesmc1
Posts: 4
Joined: 05 Aug 2016 15:49

Re: Batch File to Restore data

#7 Post by kwesmc1 » 07 Aug 2016 10:07

Ok, thanks. I will give that a try and let you know.

Post Reply