• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5265
  • Last Modified:

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.
0
Cobra25
Asked:
Cobra25
  • 7
  • 4
  • 2
  • +4
1 Solution
 
Sikhumbuzo NtsadaCommented:
Or you can use xcopy:

Example :xcopy "c:\Documents and Settings\Walter" "FileServer\I$\Backup" /S /E /C /Y /K /D /Z
0
 
Cobra25Author Commented:
Would prefer robocopy.
0
 
h3nnysCommented:
@ECHO OFF

SET ROBOCOPY_FILE_NAME=robocopy.exe
SET ROBOCOPY_BASE_TEST_PATH=%WINDIR%\system32
SET ROBOCOPY_MASTER_COPY_PATH=\\192.168.1.10\robocopy
::%PROGRAMFILES%\Windows Resource Kits\Tools

SET ROBOCOPY_LOCAL_DIR=C:\ROBOCOPY

SET REMOTE_BACKUP_BASE_PATH=\\192.168.1.100\profiles
SET REMOTE_BACKUP_USER_PATH=%REMOTE_BACKUP_BASE_PATH%\%USERNAME%
SET REMOTE_BACKUP_USER_COMPUTER_PATH=%REMOTE_BACKUP_BASE_PATH%\%USERNAME%\%COMPUTERNAME%

::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_PATH=%ROBOCOPY_BASE_TEST_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_PATH%\%ROBOCOPY_FILE_NAME%" "%ROBOCOPY_LOCAL_DIR%\%ROBOCOPY_FILE_NAME%" /y
       
        SET ROBOCOPY_EXECUTABLE_FILE_PATH=%ROBOCOPY_LOCAL_DIR%\%ROBOCOPY_FILE_NAME%
)

ECHO Current Variables:
ECHO %ROBOCOPY_BASE_VISTA_PATH%
ECHO %REMOTE_BACKUP_BASE_PATH%
ECHO %REMOTE_BACKUP_USER_PATH%
ECHO %REMOTE_BACKUP_USER_COMPUTER_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_COMPUTER_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_COMPUTER_PATH%\" /MIR /R:1 /W:2 /XA:SH /XD *temp "temporary internet files" *cache mozilla

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Cobra25Author Commented:
I need something universal also, like where i can back up each users profile by running the same script locally on each machine.
0
 
Cobra25Author Commented:
wouldnt this work:

robocopy c:\documents and settings\ \\backupserver\profiles /E /Z /LOG+:"robo.log"
0
 
johnb6767Commented:
Wont copy alot of things out of the currently logged in user.....

So it would depend on how you launched the script....
0
 
Cobra25Author Commented:
hmm, ok, how do i go around that, log in as a diff user?
0
 
johnb6767Commented:
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.
0
 
Cobra25Author Commented:
I plan on doing this after hours anyways, is there a way to include any hidden files?
0
 
GhouseAdminCommented:
try this :

robocopy "Full source path" "Destination full path" *.* /e /zb /xo /copyall /log+:robocpy.txt /fp /tee

the above command will copy the entire folder to the destination including the permissions. If you get disconnected in the middle for any reason, running the above command again will resume copying(instead of running from scratch) and saves time in copying the folder.

---ghouse
0
 
hari_b85Commented:
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
0
 
puter_geekCommented:
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
shutdown -m \\computername -r -t 00
robocopy "\\machinename\c$\Documents and Settings\" "Destination full path" *.* /e /zb /copyall

Open in new window

0
 
puter_geekCommented:
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.
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
)

Open in new window

0
 
Cobra25Author Commented:
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?
0
 
puter_geekCommented:
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.
0
 
Cobra25Author Commented:
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\backup" *.* /E /Z
0
 
puter_geekCommented:
Are you putting in the entire script that I posted?  You have to have the "for" command in there, also.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 7
  • 4
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now