Created
January 12, 2014 21:37
-
-
Save glallen01/8390905 to your computer and use it in GitHub Desktop.
user backup batch script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
SETLOCAL | |
SET _fileserver=\\file-server\user | |
SET _target=\\file-server\user\%USERNAME% | |
SET _source=%USERPROFILE% | |
SET _options=/MIR /MT /xA:T /XJ /A:N /R:1 /W:2 | |
GOTO MENU1 :: choose robocopy runtime options | |
:JUMP1 | |
GOTO MENU2 :: choose which profile to backup | |
:JUMP2 | |
GOTO MENU3 :: choose output destination | |
:JUMP3 | |
GOTO MENU4 :: confirm all options | |
GOTO END | |
:EXECUTE | |
:: robocopy %_source% %_target% %options% | |
for /f "tokens=1,2* delims==" %%A in ('SET __userdir.') do ( | |
:: %%A is the __userdir.* var, %%B the user profile directory | |
echo robocopy C:\Users\%%B %_target%\%COMPUTERNAME%\%%B %_options% | |
) | |
goto END | |
:MENU1 | |
:: choose robocopy runtime options | |
ECHO. | |
ECHO 1. Run with no restart (local disk or LAN) | |
ECHO 2. Run with restart and throttle (WAN) | |
ECHO. | |
:: CHOICE /N /C:123 %1 | |
SET /P choice="Choice (1,2)?" | |
if not '%choice%' == '' call set choice=%%choice:~0,1%% | |
if '%choice%'=='1' goto JUMP1 | |
if '%choice%'=='2' ( | |
set _options=%_options% /ZB /IPG:10 | |
goto JUMP1 | |
) ELSE ( | |
goto ERROR | |
) | |
:MENU2 | |
:: choose which profile to backup | |
:: lists available profiles | |
for /f "tokens=*" %%G in ('dir /ad /b "C:\Users\"') do ( | |
set __userdir.%%G="%%G" | |
) | |
:: delete the following from __userdir.* | |
SET __userdir.Administrator= | |
SET __userdir.All Users= | |
SET __userdir.Default= | |
SET __userdir.Default User= | |
SET __userdir.Public= | |
echo. | |
echo **** The following profiles will be sent to backup: | |
echo. | |
for /f "tokens=1,2* delims==" %%A in ('SET __userdir.') do ( | |
:: %%A is the __userdir.* var, %%B the user profile directory | |
echo C:\Users\%%B | |
) | |
goto JUMP2 | |
:MENU3 | |
:: choose output destination | |
echo. | |
echo Press enter for default destination: %_fileserver% | |
echo or type in target directory for backup... | |
SET /P choice=": " | |
if '%choice%'=='' ( | |
SET _target=%_fileserver% | |
) else ( | |
SET _target=%choice% | |
) | |
echo Using: %_target% | |
echo. | |
SET /P confirm="'Y' to confirm, or 'N' to re-enter (use caps)? " | |
if '%confirm%'=='Y' ( | |
echo. | |
echo **** Confirmed target directory: %_target% | |
GOTO JUMP3 | |
) else ( | |
GOTO :MENU3 | |
) | |
GOTO :END | |
:MENU4 | |
:: confirm all options | |
echo. | |
echo. *** about to run the following: | |
echo. | |
for /f "tokens=1,2* delims==" %%A in ('SET __userdir.') do ( | |
echo robocopy C:\Users\%%B %_target%\%COMPUTERNAME%\%%B %_options% | |
) | |
echo. | |
echo. | |
SET /P choice="Continue (y,n)?" | |
if not '%choice%' == '' call set choice=%%choice:~0,1%% | |
if '%choice%'=='y' ( | |
ECHO "<<<----EXECUTING---->>>" | |
GOTO EXECUTE | |
) | |
if '%choice%'=='n' ( | |
ECHO "---->>>ABORTING<<<----" | |
goto END | |
) ELSE ( | |
goto ERROR | |
) | |
:ERROR | |
echo Invalid input, try again. | |
:END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment