-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestore.bat
executable file
·144 lines (127 loc) · 3.91 KB
/
Restore.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@echo off
rem Author: Samuel Jero <[email protected]>
rem Date: 12-24-2013
rem
rem Copyright (C) 2013 Samuel Jero
rem
rem This program is free software: you can redistribute it and/or modify
rem it under the terms of the GNU General Public License as published by
rem the Free Software Foundation, either version 3 of the License, or
rem (at your option) any later version.
rem
rem This program is distributed in the hope that it will be useful,
rem but WITHOUT ANY WARRANTY; without even the implied warranty of
rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
rem GNU General Public License for more details.
rem
rem You should have received a copy of the GNU General Public License
rem along with this program. If not, see <http://www.gnu.org/licenses/>.
rem Configuration
set BACKUPDIRECTORY=ComputerBackups
set PROFILEDIRECTORY=%HOMEPATH%
set PROFILEDRIVE=%HOMEDRIVE%
set LOGFILE=restore.log
set THREADS=2
echo Restore Script...
rem Set working directory to current directory
%~d0
CD %~dp0
rem We need UAC permissions to do backups because Windows is stupid...
rem inspired by http://stackoverflow.com/questions/7044985/
rem how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-admin-rights/12264592#12264592
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (shift & goto gotPrivileges)
ECHO.
ECHO **************************************
ECHO Because Windows is stupid, we require
ECHO additional priviledges to restore your
ECHO system. Attempting to elevate privileges.
ECHO You will see a UAC prompt shortly...
ECHO **************************************
rem Re-execute this script with elevated privileges causing UAC prompt
setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
"%temp%\OEgetPrivileges.vbs"
exit /B
:gotPrivileges
setlocal & pushd .
rem Look for needed programs
ROBOCOPY 2> NUL > NUL
if %ERRORLEVEL%==9009 (
echo.
echo.
echo The robocopy utility is not available on this machine.
echo This utlity is required for sucessful restore.
echo Please download it from the link below or contact
echo your system administrator.
echo http://edi.idglabs.net/?p=2737
PAUSE
exit 255
)
rem Show Restore Warning
echo WARNING: THIS IS A RESTORE SCRIPT. IT WILL REPLACE ALL DATA WITH THE BACKUP COPY
PAUSE
echo.
echo.
rem Ask for Drive
set /P DRIVE=What Drive Would You Like to Restore from:
set DRIVE=%DRIVE::=%
set DRIVE=%DRIVE: =%
If not exist %DRIVE%: (
echo Couldn't find drive to restore from
PAUSE
goto :eof
)
rem Setup Variables
set BACKUP="%DRIVE%:\%BACKUPDIRECTORY%"
set BASE="%PROFILEDRIVE%\%PROFILEDIRECTORY%"
rem check for backup Directory
If not exist "%BACKUP%\Profile" (
echo.
echo.
echo Backup Directory does not exist!
echo Please re-check your backup drive.
PAUSE
goto :eof
)
rem Display date and prompt
If exist "%BACKUP%\date.txt" (
echo This backup is from:
type "%BACKUP%\date.txt"
)
set /P ANSWER=Do You Want to Restore THIS Backup [Y/N]?
echo "%ANSWER%"
If NOT "%ANSWER%"=="Y" If NOT "%ANSWER%"=="y" (
echo Aborting...
PAUSE
goto :eof
)
rem do restore
If not exist "%BACKUP%\Profile" mkdir "%BACKUP%\Profile"
ROBOCOPY "%BACKUP%\Profile" "%BASE%" /S /E /B /R:2 /W:2 /COPYALL /MIR /XJ /SECFIX /TIMFIX /LOG+:%LOGFILE% /TEE /MT:%THREADS%
set A=%ERRORLEVEL%
rem check for errors
If %A% GTR 3 (
echo .
echo .
echo Restore Failed
echo At Profile Restore
echo Return Code: %A%
PAUSE
goto :eof
) Else (
echo .
echo .
echo Restore Completed Successfully
PAUSE
goto :cleanup
)
:cleanup
rem Delete Scripts
del /Q "%temp%\OEgetPrivileges.vbs" 2> NUL