How to use Robocopy to copy files with TimeStamp in command line - windows

Following is my command to copy the files in my computer and from my computer to network.
ROBOCOPY "K:\Builds" F:\Builds\ /E /COPY:DAT
ROBOCOPY "E:\" "K:\Shan Khan\" /E /COPY:DAT
How i can make timestamp in destination folder only when copying the file for example
"K:\Builds" when copied to F:\Builds\
F:\Builds\ ---> F:\Builds_26092015
"E:\" when copied to "K:\Shan Khan\Workspace"
"K:\Shan Khan\Workspace"---> "K:\Shan Khan\Workspace_26092015"
Kindly note that K drive is password protected and i manually saved the password while mapping the IP address to K drive.

I tried this lines and it works.
it created the directory in such a way
Fri 06_26_2015
for /f "tokens=1* delims=" %%a in ('date /T') do set datestr=%%a
md F:\Builds\"%date:/=_%"
ROBOCOPY "K:\Builds" "F:\Builds\%date:/=_%" /E /COPY:DAT /DCOPY:T

Related

Backup from server, folders to ftp and passing problems

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.

batch for loop file search

#ECHO OFF
SET driveLetter=%~d0
FOR /R %%x IN (*.pst) DO (
ROBOCOPY %%x %driveLetter%\%%x /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
)
PAUSE
EXIT
I can't get this working. What I want to do is search the user folder (incl. subfolders) for any .pst files and then copy these to a flash drive.
Pretty simple actually just use xcopy:
xcopy c:\users\%username%\*.pst F:\ /e
(replace F:/ with drive location if its not F).
#ECHO OFF
SET driveLetter=%~d0
ROBOCOPY %USERPROFILE% %driveLetter%\Outlook *.pst /S /COPYALL /ZB /XJ /MT:20 /R:2 /W:5
PAUSE
EXIT
Solution. Thanks to everybody.

BATCH - Mirrow two Folders in both Ways

I safe some Files at my Local Drive(Laptop) and also have Files saved at my Network Storage at Work.
I want that both Folders have the same Files, If I create/delete or change an File in one Folder, the other Folder should get Updated when I use the BATCH.
It should use the newest Version on an Document.
So I tried it with ROBOCOPY Folder01 Folder02 /MIR /R:3 /W.20, it worked but only in one Way, from Folder01 to Folder02, so if I created an File in Folder02 and used the Batch, the File got deleted.
Then I tried to copy both Folders into one TEMP Folder and then copy the TEMP-Files to both Folders. I used
ROBOCOPY Folder01 TEMP /XO /E /R:3 /W:20
ROBOCOPY Folder02 TEMP /XO /E /R:3 /W:20
ROBOCOPY TEMP Folder01 /MIR /R:3 /W.20
ROBOCOPY TEMP Folder02 /MIR /R:3 /W.20
this was almost perfect, always the newest Document was used and everything was there, but when I delete a File from Folder01, which still exists in Folder02, it will come back next time I use my BATCH.
Sorry for my English
Greetings, Tobias
Try this solution provided by #Sachadee with Xcopy
:://Synchro.bat
:://SachaDee 2014
#echo off&cls
:: We set Folders to synchonized
set "Folders= C:\HackooTest E:\Backup\Folder1 E:\Backup\Folder2 E:\Backup\Folder3"
for %%a in (%Folders%) do (
for %%b in (%Folders%) do (
if not "%%a"=="%%b" (
set "VAR%%a%%b=%%a %%b"
)
)
)
for /f "tokens=2,3 delims== " %%a in ('set VAR') Do (
echo xcopy "%%a" "%%b" /E /D /C /Y /I
)
pause

Copy profile data using robocopy with permission

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

Robocopy - Copying folders and files doesn't recreate directory structure

Well, it kind of does but skips one level I think. So, here's folder structure I have (Windows 2008 R2 SP2 standard):
ClientA
|_ClientAfolder1
|_ClientAfolder2
ClientB
|_ClientBfolder1
|_ClientBfolder2
And so forth...
Here's the script I'm using:
for /f "delims=" %%a in ('type "folderlist.txt" ') do robocopy "%%a" "Z:\temp\test" /E /xo /fft /COPYALL /r:0 /w:0
My folderlist.txt looks like this:
f:\ClientA\ClientAfolder1
f:\ClientA\ClientAfolder2
f:\ClientB\ClientBfolder1
f:\ClientB\ClientBfolder2
And after executing the script, my folder structure becomes like this:
ClientAfolder1
ClientAfolder2
ClientBfolder1
ClientBfolder2
So, it skips creating parent folders which are ClientA and ClientB. What am I doing wrong?
Thank you for any help.
for /f "usebackq delims=" %%a in ("folderlist.txt") do (
robocopy "%%a" "Z:\temp\test%%~pnxa" /E /xo /fft /COPYALL /r:0 /w:0
)

Resources