Wednesday, July 30, 2025

User Profile Backup

 I have a PC with a second standard user. The data size should remain small. Various users will have access, and corruption may occur. I'm looking for a way to back up and restore the user profile.

Here are the scripts to try.
Change the hard drive letters and user name to fit the situation.

Backup
@echo off
:: CONFIGURATION SECTION
set "SourceProfile=C:\Users\JohnDoe"
set "BackupLocation=C:\Backups\JohnDoe_Backup"
set "LogFile=C:\Backups\Logs\BackupLog_%DATE:/=-%_%TIME::=-%.txt"

:: Create backup folder if it doesn't exist
if not exist "%BackupLocation%" (
    echo Creating backup directory: %BackupLocation%
    mkdir "%BackupLocation%"
)

if not exist "%~dp0Logs" (
    mkdir "%~dp0Logs"
)

echo Starting backup from %SourceProfile% to %BackupLocation%
echo Logging to %LogFile%

:: Perform the backup using Robocopy
robocopy "%SourceProfile%" "%BackupLocation%" /MIR /XJ /Z /R:2 /W:2 /COPYALL /DCOPY:T /NFL /NDL /NP /LOG+:"%LogFile%"

echo Backup completed.
pause


Restore
@echo off
:: CONFIGURATION SECTION
set "BackupSource=C:\Backups\JohnDoe_Backup"
set "TargetProfile=C:\Users\JohnDoe"
set "LogFile=C:\Backups\Logs\RestoreLog_%DATE:/=-%_%TIME::=-%.txt"

:: Confirm operation
echo --------------------------------------------------
echo You are about to restore a user profile:
echo FROM: %BackupSource%
echo TO:   %TargetProfile%
echo --------------------------------------------------
pause

:: Create target directory if it doesn't exist
if not exist "%TargetProfile%" (
    echo Creating target directory: %TargetProfile%
    mkdir "%TargetProfile%"
)

if not exist "%~dp0Logs" (
    mkdir "%~dp0Logs"
)

:: Use Robocopy to restore backup
robocopy "%BackupSource%" "%TargetProfile%" /MIR /XJ /Z /R:2 /W:2 /COPYALL /DCOPY:T /NFL /NDL /NP /LOG+:"%LogFile%"

echo Restore complete.
pause

If something doesn't work check the path to the profile in registry.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList


User Profile Backup

 I have a PC with a second standard user. The data size should remain small. Various users will have access, and corruption may occur. I...