Robocopy option to force copy fail if destination folder does NOT exist - robocopy

I'm trying to use Robocopy as part of my backup procedures, whereby backup files are copied from one disk to another (for secondary and tertiary backups). I basically have one key external drive for primary backups, and then various of the backups get siphoned off to other disks, depending on which disk it is. I want to develop a sequence of Robocopy commands in a batch file that I can use in any situation, so that if the Robocopy command tries to copy a folder from the source to a destination drive where there is no matching folder, it automatically FAILS and moves on to the next command. Robocopy by default creates the destination folder if it does not already exist, and I want to switch this default OFF if at all possible.

Related

Automatically copy files in use

I have some files that are always in use and I want to make a copy of them automatically on another disk. I have tried Shadow Copy, but it does not put them in a specific path so that I can access them and send them in an email automatically
Automatically copy files in use
One way to make a copy of files that are always in use is to use the robocopy command-line utility. robocopy is a robust file copying tool that is built into Windows. It can handle copying files that are in use, and it has a wide range of options that allow you to customize the copy process.
For example, you can use the '/mir' option to mirror the source folder to the destination folder, the /r:n option to retry the copy operation a specified number of times if errors occur, and the '/w:n' option to specify the wait time between retries.
You can also use the '/log' option to create a log file of the copy operation, and the '/np' option to suppress the display of the file-transfer progress.
robocopy C:\SourceFolder D:\DestinationFolder /mir /r:3 /w:3 /log:C:\Robocopy.log /np
You can schedule this command to run at specific intervals using the Task Scheduler. Then you can use this command to copy the files that are in use at specific intervals.
Additionally you can use any language or automation tool to send the files after the copy operation is done

Copy files from single source to multiple destinations

I have a script to copy files from local machine to Azure blob, but my new requirement is to copy half of source files into one blob container and another half into another blob container. Let me know if I can do so using parallel or one after the other. I am using azcopy for now to move these files without splitting and from only one source to one destination.
.\AzCopy.exe /Source:$localfilepath /Dest:$Destinationpath /DestKey:$key1 /S
As I known, if there is a pattern for filtering these file names, you can use the parameter Pattern of AzCopy tool to separately upload them in two times, such as the command as below from the section Upload blobs matching a specific pattern of the offical tutorial if they are named with the a prefix.
AzCopy /Source:C:\myfolder /Dest:https://myaccount.blob.core.windows.net/mycontainer /DestKey:key /Pattern:a* /S
Here is the description of the parameter Pattern of AzCopy
/Pattern:"file-pattern"
Specifies a file pattern that indicates which files to copy. The behavior of the /Pattern parameter is determined by the location of the source data, and the presence of the recursive mode option. Recursive mode is specified via option /S.
If the specified source is a directory in the file system, then standard wildcards are in effect, and the file pattern provided is matched against files within the directory. If option /S is specified, then AzCopy also matches the specified pattern against all files in any subfolders beneath the directory.
If the specified source is a blob container or virtual directory, then wildcards are not applied. If option /S is specified, then AzCopy interprets the specified file pattern as a blob prefix. If option /S is not specified, then AzCopy matches the file pattern against exact blob names.
If the specified source is an Azure file share, then you must either specify the exact file name, (e.g. abc.txt) to copy a single file, or specify option /S to copy all files in the share recursively. Attempting to specify both a file pattern and option /S together results in an error.
AzCopy uses case-sensitive matching when the /Source is a blob container or blob virtual directory, and uses case-insensitive matching in all the other cases.
The default file pattern used when no file pattern is specified is . for a file system location or an empty prefix for an Azure Storage location. Specifying multiple file patterns is not supported.
Applicable to: Blobs, Files
If there is a simple pattern for files, you have to manually move them into the directories of their own category or write a simple script to filter them to generate the command strings for uploading. Then you can use Foreach-Parallel in PowerShell to realize the parallel upload workflow to satisfy your needs.

Powershell: Copy-Item -Recurse -Force is not copying all sub files

I have a one liner that is baked into a larger script for some high level forensics. It is just a simple copy-item command and writes the dest folder and its contents back to my server. The code works great, BUT even with the switches:
-Recurse -Force
It is not returning the file with an extension of .dat. As you can guess what I am trying to achieve, I need the .dat file for analysis. I am running this from a privileged account. My only thought was that it is a read/write conflict and the host file was currently utilizing it (or other sys file). What switch am I missing? The "mode" for the file that will not copy over is -a---. Not hidden, just not copying. Suggestions elsewhere have said to use xCopy/robocopy- if possible I do not want to call another dependancy- im already using powershell for the majority of the script, id prefer to stick with it....Any thoughts? Thanks in advance, this one has been tickling my brain for a little...
The only way to copy a file in use is to find the locking handle close it then retry the copy operation(handle.exe).
From your question it looks like you are trying to remotely copy user profiles which includes ntuser.dat and other files that would be needed to keep the profile working properly. Even if you did manage to find a way to unload the dat file(s), you would have to consider the impact that would have on the remote system.
Shadow copy is typically used by backup programs to copy files in use so your best bet would be to find the latest backup of each remote computer and then try to extract the needed files from the backed-up copies or maybe wait for the users to logoff and then try.

Execute robocopy powershell continuously between two times established

I have a program that creates temporary files in a specific folder. Then, automatically, after a few seconds, these files are deleted.
I wanted to copy those temporal files to an specific folder, I would like to use a powershell script to do this:
robocopy startFolder destinationFolder *.TIFF *.JPEG *.jpg *.PNG *.GIF *.BMP *.ICO *.PBM *.PGM *.PPM /s /XO
My problem is that I couldn't use a scheduled task (because of the problem with limitation of seconds) or install this powershell as a Windows Service with a powershell script (as far as I know is a bad practice) . I need this powershell running all the time trying to get files at the moment that they are created, before this folders were deleted.
Could you give me a hand please? Thanks!
Not sure it's quite what you want, but robocopy does have directory monitoring funcitonality built-in. You could add /mon:1 which should monitor the source directory and re-run the copy when it detects one change (a new or changed file, for example).
However, a down-side of this perhaps is that using this method, robocopy won't exit - it will run until you kill it.
Edit: I've just noticed you specify in your question title that this should run between two established times, in which case you could add the /rh:hhmm-hhmm option to specify times between which new copies can be started. For example, /rh:1000-1200 should only perform the copies (and hence monitoring) between 10am and midday.
Caveat: I've not tried using the "monitor" option of robocopy, so I'm not sure what sort of delay there would be between a change taking place, and the copy being re-run, but it's worth a shot.

Shadow copy to clone system volume on Windows XP

I am looking for a program that uses shadow copy to copy the contents of a Windows XP system volume that is running.
I.e. I want to clone the system volume with the following snags:
(1) I want to be able to select which files to copy (i.e. not the entire file system)
(2) This is probably implied by (1), but I also have to avoid sector-by-sector copies
(3) I do not want to clone a file system into an image file and restore to a 3rd drive but want to do a filesystem to filesystem copy
All the backup/clone utilities I looked into stumble on one of above points. Any ideas?
Perhaps this one: Hobocopy