Windows XP to Windows 7 Backup + Restore script

modem7

Honorable
Jul 1, 2013
3
0
10,510
Hey guys,

Need a bit of help. I'm trying to create a batch file that will detect if the machine is Windows 7 or Windows XP.

Once it's detected, it will find the right thing to backup (the bit I'm struggling with is the "My Documents/Documents" difference).

The reason for the script is the we are doing a lot of Windows 7 upgrades from XP, so it's useful for the staff to have some data backed up (that they haven't put on their home drive on the network) and restored.

It seems to backup My documents from XP, but it doesn't seem to restore (also, it seems to have problems backing up + restoring from Win7 to Win7).

Code:
@echo off

REM Backup Batch File

REM Created and Modified by Alex Lane

REM This script is designed to back up user files.

REM It currently has the following features:
REM Number Choice error correction.
REM Will backup (and restore): Microsoft Office custom dictionary (including outlook dictionary), Outlook Autocomplete, Outlook Signatures, Internet Explorer favourites, User "My Documents", Windows 7 jumplists, User Desktop and will list all programs installed.
REM It will also backup and restore Firefox Profile (including all plugins).
REM This script is also designed to backup user defined Wallpaper and Screensaver. However it is not designed to restore these due to probable lack of local admin rights blocking access to write to the registry.

