Batch (Backup All User Profiles to Networked Share)

July 6, 2012 at 10:29:41
Specs: Windows 7
Ok, I have looked and looked... I can find everything i need to back up the "All Users" Profile... However, I have over 90 machines i need to backup to the Backup Share to include "Every" User Account, preferably all accounts active within the last 60 days...

This is what i am working with now and it works perfectly for the current logged in user, however as stated need all users profiles....

WAIT, there's a catch....Hard Drive is encrypted using Bitlocker, User Logon is by Common Access Card (CAC) Only.... However, The Administrator can access all profiles, but... first UAC has to be disabled on the machine even when local admin needs to access user profiles, have to Allow Permission and enter admin username and password to "add the admin" to the profile folder permissions. Soooo..... this is what i am written so far and it works on "Current User" however will not backup subdirectories in other user folders, IT WILL create a folder on the backup drive with the profile name and it will generate the log file as well... any ideas...? really need help on this one.

Script is a "TEST" Production Ready for local logged on user account, needs some tweaking for your network...


NOTE: Remove REM @ xcopy locations to make full backup.....

**********************************Begin Script************************************

@ECHO OFF
title *UNIT*- AutoBackup Utility ComputerName: %ComputerName%
mode con:cols=70 lines=35
rem written by (SGT Towler, HAAF, Savannah, GA)

ping -n 1 *edit* | find "Reply" >nul
if errorlevel 1 goto nodhcp

set ip_address_string="IPv4 Address"
echo Network Connection Test
for /f "usebackq tokens=2 delims=:" %%f in (`ipconfig ^| findstr /c:%ip_address_string%`) do echo Your IP Address is: %%f
set ip_address_string="IP Address"
rem set ip_address_string="IPv4 Address"
echo Network Connection Test
for /f "usebackq tokens=2 delims=:" %%f in (`ipconfig ^| findstr /c:%ip_address_string%`) do echo Your IP Address is: %%f
goto select

:nodhcp
echo NOT CONNECTED TO DHCP SERVER...
Ping -n 2 127.0.0.1>nul
echo EXITING... CONTACT YOUR IMO!!!
Ping -n 3 127.0.0.1>nul
exit

:select
SET machine=%COMPUTERNAME%
set backupshare=\\editedserver\Profiles\AutoBK\Vista_Backup
ping -n 1 127.0.0.1>nul
goto syscheck


:syscheck
SET machine=%COMPUTERNAME%
SET targetuser=%USERNAME%
SET profile=%USERPROFILE%
IF EXIST "%systemdrive%\Users" GOTO Vista
IF EXIST "%systemdrive%\Documents and Settings" GOTO XP
IF NOT EXIST "%profile%" GOTO Noprofile


:Vista
mkdir "%backupshare%\%machine%"
dir c:\users /ad-H /b >%backupshare%\%machine%\users.txt
ping -n 1 127.0.0.1>nul
for /f "tokens=* delims=" %%a in (%backupshare%\%machine%\users.txt) do (
set backuptarget=%backupshare%\%machine%\%%a
mkdir "%backupshare%\%machine%\%%a"
echo **************************************>>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo **************************************>>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo **************************************>>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo [%date%] [%time%]--Log Created for %computername% >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo [%date%] [%time%]--Detected Vista OS. >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
ECHO [%date%] [%time%]--Starting Backup From : %profile% >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
ECHO [%date%] [%time%]--Starting Backup To : %backuptarget% >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
ECHO.
echo.
echo Processing Request....Please Wait...DO NOT EXIT
ping -n 1 127.0.0.1>nul
echo Checking Space Available...
echo.
ping -n 3 127.0.0.1>nul
echo.
icacls "%backupshare%\%machine%" /grant:r %USERNAME%:F /T /C >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
icacls "%backupshare%\%machine%" /remove:g "Authenticated Users" /T /C >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
icacls "%backupshare%\%machine%" /grant:r %targetuser%:F /T /C >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo Completed Checks....
echo.
echo.
ping -n 1 127.0.0.1>nul
echo Starting Transfer to Backup Media....PLEASE WAIT
echo.
echo.
rem xcopy "%profile%\AppData\Local\Microsoft\Outlook\*" "%backuptarget%\Outlook\" /Y /S /H /C /V /G >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
rem xcopy "%profile%\Documents\*" "%backuptarget%\MyDocuments\" /Y /S /H /C /V /G >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
rem xcopy "%profile%\Pictures\*" "%backuptarget%\MyDocuments\My Pictures\" /Y /S /H /C /V /G >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
rem xcopy "%profile%\Music\*" "%backuptarget%\MyDocuments\My Music\" /Y /S /H /C /V /G >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
xcopy "c:\users\%%a\Favorites\*" "%backuptarget%\Favorites\" /Y /S /H /C /V /G >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
rem xcopy "%profile%\Videos\*" "%backuptarget%\MyDocuments\My Videos\" /Y /S /H /C /V /G >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
xcopy "c:\users\%%a\Desktop\*" "%backuptarget%\Desktop\" /Y /S /H /C /V /G >>%backupshare%\%machine%\%%a\%machine%_%%a.txt


ECHO.
ECHO [%date%] [%time%]--Completed Backup From : %profile% >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
ECHO [%date%] [%time%]--Completed Backup To : %backuptarget% >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
ECHO Backup Complete! >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo **************************************>>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo **************************************>>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo **************************************>>%backupshare%\%machine%\%%a\%machine%_%%a.txt
ECHO Backup From : c:\users\%%a
ECHO Backup To : %backuptarget%
ECHO You can verify the backup by checking the folders above.
echo.
ping -n 4 127.0.0.1>nul
echo.
)
GOTO end


