Solved

window 8

Posted on 2016-09-12
14
46 Views
Last Modified: 2016-10-02
dear sir,
we need to one batch file via this we can sync folders to our network drive every three hours for backup purpose
0
Comment
Question by:prana1984
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 4
14 Comments
 
LVL 9

Expert Comment

by:Tomas Valenta
ID: 41793804
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.
0
 

Author Comment

by:prana1984
ID: 41793812
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)
0
 
LVL 9

Expert Comment

by:Tomas Valenta
ID: 41793820
In your case use quarter marks
xcopy "D:\COMPANY PROJECT\*.*" "Z:\new backup" /S /E /C /Y
0
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 
LVL 24

Expert Comment

by:NVIT
ID: 41793844
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.
0
 

Author Comment

by:prana1984
ID: 41793961
still not copy data request for alternate solution
0
 
LVL 9

Expert Comment

by:Tomas Valenta
ID: 41793970
can you provide me the error you received by running the command, please ?
0
 

Author Comment

by:prana1984
ID: 41793986
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 .
0
 
LVL 9

Expert Comment

by:Tomas Valenta
ID: 41793991
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.
0
 

Author Comment

by:prana1984
ID: 41794055
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 !
0
 
LVL 9

Expert Comment

by:Tomas Valenta
ID: 41794064
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
0
 
LVL 24

Expert Comment

by:NVIT
ID: 41794256
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"
0
 
LVL 24

Accepted Solution

by:
NVIT earned 250 total points (awarded by participants)
ID: 41794274
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"
0
 
LVL 9

Assisted Solution

by:Tomas Valenta
Tomas Valenta earned 250 total points (awarded by participants)
ID: 41795552
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
0
 
LVL 24

Expert Comment

by:NVIT
ID: 41825214
Question answered.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question