window 8

dear sir,
we need to one batch file via this we can sync folders to our network drive every three hours for backup purpose
prana1984Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tomas ValentaIT ManagerCommented:
Open notepad and paste the following command:
xcopy c:\FolderToSync\*.* x:\PathForBackup /S /E /C /Y
Change your source (c:\FolderToSync\*.*) and destination (x:\PathForBackup) to real names in your environment and save the file like sync.cmd.
This script will copy files and subfolder in source to the destination and will not stop in case of error and suppress warning about rewriting the destination file so in the target path will be always latest data.
For this script create task in scheduler and run it in period you wants.
prana1984Author Commented:
dear sir i have created and try to manual run but not data copy
xcopy D:\COMPANY PROJECT\*.* Z:\new backup /S /E /C /Y

source path             D:\COMPANY PROJECT
destination path     Z:\new backup (network drive)
Tomas ValentaIT ManagerCommented:
In your case use quarter marks
xcopy "D:\COMPANY PROJECT\*.*" "Z:\new backup" /S /E /C /Y
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

NVITEnd-user supportCommented:
If you want, in subsequent scheduled runs,  the sync to include files that may have been deleted from source, which xcopy does not do, you should use Robocopy instead. With the /MIR switch. E.g.

robocopy /mir /dcopy:t /e "D:\COMPANY PROJECT\*.*" "Z:\new backup"

Open in new window


/mir makes an exact copy of source.

/dcopy:t copies the datestamps of folders. Else the current date is used.

/e copies sub folders, including empty ones. If you just want non empty folders, use the /s switch.
prana1984Author Commented:
still not copy data request for alternate solution
Tomas ValentaIT ManagerCommented:
can you provide me the error you received by running the command, please ?
prana1984Author Commented:
dear sir
i have created batch file and just click to on this batch file its running and close within second so how to analyses error
i am very thankful of u if u help me to resolve this issue .
Tomas ValentaIT ManagerCommented:
Open command prompt by clicking on Start button and typing cmd.exe.
It opens separate window where you can paste (by mouse right click and paste)
the command and run it by pressing Enter. The result is written to the same window.
prana1984Author Commented:
error is below

icrosoft Windows [Version 6.1.7601]
opyright (c) 2009 Microsoft Corporation.  All rights reserved.

:\Users\3524>robocopy /mir /dcopy:t /e "D:\COMPANY PROJECT\*.*" "Z:\new backup

------------------------------------------------------------------------------
  ROBOCOPY     ::     Robust File Copy for Windows

------------------------------------------------------------------------------

 Started : Mon Sep 12 17:54:39 2016

  Source -
    Dest -

   Files :
 Options : /S /E /COPY:DAT /DCOPY:T /PURGE /MIR /R:1000000 /W:30

-----------------------------------------------------------------------------

RROR : Invalid Parameter #4 : "D:\COMPANY PROJECT\*.*"

      Simple Usage :: ROBOCOPY source destination /MIR

            source :: Source Directory (drive:\path or \\server\share\path).
       destination :: Destination Dir  (drive:\path or \\server\share\path).
              /MIR :: Mirror a complete directory tree.

   For more usage information run ROBOCOPY /?


***  /MIR can DELETE files as well as copy them !
Tomas ValentaIT ManagerCommented:
OK. I think result of xcopy command I sent you at the start of this topic.
In robocopy command you need to change it:
robocopy /mir /dcopy:t /e "D:\COMPANY PROJECT" "Z:\new backup
NVITEnd-user supportCommented:
Sorry for my wrong post, Prana.
Thanks for the help, Tomas.

Not sure if this matters but, you may need to add the closing quote for the destination. I.e.

robocopy /mir /dcopy:t /e "D:\COMPANY PROJECT" "Z:\new backup"
NVITEnd-user supportCommented:
I would add the /R and /W switches from /R:1 /W:1
Else, you may  be waiting too long  if it reaches a problem file.

robocopy /mir /dcopy:t /e /w:1 /r:1 "D:\COMPANY PROJECT" "Z:\new backup"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tomas ValentaIT ManagerCommented:
Prana, but there is general question. Do you need to have only 3 hours backup files back ? Because robocopy with /MIR switch make exact copy of your folder but when you delete file on local drive the robocopy delete this file also in backup. Maybe better should be to make decision how long back you want to be able to restore data and then to change the backup script to meet your requirements:
Here is example:
SET FromPath=d:\COMPANY PROJECT\*.*
SET BackPath=Z:\new backup\
SET LogPath=Z:\LOGS\
For /f "tokens=2-4 delims=/. " %%a in ('date /t') do (set ArchiveFolderDate=%%c-%%b-%%a)
For /f "tokens=1-2 delims=: " %%a in ('time /t') do (set ArchiveFolderTime=%%a.%%b)
set ArchiveFolderName=%ArchiveFolderDate%-%ArchiveFolderTime%
echo %ArchiveFolderName%
xcopy %FromPath% %BackPath%%ArchiveFolderName%\ /S /E /C /Y

This script creates subfolder in Z:\new backup\ based on current date and time. So every backup creates separate snapshots of COMPANY Projects folder. The folder name depends data and time international settings on your computers so it must be tuned. If you give me back result of the following commands I can change the script:
date /t
time /t
NVITEnd-user supportCommented:
Question answered.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.