:XP
echo **************************************>>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo **************************************>>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo **************************************>>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo [%date%] [%time%]--Log Created for %computername% >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo [%date%] [%time%]--Detected XP OS. >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
set backuptarget=%backupshare%\%machine%\%targetuser%
ECHO [%date%] [%time%]--Starting Backup From : %profile% >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
ECHO [%date%] [%time%]--Starting Backup To : %backuptarget% >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
ECHO.
IF NOT EXIST "%profile%" GOTO Noprofile
mkdir "%backupshare%\%machine%"
cacls "%backupshare%\%machine%" /T /E /R "Authenticated Users" Users /P %USERNAME%:F
cacls "%backupshare%\%machine%" /T /E /P %targetuser%:F
rem xcopy "%profile%\Local Settings\Application Data\Microsoft\Outlook\*" "%backuptarget%\Outlook\" /Y /S /H /C /V /G
rem xcopy "%profile%\My Documents\*" "%backuptarget%\MyDocuments\" /Y /S /H /C /V /G
rem xcopy "%profile%\Desktop\*" "%backuptarget%\Desktop\" /Y /S /H /C /V /G
xcopy "%profile%\Favorites\*" "%backuptarget%\Favorites\" /Y /S /H /C /V /G

ECHO.
ECHO [%date%] [%time%]--Completed Backup From : %profile% >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
ECHO [%date%] [%time%]--Completed Backup To : %backuptarget% >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
ECHO Backup Complete! >>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo **************************************>>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo **************************************>>%backupshare%\%machine%\%%a\%machine%_%%a.txt
echo **************************************>>%backupshare%\%machine%\%%a\%machine%_%%a.txt
ECHO Backup From : %profile%
ECHO Backup To : %backuptarget%
ECHO You can verify the backup by checking the folders above.
echo.
ping -n 4 127.0.0.1>nul
echo.
GOTO end

:Noprofile
ECHO *******************************************
ECHO The profile you wish to target either does not exist or
ECHO is unavailable for some reason. Please manually check
ECHO the target to ensure the following:
ECHO 1. You have the correct permissions to access the
ECHO machine and user profile.
ECHO 2. That the user's profile is in the folder specified.
ECHO *******************************************
PAUSE
GOTO Menu


:nosys
echo This Utility CANNOT detect the Operating System Type...Inform IMO...
ping -n 4 127.0.0.1>nul
echo Exiting......
ping -n 2 127.0.0.1>nul
exit

:End
EXIT
:EndCMD

************************************END Script**************************************


See More: Batch (Backup All User Profiles to Networked Share)

Report •

#1
July 6, 2012 at 12:26:10
Obvious question: Why not just invest the money on a real backup program? The time and effort spent on a home brew solution should more than pay for it.

How To Ask Questions The Smart Way


Report •
Related Solutions


Ask Question