rsync copy for a lots of different types of extensions - macos

I'm trying to copy all of the mac files to usb external drive.
The purpose is, I need to copy specific types of file for internal investigation.
The Equivalent Robocopy command on Windows will be like this
Robocopy C:\ D:\Company\Dept.\username /S /DCOPY:T /TEE /R:1 /W:1 /NP /FP /V /TS /NDL
/BYTES /Log:D:\Company_Dept_userame.Log *.doc *.ppt *.xls *.docx *.pptx *.xlsx *.pdf
*.gul *.hst *.db *.dbf *.dzw *.dzi *.dbs *.mdb *.accdb *.pst *.eml *.msg *.edb *.dbx
*.ost *.mbox *.zip *.ace *.arj *.cab *.egg *.7z *.enc *.alz /XD Dirs "Documents and Settings" "Application Data"
it's pretty simple, copy the target file types from the entire OS disk to the external drive and make a log for this file copy.
But, for MacOS, I couldnt't make it using Rsync or using the CP. it just doesn't work for me making file path errors and I couldn't find any answers I could use neither.
Can anyone please help me to solve this issue?
Manual copying is such a pain.
Thank you,
Steve

I didnt want to post an answer to my question but just wanted share and hope there shouldn't be no more stupid like me.
I found the reason. I was running the source path as absolute path. I needed to cd to the root, which is Macintosh HD by
cd /
and then run the rsync command.
In my case, I'm copying all of my OS disk specifying a lots of extensions to the external disk so I ticked -aPcx which means
archive,skip checksum, exclude other disks.
especially 'x' option is important otherwise you'll get a copy of USB disk itself to the destination folder.
rsync -aPcx --prune-empty-dirs --log-file=/Volumes/SSD/Company_Dept_username.log --include=*/ --include=*.{hwp,doc,ppt,xls,docx,pptx,xlsx,pdf,gul,hst,db,dbf,dzw,dzi,dbs,mdb,accdb,pst,eml,msg,edb,dbx,ost,mbox,zip,ace,arj,cab,egg,7z,enc,alz} --exclude=* . /Volumes/SSD/Company/Dept/username

Related

XCOPY crashing when I try to copy and rename 80K files. Is there a better way?

Probably there is a better approach to fix what I am trying to do. I have a folder with pictures that I want to copy to another folder renaming them.
Basically, I have a list of all the 80K files of the file name they have, and what is the new name that they should have. There is no fixed pattern to rename the files. What I’ve been doing is using Excel to find the path and current file name and then renaming the files checking the new file name in a SQL database.
Basically, for every file I form a XCOPY line then I paste them on powershell.
echo F|xcopy /s /q /y /f "file path" "renamed file path"
My problem is that for some reason powershell stops processing the xcopy lines after approximately 4K files. I already tried running this as a BAT with these lines for each file.
xcopy /s /q /y /f "file path" "renamed file path *" with an asterisk at end to avoid the question if it’s a file or a folder. But it stops processing after 2K files.
I know that robocopy is better than xcopy but I need to rename each file, and there is not a clear pattern in the renaming, I don’t know how to do a robocopy each file and then rename each file, but that should be even worse no?
Also, the server has a good SSD and its only processing 1 xcopy line per each second, should be a lot faster. The .jpg files are small (˜200Kb).
Any ideas are appreciated.
Regards,
Tiago

How to copy a file from a USB drive to C drive in Windows 10 using a batch file?

I have some files in a USB drive which need to be copied to multiple computers. These files contain an executable which will use the other config files.
My issue is, for Windows 10 PCs, while the temp_folder gets created, none of the files get copied.
For windows 7 I was able to create a batch file which copied the files to the local drive and ran the executable using the config files.
The batch file contents were as below :
mkdir C:\temp_installer
copy ".\file_name" "C:\temp_installer"
<rest of the code>
I have tried using xcopy and robocopy, but still see the batch file run and just stop at creating the folder. The same issue isn't observed in Windows 7.
Has someone tried this or can someone tell me what I might be doing wrong?
This would be a better option, we do not need to be concerened about permission issues on the root of C:
#echo off
cd /d "%~dp0"
set "inst_dir=%temp%\temp_installer"
mkdir "%inst_dir%">nul 2>&1
for %%i in (*) do if not "%%i"=="%~nx0" copy /Y "%%i "%inst_dir%"
:# When completed, we can call execute the files from "%inst_dir%"
The for loop is not needed to be honest, I am only doing it to not copy the .bat/.cmd file itself to the folder as there would be no need for it there.
Or even simpler, without having to do all the above, you could just use robocopy
#echo off
cd /d "%~dp0"
robocopy /MIR .\ "%temp%\temp_installer"
Powershell is your friend here, try this:
Copy-Item E:\Document\ C:\Temp\Document\ -R
Works great for me and it even creates destination directory, also Copy-Item has alias cp and copy.
If you running some sort of script, you might have issues with Execution-Policy: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6

