A N

June 10, 2016

RoboCopy – Copy files from source to destination with x days old

Filed under: Tips — donrsh @ 11:47 am
<#	
	.NOTES
	===========================================================================
	 Created on:   	2016-06-08 
	 Created by:   	Arash Nabi
	 Email: 	arash@nabi.nu 

	===========================================================================
	.DESCRIPTION
     # /SEC           - Copies files with security
     # /R:1           - Specifies the number of retries on failed copies.
     # /W:1           - Specifies the wait time between retries, in seconds.
     # /NP            - Specifies that the progress of the copying operation (the number of files or directories copied so far) will not be displayed.
     # /FP            - Includes the full path names of the files in the output.
     # /V             - Produces verbose output, and shows all skipped files.
     # /MOVE          - Moves files and directories, and deletes them from the source after they are copied.
     # /maxage:<N>    - Specifies the maximum file age (to exclude files older than N days or date).
     # /log:<LogFile> - Writes the status output to the log file (overwrites the existing log file).
     # /minage:<N>    - Specifies the minimum file age (exclude files newer than N days or date).
     # /L             - Specifies that files are to be listed only (and not copied, deleted, or time stamped).	
     # /S             - Copies subdirectories. Note that this option excludes empty directories.
     # /FP            - Includes the full path names of the files in the output.
     # /NC            - Specifies that file classes are not to be logged.
     # /TS            - Includes source file time stamps in the output.
	 	
#>



$Time = (get-date -Format T).Replace(':','.')
$TimeDay = get-date -Format "yyyyMMdd"
$DateMonth = get-date -Format "yyyyMM" 
$Y = New-Item -Path "c:\temp\log\" -ItemType Directory -Name $TimeDay -Force
$Log = "C:\temp\log\$TimeDay\LogTime-$Time.txt" 
$MinAgeDate = (get-date).AddDays(-2) | get-date -Format "yyyyMMdd" 
$Dir = 'C:\temp\Archive\'
$Destination = 'C:\temp\Archive2'
$RoboCopyList = Invoke-Expression -Command  "Robocopy $Dir $Destination\$DateMonth /S /COPYALL /MINAGE:$MinageDate /MOV /R:10 /W:5 /TS /NFL /ETA /LOG+:$log"
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: