Is it possible to use the robocopy command with the monitor source switch to copy files with a new file name when they change?
I use the command below but would like to explore leave it running for several hours and capturing changes. In its current state the command overwrites changes in the destination folder.
report.txt can have several changes (say at 10:00 and 3:00) I would like to have each version saved as report_1000.txt and report_0300.txt.
robocopy \\temp\output c:\users\eric\desktop\robocopy\ report.txt /mon:1 /r:4000
Related
I am a bit confused on how to achieve this. Any input would be great.
I have a source dir and a target directory. During copy, if the file exists with same last modified stamp, then don't bother doing anything to save CPU resources.
If the source dir has a file that exists in target but the source version has a newer modified date, then the existing file in target directory should be renamed to file_yyyymmddhhmmss (the old modified date)
This way the new file can get in.
I got the basic copy here but struggling how can i amend this?
#Set source directory
$sourcedir="D:\Temp\2023\Source"
#Set target directory
$destinationdir="D:\Temp\2023\Destination"
#Set logfile - Add YYMMDDHHMMSS to log
$logfile="D:\Temp\2023\Log.txt"
robocopy $sourcedir $destinationdir /e /xo /log:$Logfile
If you think this can be achieved in Batch script, then fine. Otherwise Powershell is first preference.
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
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.
I am having an intermittent issue with ROBOCOPY copying files with an incorrect date.
I am using ROBOCOPY to copy backup files from a local folder to a remote fileshare as a part of having a remote backup solution. The script is scheduled through task manager to run daily. Here is pseudo code:
ROBOCOPY E:\LocalFolder \\RemoteServer\FileShare\Folder *.bak
Most of the files copy with the correct file date, hovever one or two files sometimes will have the date of 1/1/1980. This presents a major issue with managing the backups in the fileshare because the dates are crucial to its management.
What might causes this?
What can be done to prevent this behavior?
I was having a similar issue. After some searching, I found reference to a behavior of Robocopy where it sets the modified date to 1/1/1980 until after a transfer is completed. [source]
What was really strange in my case was, if I watched the directory during the copy, I would see the file with the correct date appear, then AFTER it was complete the date would change to 1/1/1980. After some experimentation, I removed the /B switch I had been using and the dates seemed to be left alone.
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.