Delete files do not exist in source folder in cmd?

I have two folders that I backup from source to destination folder using command:
xcopy /E /Y /I /D
Now I want to delete files in destination folder that do not exist in source folder.
There is no 'mirroring' option in xcopy. I have 2 suggestions:
1.
you could run xcopy dest source /L > todelete.txt to obtain a list of files which exist in dest but not in source. Then use a for loop to delete these files in dest.
or
2.
Use robocopy which was designed to use the same options as xcopy but has a lot more funtionality. For instance, a /MIR option to mirror one folder to the other. robocopy is included in all Windows versions from Vista on (the Win7 version might run under XP as well - not tested though).
Besides, it is way faster and and and...

DFRS has gone mad. Copying old files back

My Issue
Our DFRs has gone mad and was having issues. It started copying back older versions of files from the destination to the source server.
Users have been updating files in the source server since last nights backup.
I am not sure what has been copied back though.
What I want to do is check the timestamp of files located in \SourceServer\Folder1 (and sub folders) and \TargetServer\Folder1 (and sub folders) and copy the latest version of all files to a separate Folder (say \SourceServer\Folder2)
Then I can restore the other files from last nights backup.
I have seen a way to use Powershell Compare-Object but only using a -referenceObject and a -differenceObject
All help is greatly appreciated.
Thanks in advance
You could use robocopy for that task. Run the following on SourceServer:
robocopy C:\path\to\Folder1 C:\path\to\Folder2 /e /copyall /dcopy:t /xj
robocopy \\TargetServer\Folder1 C:\path\to\Folder2 /e /copyall /dcopy:t /xj /xo
For general troubleshooting of DFS-R see here and here.

Windows batch command to move all folders in a directory with exceptions

I am trying to write a Windows Batch file that will allow me to move all directories within a given source directory into a target directory that exists within that source directory.
Obviously my move command with need to only apply to directories and also exclude the target directory from being processed.
Is this possible with a Windows batch command?
Robocopy (present in recent versions of windows or downloadable from the WRK) can do this, just use the /xd switch to exclude the target directory from the copy;
robocopy c:\source\ c:\source\target\ *.* /E /XD c:\source\target\ /move
FOR /d %%i IN (*) DO IF NOT "%%i"=="target" move "%%i" target
That won't work - you'll get an error telling you the target directory is inside the source directory or so, even if you explicitly exclude the target directory. What you can do is move the directories to a temporary location which is not under the source, and then move them into the target.
BTW, using the move command won't let you specify folders to exclude. For that you can use xcopy, but note that it will copy the folders, as opposed to move them. If that matters, you can delete whatever you want afterwards, just make sure you don't delete the target dir, which is in the source dir...
Using robocopy included with Windows 7, I found the /XD option did not prevent the source folder from also being moved.
Solution:
SET MoveDirSource=\\Server\Folder
SET MoveDirDestination=Z:\Folder
FOR /D %%i IN ("%MoveDirSource%\*") DO ROBOCOPY /MOVE /E "%%i" "%MoveDirDestination%\%%~nxi"
This loops through the top level folders and runs robocopy for each.
NB: Robocopy mentioned above using the /move flag will copy the files and then delete them from the source folder rather than moving the files. This may be critical if moving large numbers of files from one location to another on the same disk (because move is virtually instantaneous, while copying is a much slower operation)
On windows batch:
FOR /d %%i IN (MySourceDirectory\*) DO move "%%i" MyTargetDirectory\%%~ni
The above command moves all directories found in MySourceDirectory (/d) to MyTargetDirectory using the original directory name
(~ni) Robocopy's move first does a copy, then delete, so it is slower.
This works for me:
move c:\fromDir\*.* c:\toDir\

Resources