Bill H
asked on
Robocopy Script to Copy User Profiles
I'm looking to create a script that i can schedule on a few machines that will copy an entire users profile to a shared folder. I do not want anything deleted.I dont need mirroring or anything like that, it would be just a one time backup. I have to use this same script for everyone.
ASKER
Would prefer robocopy.
@ECHO OFF
SET ROBOCOPY_FILE_NAME=robocop y.exe
SET ROBOCOPY_BASE_TEST_PATH=%W INDIR%\sys tem32
SET ROBOCOPY_MASTER_COPY_PATH= \\192.168. 1.10\roboc opy
::%PROGRAMFILES%\Windows Resource Kits\Tools
SET ROBOCOPY_LOCAL_DIR=C:\ROBO COPY
SET REMOTE_BACKUP_BASE_PATH=\\ 192.168.1. 100\profil es
SET REMOTE_BACKUP_USER_PATH=%R EMOTE_BACK UP_BASE_PA TH%\%USERN AME%
SET REMOTE_BACKUP_USER_COMPUTE R_PATH=%RE MOTE_BACKU P_BASE_PAT H%\%USERNA ME%\%COMPU TERNAME%
::Robocopy exists in the System32 folder in both MS Vista and MS Windows 7.
IF EXIST "%ROBOCOPY_BASE_TEST_PATH% \%ROBOCOPY _FILE_NAME %" (
SET ROBOCOPY_EXECUTABLE_FILE_P ATH=%ROBOC OPY_BASE_T EST_PATH%\ %ROBOCOPY_ FILE_NAME%
) ELSE (
::Create the local directory for the Robocopy executable.
MKDIR "%ROBOCOPY_LOCAL_DIR%"
::Copy the robocopy executable to the local directory.
::/y Suppresses prompting to confirm that you want to overwrite an existing destination file.
COPY "%ROBOCOPY_MASTER_COPY_PAT H%\%ROBOCO PY_FILE_NA ME%" "%ROBOCOPY_LOCAL_DIR%\%ROB OCOPY_FILE _NAME%" /y
SET ROBOCOPY_EXECUTABLE_FILE_P ATH=%ROBOC OPY_LOCAL_ DIR%\%ROBO COPY_FILE_ NAME%
)
ECHO Current Variables:
ECHO %ROBOCOPY_BASE_VISTA_PATH%
ECHO %REMOTE_BACKUP_BASE_PATH%
ECHO %REMOTE_BACKUP_USER_PATH%
ECHO %REMOTE_BACKUP_USER_COMPUT ER_PATH%
ECHO "%ROBOCOPY_EXECUTABLE_FILE _PATH%"
ECHO "%USERPROFILE%"
::Create the remote profile backup directory for the current user.
MKDIR "%REMOTE_BACKUP_USER_PATH% "
::Create the remote profile backup directory for the current computer.
MKDIR "%REMOTE_BACKUP_USER_COMPU TER_PATH%"
::Execute robocopy to copy the user's profile folder contents to the remote storage location.
::/MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).
::/R:n :: number of Retries on failed copies: default 1 million.
::/W:n :: Wait time between retries: default is 30 seconds.
::/XA:[RASHCNETO] :: eXclude files with any of the given Attributes set, e.g., S=System, H=Hidden.
::/XD dirs [dirs]... :: eXclude Directories matching given names/paths.
"%ROBOCOPY_EXECUTABLE_FILE _PATH%" "%USERPROFILE%" "%REMOTE_BACKUP_USER_COMPU TER_PATH%\ " /MIR /R:1 /W:2 /XA:SH /XD *temp "temporary internet files" *cache mozilla
SET ROBOCOPY_FILE_NAME=robocop
SET ROBOCOPY_BASE_TEST_PATH=%W
SET ROBOCOPY_MASTER_COPY_PATH=
::%PROGRAMFILES%\Windows Resource Kits\Tools
SET ROBOCOPY_LOCAL_DIR=C:\ROBO
SET REMOTE_BACKUP_BASE_PATH=\\
SET REMOTE_BACKUP_USER_PATH=%R
SET REMOTE_BACKUP_USER_COMPUTE
::Robocopy exists in the System32 folder in both MS Vista and MS Windows 7.
IF EXIST "%ROBOCOPY_BASE_TEST_PATH%
SET ROBOCOPY_EXECUTABLE_FILE_P
) ELSE (
::Create the local directory for the Robocopy executable.
MKDIR "%ROBOCOPY_LOCAL_DIR%"
::Copy the robocopy executable to the local directory.
::/y Suppresses prompting to confirm that you want to overwrite an existing destination file.
COPY "%ROBOCOPY_MASTER_COPY_PAT
SET ROBOCOPY_EXECUTABLE_FILE_P
)
ECHO Current Variables:
ECHO %ROBOCOPY_BASE_VISTA_PATH%
ECHO %REMOTE_BACKUP_BASE_PATH%
ECHO %REMOTE_BACKUP_USER_PATH%
ECHO %REMOTE_BACKUP_USER_COMPUT
ECHO "%ROBOCOPY_EXECUTABLE_FILE
ECHO "%USERPROFILE%"
::Create the remote profile backup directory for the current user.
MKDIR "%REMOTE_BACKUP_USER_PATH%
::Create the remote profile backup directory for the current computer.
MKDIR "%REMOTE_BACKUP_USER_COMPU
::Execute robocopy to copy the user's profile folder contents to the remote storage location.
::/MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).
::/R:n :: number of Retries on failed copies: default 1 million.
::/W:n :: Wait time between retries: default is 30 seconds.
::/XA:[RASHCNETO] :: eXclude files with any of the given Attributes set, e.g., S=System, H=Hidden.
::/XD dirs [dirs]... :: eXclude Directories matching given names/paths.
"%ROBOCOPY_EXECUTABLE_FILE
ASKER
I need something universal also, like where i can back up each users profile by running the same script locally on each machine.
ASKER
wouldnt this work:
robocopy c:\documents and settings\ \\backupserver\profiles /E /Z /LOG+:"robo.log"
robocopy c:\documents and settings\ \\backupserver\profiles /E /Z /LOG+:"robo.log"
Wont copy alot of things out of the currently logged in user.....
So it would depend on how you launched the script....
So it would depend on how you launched the script....
ASKER
hmm, ok, how do i go around that, log in as a diff user?
Machine Startup , or after hours deployed script (to reboot the machine and launch the copy)
If a user is logged in, you may get most of the profiles, but the one thats logged in cannot be fully backed up using robocopy/xcopy etc, as there are files open, mainly the registry, and anything else left open.
If a user is logged in, you may get most of the profiles, but the one thats logged in cannot be fully backed up using robocopy/xcopy etc, as there are files open, mainly the registry, and anything else left open.
ASKER
I plan on doing this after hours anyways, is there a way to include any hidden files?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Might this help you,
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -----
@Echo off
cls
set user=
echo Enter Username
set /p user=
robocopy "source\%user% "Destination\%User% /e /v /r:2 /w:2
--------------------------
@Echo off
cls
set user=
echo Enter Username
set /p user=
robocopy "source\%user% "Destination\%User% /e /v /r:2 /w:2
Are you in a domain environment? If you are you could run this batch file from the server:
That will reboot the computer and then copy everything
That will reboot the computer and then copy everything
shutdown -m \\computername -r -t 00
robocopy "\\machinename\c$\Documents and Settings\" "Destination full path" *.* /e /zb /copyall
If you have more than one computer to run it on you could put all the computernames in a text file and pull the computername from the file. That would save you from going to each PC individually.
Create a text file with all the computer names first and put it somewhere. The script is below:
forgot something: you'll have to have the sleep command. It can be found in the Server 2003 Resource Kit. http://www.microsoft.com/downloads/en/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
The batch file below is set for two minutes(120 seconds) of waiting for the computer to reboot. You may need to extend it for older computers.
Create a text file with all the computer names first and put it somewhere. The script is below:
forgot something: you'll have to have the sleep command. It can be found in the Server 2003 Resource Kit. http://www.microsoft.com/downloads/en/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
The batch file below is set for two minutes(120 seconds) of waiting for the computer to reboot. You may need to extend it for older computers.
for /f "tokens=*" %%a in (C:\OldHDD\ComputerList.txt) do (
shutdown -m \\%%a -r -t 00
sleep 120
robocopy "\\%%a\c$\Documents and Settings\" "Destination full path" *.* /e /zb /copyall
)
ASKER
I got the script working so far, and everything copied over. However, a few of the files that copied over, like say the Outlook .nk2 file is 0KB, when it should be 5kb. Why would this be?
nk2 files are for Outlook's Autocomplete List. Was Outlook open when it was copied? That would result in a corrupt backup. Technically, copying the nk2 file isn't a good idea anyway, because there are potential problems with display names not matching underlying addresses and such.
ASKER
putergeek,
i got the nk2 issue sorted out. Now, regarding your script, i put a computer name in a text file and updated the paths. But the error message i get is error 53: accessing source directory \\%%a\C$\documents and settings\administrator.
My robocopy script looks like this if you need it:
robocopy "\\%%a\C$\documents and settings\administrator" "\\remotesan\testing\backu p" *.* /E /Z
i got the nk2 issue sorted out. Now, regarding your script, i put a computer name in a text file and updated the paths. But the error message i get is error 53: accessing source directory \\%%a\C$\documents and settings\administrator.
My robocopy script looks like this if you need it:
robocopy "\\%%a\C$\documents and settings\administrator" "\\remotesan\testing\backu
Are you putting in the entire script that I posted? You have to have the "for" command in there, also.
Example :xcopy "c:\Documents and Settings\Walter" "FileServer\I$\Backup" /S /E /C /Y /K /D /Z