QuickTip – RoboCopy – Command to Move Files Older Than Certain Number of Days, with Directory Structure
Let’s say that you have a design department share that is filling up your datastore of one of your on-premises ESXi servers hosting some Windows file servers. Your budget to upgrade your host servers has been delayed and, thanks to Covid-19, now, even further out. You need to keep this datastore from filling up but don’t want to force the end users to deal with changes on their Macs but still allow the data to be accessible. The design manager has agreed to allow data older than a few years to be tiered to other storage.
Assuming you have found (or somehow managed to make) another datastore with greater available capacity or some other storage presented via the same (or even another) Windows file server , you can use a single Robocopy command to move the files from one directory/server/share to another accessible share.
robocopy "\\FP03\DesignShare\Images\" "\\FP03\DesignSharearchive\Images\" /mov /minage:1875 /copyall /e >c:\temp\FilesOver1875daysMoved.txt
- Paths – The first path is the source.The second, is the destination.
- The /mov switch is to specify that we are moving the file, not just copying it.
- /minage is the minimum age, specified in number of days, that you want to allow to stay in the source path.
- The /copyall switch is the equivalent to using the /copy:DATSOU command, which will include the Data, Attributes, Time stamps, NTFS ACL, Owner Info and Auditing Info. The /e switch allows for sub-directories (including empty directories) to be replicated on the destination side.
- The final element of this command is a txt log file that records a list of all the files/paths moved. You can also use another command, combined with this log file to restore all the files moved to the source path. If you do use this, make sure that you are saving this to a more permanent and accessible location than C:\temp. Maybe I will post that at some point in the future.