Solved

window 8

Posted on 2016-09-12
14
35 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
  • 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
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!

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

810 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