:: ============== Change <Username> into your inlog name and <BackupDrivePath> into the Driveletter:\Path Path=backup path. ==================
:: Example: Username=Mickey
::          BackupDrivePath=X:\PersBackup
set Username=<Username>
set BackupDrivePath=<BackupDrivePath>
:: ===========================================================================================================================================
:: No other changes are necessary below!

@title Copy the C:\Users\%Username%\*.* dir to a backup location %BackupDrivePath%\*.*
mode con cols=170 lines=30
echo off
echo Start: %time%
:: ********************************************************************************************************************************************
::   --= Copies C:\Users\<Username>\*.* with robocopy to a new location: <Backupdrive>:\PersBackup. Run as Admin. =--
::
:: Had a lot of difficulty's to switch off Hidden dir's. 
:: Application Data went nesting itself till 15 dirs deep at the backup location.
:: Solution was /XA:SH /XJD en /XD
::
:: Hidden dir's as Application Data, History, Temporary Internet Files are not accessible. No need to backup them.
:: 	>>>>>> You can add /L after the ... /XD option to simulate a mirror or copy. <<<<<< Trail run!
::
:: After the copy you can inspect the results in that Logs dir. File is called: "copy_userdir.log". 
:: 1st run takes a long time (depending on the datasize) but a 2nd run is done within seconds.
:: With that 2nd runs it copy's only the new files and deletes files that on the original location that were deleted.
:: It deletes them also on the backup location. (Mirror function) So copy = identical to the original data with each run.
::
:: You can try this with the explorer but you will encounter errors; Locked files, hidden files it can not access.
:: 
:: With Robocopy there will be no such things. If it encounters locked files? It will skip these file. It has no use to 
:: copy these locked files. They are made by a currently running processes of Windows. If a new installation? 
:: It will make automatically new ones... 
::
:: *********************************************************************************************************************************************
::  >>>>>>>>>>> Check if Admin.
%systemroot%\System32\fsutil dirty query %systemdrive%
if %errorlevel% neq 0 (echo You tried to run this script not as Admin. Usage: Run this script as Admin!)
if %errorlevel% neq 0 (echo Can't continue.... exiting...)
if %errorlevel% neq 0 goto :eof
if %errorlevel% equ 0 (echo You ran this script as Admin: OK, lets continue....)

::  >>>>>>>>>>> Make a new backupdir location.
mkdir "%BackupDrivePath%"
mkdir "%BackupDrivePath%\Logs"
echo Error if they already exits. That's normal for a 2nd etc. run. Error can be ignored!
echo Starting to copy all the files. No progress will be seen in this screen. Watch the %BackupDrivePath% filling with data.
echo Also watch the %BackupDrivePath%\Logs\copy_userdir.log grow and growing in size. Once done: check the log file for errors.
echo Busy copying data.... Be patient....

:: >>>>>>>>>>> Copy C:\Users\<Username>\*.* to a different disk.
Set SourceDir="C:\Users\%Username%"
Set DestinationDir="%BackupDrivePath%"
Set LogDir="%BackupDrivePath%\Logs"

%systemroot%\System32\Robocopy %SourceDir% %DestinationDir% /S /E /COPYALL /PURGE /MIR /XA:SH /R:0 /W:0 /XJD /XD /L > %LogDir%\copy_userdir.log
echo ===================================================== 
if ERRORLEVEL 16 echo ***FATAL ERROR*** 
if ERRORLEVEL 15 echo OKCOPY + FAIL + MISMATCHES + XTRA 
if ERRORLEVEL 14 echo FAIL + MISMATCHES + XTRA 
if ERRORLEVEL 13 echo OKCOPY + FAIL + MISMATCHES 
if ERRORLEVEL 12 echo FAIL + MISMATCHES
if ERRORLEVEL 11 echo OKCOPY + FAIL + XTRA 
if ERRORLEVEL 10 echo FAIL + XTRA 
if ERRORLEVEL 9 echo OKCOPY + FAIL 
if ERRORLEVEL 8 echo FAIL 
if ERRORLEVEL 7 echo OKCOPY + MISMATCHES + XTRA 
if ERRORLEVEL 6 echo MISMATCHES + XTRA 
if ERRORLEVEL 5 echo OKCOPY + MISMATCHES 
if ERRORLEVEL 4 echo MISMATCHES 
if ERRORLEVEL 3 echo OKCOPY + XTRA 
if ERRORLEVEL 2 echo XTRA 
if ERRORLEVEL 1 echo OKCOPY 
if ERRORLEVEL 0 echo No Change
echo =====================================================
echo End: %time%
echo Finished. Press a key to exit.
pause


