Hi Sorry to ask another question regarding robocopy but by its very nature it is quite diverse so I need to be clear on what I am trying to achieve.
Scenario.
Moving from a Nas to a windows file Share , Completely New ACL's will be created and inherited from the new share already setup . SO this is a straight file and folder copy with mirroring.
I decided to use powershell to run the command - it felt right at the time and achieved the desired result on a few shares .
I mapped the drive and ran the following .
robocopy z:\"Dept Folder 1"\ E:\Shares\deptdata\"New dept folder" /e /LOG+:file /v /TEE
robocopy z:\"Dept Folder 2"\ E:\Shares\deptdata\"New dept folder2" /e /LOG+:file /v /TEE
The files and folders copied as expected inheriting the new ACL's The first Job finished and then moved on to the second copy and again completed successfully.
What I would like to do now on some of the larger shares is incorporate the mir command as I need to keep a constant mirror on all folders until such time as I have tested the new ACL's and I have mapped the new drive via GPO.
My First Question knowing the behaviour when having batched commands is this .
When using the Mir command will the first command in the batch continue to mirror
the share and move onto the next Mirror command and so forth. or will it just sit their mirroring the first command and not move onto the second?
If it wont move on to the next command how do I achieve that is it possible? would i have to run multiple mirror commands at the same time and not batch them up in one?
When the Mir command is running if I add new files into the New destination will those files get deleted, or is it only mirroring the source and doesn't care about new files in the destination?
Where would I specify the MIR command?
Related
Plz help..
I am trying to run a batch on another server to copy a file to not shared directory (not UNC):
there are two servers and two batch files: serv01 serv02 & bat1 bat2
bat1 runs from serv01 and bat2 located on serv02 is called by bat1 from serv01
bat2 is shared on serv02 so serv01 can see it
I am trying to copy a file from serv01 to serv02. Copy destination path is not shared, but the bat2 is local on serv02 like, so the "double click" run will do the job.
bat1:
call "\\serv2\folder\bat2.bat"
bat2:
SET path01="\\serv01\deployment\serv02"
SET path02="d:\application\ui"
copy "%path01%\web.config" "%path02%\web.config"
I have tried %~dp0 but this only uses the shared folder directory and can only copy to that folder(not desired location)
I tried PUSHD but this also creates a local virtual directory so in this case is path01 and this only, where I am trying to copy a file to local path02 (serv02)
I know there is always a problem with reading UNC`s and I couldnt find an answer to this on stack. Is there a way to run bat02 as local but still pull path01? As a "double click" run on the bat2 is working fine and does the job.
Many thanks!
If you are an admin then everything is shared. The admin shares C$, D$, ..., N$ are admin hidden shares.
copy "\\serv01\C$\folder\file.ext" "\\serv02\C$\folder\file.ext"
There are also Print$ and Admin$ shares. Type net share to see list.
To run a file remotely
wmic /node:serv02 process call create "cmd /c somefile.bat"
I want to create a backup Batch file that meets these requirements:
Requirement:
1-Only copy the source files if the source file got modified.
2-If the destination contains the files/folders that do not exist in the source, then the destination files/folders will be deleted.
3-Copies all subdirectories, even if they are empty.
4-If something happened that make the coping process uncompleted (ie copied unsuccessfully), the program will revert & keep the old version of the destination folder.
5-The batch file should run at the time i turn off my PC or at 7pm Daily.
So, i tried this
xcopy C:\MyProject N:\backup\MyProject /V /Y /E /D
Note: /v=Verify, /y=No prompting /e=subdirs /d=Copy only changed
However, after running the batch, it did not delete the files/folders mentioned in requirement 2. Also, i don't know how to do the requirement 4 & 5.
I searched many questions but seem they didn't have the code to meet requirement 2 & 4 & 5.
I don't want to use backup tool in Win7 since it is very heavy & it requires a big backup disk space. I prefer something simple (why didn't Window make things simple?? ).
Backup is very important when u do the project, I hope my question will help a lot of other programmers.
Can anyone know a good solution for this?
If you want a mirror backup, which only copies new and changed files, removes files that no longer exist in the source - then Robocopy is built in and can do that. A batch file that is scheduled at 7pm daily will work.
Your requirement #4 is something that I haven't seen in any backup programs, including Robocopy.
I recently wrote a batch file like this for an old XP machine, since I didn't trust the format produced by NTbackup to be readable on future machines. E.g. Windows 7 and 8 require a download of some sort of converter: forget that. My batch file lives in the root C:\ directory, and I have a shortcut in my "tools" program list.
Write the file in Notepad, and save as e.g. c:\backup.bat. Run it from the "Run" command. The first time it runs, all the directories you specify will be copied exactly to your backup drive, including all subdirectories (I use a 4 Gbyte thumb drive: you may well need larger). The first time, my small 3 GB or so of stuff took about 4 minutes on an old XP machine.
Interestingly, the total uncompressed backup produced this way is no larger than the backup produced by NTbackup in Windows XP in that program's unreadable format.
Here's a batch file, with comments (REM)...
REM backup.bat
The xcopy line below is for stuff in directory c:\anydir and its subdirectories, being copied to a directory \anydir on an e: drive (e.g. USB drive).
REM The actual command:
xcopy c:\anydir e:\anydir /i /s /y /d
For other directories, just change the c:\directory and e:\directory names in the xcopy command. Watch out, however, for names like My Pictures, with a space: you must rename them (just delete the space), so that DOS recognizes them.
REM finish
exit
The /i means make any (sub)directories that don't exist on the backup drive. This therefore copies the whole branch from the c: directory where you start.
The /s copies source directories and subdirectories unless they are empty.
The /y says don't ask about over-writing existing files.
The /d says only copy files of a later date: perfect for backup, and very fast.
The files are exactly as original: no weird backup format.
With regard to the questioner's question #4, I think just running the backup again would overwrite any failure. But if that fails, wipe your backup drive and start over. And question #5...XP (and I think 7) allow scheduled tasks from the Startup menu: just insert c:\backup.bat in the list. But I haven't tried that.
I am trying to copy all .txt files that I have scattered throughout several subdirectories of one main directory into another directory using a batch file. I have research this site and found lots of answers at this link: batch file Copy files with certain extensions from multiple directories into one directory. Like the code below from Jay:
set dSource=C:\Main directory\sub directory
set dTarget=D:\Documents
set fType=*.doc
for /f "delims=" %%f in ('dir /a-d /b /s "%dSource%\%fType%"') do (
copy /V "%%f" "%dTarget%\" 2>nul
)
My question is how to modify this code or other codes on this link to batch copy the files with time stamps, like I only want to copy .txt files created from Jan 1, 2012 to Nov 1, 2012.
My suggestion for finding and moving *.txt files in a directory tree of a drive, or the entire drive, or even multiple drives with last modification date in a definite time period is:
Start Windows Explorer.
Click on button Search.
Open advanced search options for finding files and folders.
Select/enter to search for files by last modification date.
Enter the two dates to specify time period or select the time period.
Run the search.
Select all found files in search result, for example with Ctrl+A.
Press Ctrl+X to mark the found files for being cut (moved).
Open the folder into which the files should be moved.
Press Ctrl+V to paste the files (move them).
That's it.
Nobody needs to code a batch job for this task if this find + move files job should not be done periodically using a scheduling task.
The exact steps for doing such an advanced find for files in a definite time period with Windows Explorer depends on version of Windows. See for example the computer tips
Find files by date modified in Windows for Windows 8/7/Vista, or
for Windows XP: How do I search for a file on my computer?
And of course there are many freeware and shareware tools which support also finding files according to various search criterias like last modification date within a specified time period and move them.
Well, that does not really answer the question as it does not contain the batch code for doing the job. So I answer this question with another question:
Why thinking about coding a batch file for such a task hard to adapt for varying dates if dozens of GUI applications including Windows Explorer exist doing the same by simple user input with no need on coding skills and therefore very easy to use, and the find + move must be done only once or from time to time with changed criterias?
I have a foldering system setup consisting of a “master folder” wich varys in name holds two sub folders, the sub folders though are always called CTB and DWG. I want the contents. of the DWG folder always to be coppied to the desktop and the contents of the CTB to always be coppied to C:\ICT\Autocad_2010\CTB. Remembering that the master folder varys in name pending on the project.
Is this possible with batch?
somthing like:
XCOPY %0\DWG\*.* c:\ICT\AutoCAD_2010\CTB
Nevermind i got it
XCOPY "%cd%\DWG\*.DWG" c:\
however how do i copy it to the desktop?
try this to copy to the current user desktop
xcopy "dwg\*.dwg" "%Homedrive%%Homepath%\desktop"
or this to copy to all users desktop
xcopy "dwg\*.dwg" "%allusersprofile%\desktop"
I need help writing a batch file to update templates on a database. Basically, all our clients have their own folder, with multiple templates inside. Due to the computer illiteracy of my office (sigh), there's no real better way to fix this. However, I need a way to update those templates in a batch. For instance
\\SERVER\New Client Template Folder\Correspondence\Transmittal Letter.WPD
is updated. I then need to copy it to:
\\SERVER\Client Files\Client 1\Correspondence;
\\SERVER\Client Files\Client 2\Correspondence;
...etc. Essentially, I need to copy to \\SERVER\Client Files\\*\\, and I need to make it a batch file that I can train someone else to use whenever I leave this job. How can I do that?
Thanks.
The new versions of Windows (7 and 2008 Server R2) have the robust file copy tool (robocopy). This can be installed on XP and 2003 also be installed using the Resource Kit. Essentially, robocopy gives you a command-line directory mirroring tool that could help you accomplish what you're trying to do. Simply place robocopy commands into a batch file (/MIR = mirror directory contents /XJ = ignore junctions) :
robocopy <source_dir> <destination_dir> /MIR /XJ
You didn't indicate which operating system you are working under. Let me guess its windows. My DOS BAT file knowledge is limited, but you
could try creating a BAT file with something like:
set Src="\\SERVER\New Client Template Folder\Correspondence\Transmittal Letter.WPD"
set DestA="\\SERVER\Client Files\
set DestB=\Correspondence;"
FOR /F "delims=" %%i IN (distribution.txt) DO copy %Src% %DestA%%%i%DestB%
and then create a distribution.txt file like:
Client 1
Client 2
Running this BAT file will read the distribution.txt file and issue a copy command for each line in it. As follows:
COPY "\\SERVER\New Client Template Folder\Correspondence\Transmittal Letter.WPD" "\\SERVER\Client Files\Client 1\Correspondence;"
COPY "\\SERVER\New Client Template Folder\Correspondence\Transmittal Letter.WPD" "\\SERVER\Client Files\Client 2\Correspondence;"
But there must be a better way!!!!
You can get more help on the FOR command by typing help for at the DOS prompt.
If you don't like the idea of having to build/maintain the distribution.txt file, you could play with using DIR /A:D /B "\\SERVER\Client Files\*" to drop a directory listing into a temporary file, then use it as input to the FOR loop.