Backup Education
This is the ultimate robocopy examples list - Printable Version

+- Backup Education (https://backup.education)
+-- Forum: Windows Server (https://backup.education/forumdisplay.php?fid=22)
+--- Forum: Utilities (https://backup.education/forumdisplay.php?fid=23)
+--- Thread: This is the ultimate robocopy examples list (/showthread.php?tid=1122)



This is the ultimate robocopy examples list - savas - 10-22-2024

Robocopy is a powerful command-line tool that can make file copying and backup tasks so much smoother. For instance, using the command "robocopy C:\Source D:\Destination /E" copies everything, including empty directories, from the source to the destination. This is great for ensuring that your backups are complete, but it can also take a while if you have a lot of files, so keep that in mind.

If you want to skip files that haven’t changed, you can use "robocopy C:\Source D:\Destination /MIR". This command mirrors the source and destination, which is efficient for backups. However, be cautious, as it will also delete files in the destination that are no longer present in the source, which might lead to data loss if you’re not careful.

Sometimes, you might only want to copy specific file types. With "robocopy C:\Source D:\Destination *.jpg /S", you can do just that. This command copies all JPEG files, but you need to remember that the "/S" flag excludes empty directories. It’s super handy for media backups but won’t grab those empty folders if you need them.

If you’re dealing with large files and want to copy them without the hassle, "robocopy C:\Source D:\Destination /J" is a game-changer. The "/J" flag allows for unbuffered I/O, which can significantly speed up the process for large files. However, this might not work well on all systems, especially if your drives don’t support unbuffered transfers.

For situations where you want to limit the number of retries in case of errors, "robocopy C:\Source D:\Destination /R:3" is useful. This command will retry three times on failed copies. It’s a good way to prevent endless loops in case of persistent issues, but be cautious not to set the retries too low, or you might miss out on copying files that could succeed after a few more attempts.

When you need to preserve file timestamps, "robocopy C:\Source D:\Destination /COPY: DAT" ensures that data, attributes, and timestamps are preserved. It’s crucial for maintaining the integrity of backups, but it’s worth noting that it can slow down the copy process if you have a lot of files with varying timestamps.

If you want to mirror the directory structure without copying files, "robocopy C:\Source D:\Destination /E /CREATE" is what you need. This creates the folder hierarchy at the destination but leaves out the files. It’s a neat way to set up a backup structure without data, but you’ll have to follow up with another command to actually copy the files later.

For those who prefer to see progress, using "robocopy C:\Source D:\Destination /V /NP" gives you verbose output without showing progress percentage. This can be really helpful when copying a large number of files, as it provides feedback without overwhelming you with too much information. However, if you prefer a cleaner output, you might find it a bit cluttered.

When copying over a network and you need to set a bandwidth limit, "robocopy \\NetworkSource D:\Destination /IPG:50" limits the inter-packet gap to 50 milliseconds. This is useful for avoiding network congestion, but setting it too high could slow down your transfers significantly.

To exclude specific file types, "robocopy C:\Source D:\Destination /XF *.tmp" lets you skip temporary files during the copy process. This can be a real time-saver if you have a lot of clutter. Just be aware that you may need to add more exclusions as needed to keep your destination tidy.

If you’re working with very large directories, "robocopy C:\Source D:\Destination /L" will simulate the copy without actually moving any files. This is a great way to check what would be copied without risking any data. However, it’s not a solution for actually making backups, so you'll need to run the command again without the "/L" to perform the actual copy.

For those who want to preserve file permissions, "robocopy C:\Source D:\Destination /COPY:ALL" includes everything in the copy process. This is essential for maintaining access controls, but it can make the operation slower and more complex if you have a lot of files with various permissions.

Using "robocopy C:\Source D:\Destination /MAXAGE:30" allows you to only copy files that have been modified in the last 30 days. This is super handy for incremental backups, but be careful if you need older files, as they won’t be included in this operation.

When you need to log your operations for auditing, "robocopy C:\Source D:\Destination /LOG:C:\Logs\robocopy.log" saves the output to a log file. This is fantastic for tracking what was copied, but make sure you have enough disk space, as logs can grow quite large depending on your operations.

If you want to copy files based on their size, "robocopy C:\Source D:\Destination /MIN:1000000" will only copy files larger than 1MB. This can help in managing large datasets efficiently, but you might miss smaller files that could be crucial later.

When copying from a slow or unreliable source, using "robocopy C:\Source D:\Destination /Z" enables restartable mode, which allows the transfer to resume if it gets interrupted. This is a lifesaver for lengthy transfers, but it can be slower than standard copies because of the additional overhead.

For users who need to see a summary after the copy, "robocopy C:\Source D:\Destination /S /NFL /NDL" excludes files and directory lists from the output, giving you a concise summary of what was done. This is helpful for quick checks, but you might miss detailed information if something goes wrong.

If you want to ensure files are copied only if the source is newer, "robocopy C:\Source D:\Destination /MAXAGE:30 /XO" copies files only if they are older than 30 days and skips those in the destination that are newer. This is excellent for keeping backups up to date without unnecessary duplication, though you have to be careful about the age criteria you set.

Using "robocopy C:\Source D:\Destination /COPY: DAT /XJ" allows you to copy data and attributes while excluding junction points. This is helpful for avoiding issues with circular references. Just keep in mind that you might be missing some data that was linked through junctions.

For a more granular approach, "robocopy C:\Source D:\Destination /MINAGE:30" will only copy files that are at least 30 days old. This is useful for archiving older files while leaving newer ones untouched, but you’ll need to ensure that this aligns with your overall file management strategy.

If you need to maintain the owner of files, "robocopy C:\Source D:\Destination /COPY: DATO" is the command to go with. This ensures data, attributes, timestamps, and owner information are preserved. However, it can add complexity, especially in environments with various user accounts.

When managing logs, you might want to rotate them to avoid using too much space. Using "robocopy C:\Source D:\Destination /LOG+:C:\Logs\robocopy.log" appends log entries to an existing log file instead of overwriting it. This is great for keeping historical data, but it’s essential to monitor log size to prevent disk space issues.

If you need to maintain all NTFS file properties, "robocopy C:\Source D:\Destination /COPYALL" does the trick. It copies all attributes, including permissions and timestamps, ensuring that everything remains intact. However, this can be slower, especially for larger datasets, so weigh that against your needs.

In instances where you want to limit the copy to certain times of day, you can use scheduled tasks alongside robocopy commands. For example, running a task that executes "robocopy C:\Source D:\Destination /S" every night at midnight ensures you have a fresh backup every day. This setup is reliable but requires initial configuration and monitoring.

If you’re dealing with network drives and need to ensure they are accessible before copying, "robocopy \\NetworkSource D:\Destination /R:5 /W:5" retries the connection five times with a wait of five seconds between each try. This can help avoid disruptions, but if the network is persistently down, you may end up waiting unnecessarily.

For a final trick, you can combine commands. Running "robocopy C:\Source D:\Destination /E /MOV" not only copies files but also moves them, clearing out the source. This is handy for reorganizing files but can lead to data loss if you accidentally move something you wanted to keep.

Each of these commands showcases the versatility of robocopy for various scenarios. The flexibility it provides can make data management tasks simpler and more efficient, but it's always important to be mindful of what you’re doing to avoid unintended consequences.

Those were a lot of robocopy commands, indeed. However, you may also want to check out my post Why robocopy is not good for backups! because robocopy really is not meant to be a backup solution...