Using Robocopy to merge two user home directories shares from two different servers to a new server, but can't use /purge to mirror deletes because it will delete the other servers stuff.
I need a way to enumerate the folder names from the users$ share on each server, and add it to both path statements in the command below, so I can purge at the Users subfolder level.
Robocopy command:
robocopy "\CurrentServer1\users$" "F:\Users" /E /B /COPY:DATSOU /R:1 /W:1 /MT /LOG:"C:\RobocopyLogs\MirrorUsers1.txt"
Can a batch or vbscript do that?
Thanks in advance for any help you can provide.
You could merge both source folders into a staging folder, then mirror that staging folder to the destination folder:
mkdir C:\staging
robocopy \\server1\src C:\staging /e /b ...
robocopy \\server2\src C:\staging /e /b ...
robocopy C:\staging C:\dst /mir /b ...
rmdir /s /q C:\staging
Related
I have issue with backup folders from server to ftp (NAS). I was using Cobian backup, but after security updates Cobian started don't handle some files what earlier wasn't problem (doc,pdf or some type setup file). I tried change to .bat files script with scheduler help. I was using script
net use X: \\address\Backup /user:logins /p:no
for /f "tokens=1* delims=" %%a in ('date /T') do set datestr=%%a
md X:\*\*_"%date:/=_%"
md X:\*\*_"%date:/=_%"
md X:\*\*_"%date:/=_%"
md X:\*\*_"%date:/=_%"
md X:\*\*_"%date:/=_%"
net stop MSSQL$PAYPREMIUM
net stop ASANYs_labbis
net stop ASANYs_FinvaldaMaxiServer
net stop ASANYs_FinvaldaMaxiServern
robocopy C:\Program Files\Microsoft SQL Server\MSSQL10_50.PAYPREMIUM\MSSQL\DATA X:\1\PAYPREMIUM\DATA /MIR /LOG:D:\LOG\log.txt
robocopy /mir C:\*\ X:\*\*_"%date:/=_%" /COPY:DAT /E /LOG:D:\LOG\log.txt
robocopy /mir C:\Program Files\Microsoft SQL Server\MSSQL10_50.PAYPREMIUM\MSSQL\DATA\ X:\*\*_"%date:/=_%" /COPY:DAT /E /LOG:D:\LOG\log.txt
robocopy /mir C:\ProgramData\*\data\ X:\*\data_"%date:/=_%" /COPY:DAT /E /LOG:D:\LOG\log.txt
robocopy /mir G:\*_K\ X:\*\*_K_"%date:/=_%" /COPY:DAT /E /LOG:D:\LOG\log.txt
robocopy /mir G:\*\ X:\*\*_"%date:/=_%" /COPY:DAT /E /LOG:D:\LOG\log.txt
net start MSSQL$PAYPREMIUM
net start ASANYs_labbis
net start ASANYs_FinvaldaMaxiServer
net start ASANYs_FinvaldaMaxiServern
net use X: * /delete /Y
But robocopy and xcopy did not handled some situations. So after this I try use WinSCP script
option batch abort
option confirm off
open ftp://logins
put -preservetime E:\FILESERVER /disk1/ftp/SRV/FileServer_%TIMESTAMP#yyyymmddhhnnss%
exit
But even this did not handle the situation when from catalog tree with files from 60+GB only copy one folder without files that make trouble. Trouble that when you copy simple you get notifications about path long and another about that cant copy permissions pdf, doc, ppt files. So I need to make that pass this problems and copy as much that not have problem with path long and path long files that make error just skip.
The long path issue you'll have to address by shortening the destination path name; sometimes SUBST can be used to help you get around that problem, if memory serves. Something like:
NET USE X: \\server\dir
SUBST T: X:\subdir\subsubdir\subsubsubdir\anotherlongdir\blah
Cleanup:
SUBST T: /D
As to continuing to copy files after some files get error, I believe robocopy /R:0 /W:0 will help, and XCOPY /C is its counterpart.
I have folder C:\Folder. In this folder I have thousands of subfolders. I want to target only those ending in cv. In these subfolders I have a file and another subfolder. C:\Folder\SubFoldercv\cv. I would like to move all the files in those subfolders to the second subfolder using CMD in Windows 10.
(So from C:\Folder\SubFoldercv to C:\Folder\SubFoldercv\cv).
Use for /D to find the directories ending with cv, and use robocopy to copy (or robocopy /mov to move) all files from a folder to another:
#echo off
FOR /D %%G IN ("C:\Folder\*cv") DO robocopy /mov "%%~G" "%%~G\cv" "*"
I'm currently not on a windows machine so I'm not able to test it but it should do the trick and move all files to the cv subfolder for all folders ending on cv.
If you want to use it on the command-line, use:
FOR /D %G IN ("*cv") DO robocopy /mov "%~G" "%~G\cv" "*"
instead.
EDIT: After the OP tested it, he has confirmed that it works.
How to do?
subfolderHolder = uploads
FOR /D %%i IN ("%MoveDirSource%\*\%subfolderHolder%\*") DO ROBOCOPY /MOV /E "%%i" "%MoveDirDestination%\%%~nxi"
but the wild card is not working
I'm trying to copy the ChromeData subfolder with permissions that may or may not be inside user profiles. so the folder structure is as follows.
-user1
-chromeData
-contacts
-desktop
-user2
-chromeData
-contacts
-desktop
the destination should be like this.
-user1
-ChromeData
-user2
-ChromeData
My code is as follows. It does copy the content in the chromeData folder to the destination, but it does not copy the permissions. Please note that I have used /mir /secfix and /copyall with robocopy. None of them worked. I saw a post saying robocopy does not copy inherited permissions. If this is true I need a workaround.
#echo off
setlocal EnableDelayedExpansion
set Source=F:\DFSroot\Redirected Content\
set Target=H:\Redirected ChromeData\
rem dir /s /ad /b "%Source%*.*" | find /i "\ChromeData" > C:\Temp\dir.txt
for /F "tokens=*" %%a in (C:\Temp\dir.txt) do (
set T1=%%a
call set T2=!T1:%Source%=%Target%!
robocopy "%%a" "!T2!" /copyall
pause
)
UPDATE
Found that permission is being copied for the chromedata folder but not its parent folder.
Use the following command to copy with the ACLs
robocopy "source address" "destination address" *.* /sec
Use the following command to fix an existing tree.
robocopy "source address" "destination address" *.* /secfix /sec
Found this information on this blog
I want to copy only directories (it's files and sub directories) within the current directory from a command prompt.
I've already copied all the files in the current directory using this command.
copy * d:\copyfolder
I've tried these for individual folders. To copy a folder:
XCOPY C:\utils D:\Backup\utils /i
To copy a folder including all subfolders.
XCOPY C:\utils* D:\Backup\utils /s /i
But couldn't find a way to copy only directories.
From the command line this should work to copy all folders with subdirectories and files:
for /d %a in (*) do xcopy "%a\*.*" "d:\copyfolder\%a\" /s/h/e/k/f/c
I've tried these for individual folders.
To copy a folder:
XCOPY C:\utils D:\Backup\utils /i
To copy a folder including all subfolders.
XCOPY C:\utils\* D:\Backup\utils /s /i
But this command can help, not overwriting any files.
XCOPY C:\utils\* D:\Backup\utils /s /i /d
I'd like a batch script in Windows with which I can copy one directory to another. If this directory already exists, and then for each file that already exists in both with the same name and location, it should be overwritten, if it does not exists, it should just be added.
In the end it should be a batch script to which I can pass 2 arguments, source & destination.
In your batch file do this
set source=C:\Users\Habib\test
set destination=C:\Users\Habib\testdest\
xcopy %source% %destination% /y
If you want to copy the sub directories including empty directories then do:
xcopy %source% %destination% /E /y
If you only want to copy sub directories and not empty directories then use /s like:
xcopy %source% %destination% /s /y
It seems that the latest function for this in windows 7 is robocopy.
Usage example:
robocopy <source> <destination> /e /xf <file to exclude> <another file>
/e copies subdirectories including empty ones, /xf excludes certain files from being copied.
More options here: http://technet.microsoft.com/en-us/library/cc733145(v=ws.10).aspx
Have you considered using the "xcopy" command?
The xcopy command will do all that for you.
Try this:
xcopy %1 %2 /y /e
The %1 and %2 are the source and destination arguments you pass to the batch file. i.e. C:\MyBatchFile.bat C:\CopyMe D:\ToHere
Just use xcopy /y source destination