Robocopy: Move only folders including contents older than date specified

Rick 41 Reputation points
2022-11-07T11:22:50.247+00:00

I am trying to move folders from one server to another that are older (date modified) than August 31, 2021. I need it to move the folders regardless of the file dates.

I have the following parameters, but just copied still compares the files dates and moves only older files.

robocopy "\\source\Folder1" "\\dest\Folder2" /E /ZB /SECFIX /COPYALL /MOV /TEE /R:5 /W:10 /MINAGE:20210831  
Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 36,416 Reputation points
    2022-11-08T23:59:36.777+00:00

    Run "robocopy /?". Minage references files, not folders.

    /MINAGE:n :: MINimum file AGE - exclude files newer than n days/date.  
    

    With Powershell, we can look at the directories and analyze the dates. The main question is how you want to handle subfolders. If you want to process the folders all at the same level, then there should not be a issue with using the /MOV switch.

    \source\share\folder1
    \source\share\folder2
    \source\share\folder3

    $TargetDate = get-date "August 31, 2021"  
    $Source = "c:\temp"  
    $Dest = "Z:\Temp"   
    Get-ChildItem -Path $Source -Directory  | Where-Object -Property LastWriteTime -lt $TargetDate | foreach {  
        $RcDest = $Dest + $_.FullName.Substring($Source.Length)   
        Write-Host "robocopy $($_.fullname) $RcDest /mov /e /l"     # just display the robocopy command to execute  
        # Uncomment the next line and fix switches to actually execute robocopy   
        #robocopy.exe $($_.fullname) $RcDest /mov /e /l  
    }   
    

    But if you want to move some subfolders but not others, then you will need to test thoroughly to verify that the files and folders get processed correctly.

    \source\share\folder1\folder2\folder3\folder4

    So if you wanted to move the files in folder2 and 4 but not 1 and 3, then you would need to use the -recurse switch on Get-childitem and you could not use /e with robocopy.


  2. MotoX80 36,416 Reputation points
    2022-11-10T16:57:26.167+00:00

    Permissions are all Active Directory groups, correct? That is, no local users or groups.

    \source\share\folder1 locally might be something like E:\Data\folder1. The concern that I would have is: where does permission inheritance start? If folder1 does not inherit permissions from data, then a "folder1 to folder1" should be a straightforward copy.

    For the sake of argument, let's say that \dest\share points to N:\NewData

    If folder1 does inherit from data, then I'd make sure that the permissions on N:\NewData match those on E:\Data.

    /E :: copy subdirectories, including Empty ones.
    /ZB :: use restartable mode; if access denied use Backup mode.
    /SECFIX :: FIX file SECurity on all files, even skipped files.
    /COPYALL :: COPY ALL file info (equivalent to /COPY:DATSOU).
    /MOVE :: MOVE files AND dirs (delete from source after copying).
    /R:5 :: number of Retries on failed copies:
    /W:10 :: Wait time between retries:

    I'm just real cautious when doing a data migration. Bad things happen. That's why I would not delete any source files/folders until I completed the migration and verified that everything got copied and permissions were checked. So /MOVE is the only switch that I would question.

    One suggestion that I would have is: don't have the PS script call robocopy.exe directly. Just have the script build and display the robocopy commands. Pipe them to a DataMover.bat file. Edit the file with notepad and pick a folder or 2 or 3, and manually run those robocopy's. Validate that everything worked correctly before running the .bat file to move the "hundreds of folders".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.