COLOR 0e



	:: variables
			set drive=H:\private\ITBackup
			set backupcmd=xcopy /c /d /e /h /i /r /y /k /v /z
			set dircheck=H:\Private
			
	:NetworkCheck
		PING -n 1 %logonserver:~2,99%|find "Reply from " >NUL
		IF NOT ERRORLEVEL 1 goto HomeDriveCheck
		IF     ERRORLEVEL 1 goto Netfail

	:HomeDriveCheck
		dir %dircheck% >nul 2>nul
		if errorlevel 1 (
		   goto DirCheckBad
		)

		dir %dircheck% >nul 2>nul
		if not errorlevel 1 (
		    goto Start
		)

	:Netfail
		echo You do not have access to the network. Please check your connection and run this script again.
		echo.
		echo Please press any key to try again.
			pause>nul
		cls
		IF NOT ERRORLEVEL 1 goto NetworkCheck
		IF     ERRORLEVEL 1 echo Network access could not be established. Please contact IT.
		echo.
		echo Press any key to exit
		pause>nul
		exit

	:DirCheckBad
		echo Your Home Drive does not seem to exist. Please check that your H:\ drive exists and run this script again.
		echo.
		echo Please press any key to try again.
			pause>nul
		cls
		IF NOT ERRORLEVEL 1 goto HomeDriveCheck
		IF     ERRORLEVEL 1 echo Your H:\ does not seem to exist. Please contact IT.
		echo.
		echo Press any key to exit
		pause>nul
		exit


	:Start
		cls
		echo Network and Home Drive access confirmed
		echo ### Backup drive set as: %drive%
		echo.
		echo Press 1 to Backup Files 
		echo.
		echo Press 2 to Restore Files
		echo.
		echo Press 3 to Backup Wallpaper
		echo.
		echo Press 4 to Backup Firefox Profile
		echo.
		echo Press 5 to Restore Firefox Profile
		echo.
		echo Press 6 to Quit
		echo.
		
			set /p userinp=Choice #: 
			set userinp=%userinp:~0,1%
			if "%userinp%"=="1" goto 1
			if "%userinp%"=="2" goto 2
			if "%userinp%"=="3" goto 3
			if "%userinp%"=="4" goto 4
			if "%userinp%"=="5" goto 5
			if "%userinp%"=="6" goto 6
		echo '%userinp%' is not a valid choice, press any key to try again.
			
			pause>nul
		
	goto start



	:1


		echo ### Backing up files...
		echo ### Setting backup drive as: %drive%

		echo ### Backing up Custom Dictionary
			%backupcmd% "%USERPROFILE%\Application Data\microsoft\proof" "%drive%\Outlookbackup\Proof"

		echo ### Backing up Outlook Autocomplete
			%backupcmd% "%USERPROFILE%\Application Data\microsoft\outlook" "%drive%\Outlookbackup\Outlook"

		echo ### Backing up Outlook Signatures
			%backupcmd% "%USERPROFILE%\Application Data\microsoft\signatures" "%drive%\Outlookbackup\Signatures"

		echo ### Backing up Internet Explorer Favourites
			%backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"

		REM ### You now have the final countdown stuck in your head

		echo ### Backing up My Documents
			dir %USERPROFILE%\My Documents >nul 2>nul
			if errorlevel 1 (
			%backupcmd% “%USERPROFILE%\My Documents” “%drive%\My Documents”
			)

			dir %USERPROFILE%\My Documents >nul 2>nul
			if not errorlevel 1 (
			%backupcmd% “%USERPROFILE%\Documents” “%drive%\My Documents”
			)
		
		echo ### Backing up Jump Lists
			%backupcmd% "%APPDATA%\Microsoft\Windows\Recent\AutomaticDestinations" "%drive%\Jump-Lists-Backup\AutomaticDestinations"
			%backupcmd% "%APPDATA%\Microsoft\Windows\Recent\CustomDestinations" "%drive%\Jump-Lists-Backup\CustomDestinations"

		echo ### Backing up Desktop
			%backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop"

		echo ### Listing all programs installed on the computer
		
			regedit /e %temp%\regexport.txt "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"

			find "DisplayName" %temp%\regexport.txt >%temp%\regprogs.txt

			for /f "tokens=2 delims==" %%a in (%temp%\regprogs.txt) do echo %%~a >>"%drive%\installedprogs.txt"

			del %temp%\regexport.txt
			del %temp%\regprogs.txt

	goto endbackup



	:2


		echo ### Restoring files...
			echo ### Restoring files from %drive%


		echo ### Restoring Custom Dictionary
			%backupcmd% "%drive%\Outlookbackup\Proof" "%USERPROFILE%\Application Data\microsoft\proof"

		echo ### Restoring Outlook Autocomplete
			%backupcmd% "%drive%\Outlookbackup\Outlook" "%USERPROFILE%\Application Data\microsoft\outlook"

		REM ### You have lost the game

		echo ### Restoring Outlook Signatures
			%backupcmd% "%drive%\Outlookbackup\Signatures" "%USERPROFILE%\Application Data\microsoft\signatures"

		echo ### Restoring Internet Explorer Favourites
			%backupcmd% "%drive%\Favorites" "%USERPROFILE%\Favorites"

		echo ### Restoring My Documents	
			dir %USERPROFILE%\My Documents >nul 2>nul
			if errorlevel 1 (
			%backupcmd% “%drive%\My Documents” “%USERPROFILE%\My Documents”
			)

			dir %USERPROFILE%\My Documents >nul 2>nul
			if not errorlevel 1 (
			%backupcmd% “%drive%\My Documents” “%USERPROFILE%\Documents”
			)

		echo ### Restoring Desktop
			%backupcmd% "%drive%\Desktop" "%USERPROFILE%\Desktop"

	goto endrestore

	:3	
			call:ReadDesktopRegistry Wallpaper
			call:ReadDesktopRegistry SCRNSAVE.EXE
			call:ReadDesktopRegistry WallpaperStyle
			call:ReadDesktopRegistry ScreenSaveActive
			call:ReadDesktopRegistry ScreenSaveTimeOut

			xcopy /c /h /i /r /y /k /v %Wallpaper% %drive%\Wallpaper\
			xcopy /c /h /i /r /y /k /v %SCRNSAVE.EXE% %drive%\Wallpaper\Screensaver\

	goto endwallpaper


			:ReadDesktopRegistry
			FOR /F "delims=" %%A in ('reg query "HKCU\Control Panel\Desktop" /v "%~1"') DO (SET RegRead=%%A)
			FOR /F "tokens=3" %%A IN ("%RegRead%" ) DO (SET "%~1=%%A" )
			SET RegRead=""
			goto:eof


	:4
		echo ### Backing up Firefox Profile
			%backupcmd% "%USERPROFILE%\Application Data\Mozilla\Firefox\Profiles" "%drive%\Firefox\Profiles"
	
	
	goto endbackup


	:5

		echo ### Restoring Firefox Profile
			%backupcmd% "%drive%\Firefox\Profiles" "%USERPROFILE%\Application Data\Mozilla\Firefox\Profiles"


	goto endrestore




	:endbackup
			cls
		echo Backup Complete!
		echo.
		echo.
		echo.
		echo Thank you for using the IT Department's Profile autobackup facility
		echo.
		echo Your Backup is located in %drive%
		echo.
		echo Things that have been backed up:
		echo.
		DIR %drive% /A:D /O /B
		echo.
		echo Please press any key to go back to menu
			pause>nul
	goto start


	:endrestore
		cls
		echo Restore Complete!
		echo.
		echo.
		echo.
		echo Thank you for using the IT Department's Profile autobackup facility
		echo.
		echo Your Backup has been restored from %drive%
		echo.
		echo Things that have been restored:
		echo.
		DIR %drive% /A:D /O /B
		echo.
		echo Please press any key to go back to menu
			pause>nul
	goto start

	:endwallpaper
		cls
		echo Wallpaper backed up to %drive%Wallpaper\
		echo.
		echo Screensaver backed up to %drive%Wallpaper\Screensaver\ 
		echo.
		echo Thank you for using the IT Department's Profile autobackup facility
		echo.
		echo Please press any key to go back to menu
			pause>nul
	goto start


	:6
				

			cls
		echo Thank you for using the IT Department's Profile autobackup facility
		echo.
		echo Please press any key to exit
			pause>nul
	exit




Any help would be awesome - thanks!
 

modem7

Honorable
Jul 1, 2013
3
0
10,510
Aye, USMT would be fantastic, but still trying to get to grips with it unfortunately!

It's certainly on my list. But in the meantime, the batch file does most (certainly not all!) of what USMT can do, and is needed to fill in the gap whilst I do it.

Will hoever, look at the link as it looks like a great starting place for me!

Thanks!