Solved

Moving files older than a certain date, but keeping folder structure

Posted on 2012-12-26
6
1,651 Views
Last Modified: 2013-01-03
Hi team

I'm in need of a solution to move files older than 3months off the file server (Server 2008 (Not R2)) onto an external hard drive or network share. I'm by no means skilled in creating script commands, but from what I've read most of the solutions would mean removing the folders etc from the source when moving to the destination which isn't what I want to do.

I'm hoping when the files are moved, the file structure will effectively look identical in both locations making it easier to track down these files if required.

Is this something that can be done, or am I expecting too much?

Cheers
0
Comment
Question by:DTS-Tech
  • 4
6 Comments
 
LVL 59

Accepted Solution

by:
Darius Ghassem earned 250 total points
ID: 38722490
You can use something like Robocopy ot Richcopy to copy all data off to another drive both of these have gui so you can use this without scripting

http://blogs.technet.com/b/ken/archive/2009/06/10/build-4-0-216-has-been-posted-to-the-microsoft-download-center.aspx
0
 
LVL 28

Expert Comment

by:becraig
ID: 38722506
This might help:

param ([string] $SourceFolder, [string] $DestFolder,  [string] $DDate);


write-host $sourcefolder
write-host $destfolder
write-host $ddate

if (!(Test-Path $SourceFolder)) 
{ write-host "Source $sourcefolder does not exist!" }
if (!(Test-Path $DestFolder)) 
{ write-host  "Destination $destfolder does not exist!" }


$FileList = Get-ChildItem $SourceFolder -recurse
ForEach ($FileObj in $FileList) {
if ($fileobj.LastWriteTime -lt (Get-Date).AddDays(-$Ddate))
	{
write-host "$FileName = $FileObj.Name"
write-host "$fullpath = $FileObj.FullName"

$FileName = $FileObj.Name
$fullpath = $FileObj.FullName
write-host "$copypath = [regex]::Replace($Fullpath,'$SourceFolder','');"
$copypath = [regex]::Replace("$fullpath", "$SourceFolder",'');
$destpath = $DestFolder + $copypath

Copy-Item "$fullpath" "$destpath"


	}

				}
  

Open in new window

0
 
LVL 28

Expert Comment

by:becraig
ID: 38722513
I forgot to add usage :

script name (whatever you save it as .ps1)
script.ps1 -sourcefolder c:\sourcefolder -destfolder c:\destfolder -ddate40

That should do it.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 28

Assisted Solution

by:becraig
becraig earned 250 total points
ID: 38722742
It seems I had an error in the script I posted:  updating below-

param ([string] $SourceFolder, [string] $DestFolder,  [string] $DDate);
if ($SourceFolder -eq "" -or $DestFolder -eq "" -or $DDate -eq "")
{ 
write-host "
`t You failed to specify correct syntax
`n
`t Usage: script.ps1 -sourcefolder c:\folder -destfolder c:\folder2 -ddate 40 
" -fore red
}
else
{
if (!(Test-Path $SourceFolder)) 
{ write-host "Source $sourcefolder does not exist!" }
if (!(Test-Path $DestFolder)) 
{ write-host  "Destination $destfolder does not exist!" }

$FileList = Get-ChildItem $SourceFolder -recurse
ForEach ($FileObj in $FileList) {
if ($fileobj.LastWriteTime -lt (Get-Date).AddDays(-$Ddate))
	{
$FileName = $FileObj.Name
$fullpath = $FileObj.FullName
$copypath = ($fullpath -replace [regex]::Escape($SourceFolder), '')
$destpath = $DestFolder + $copypath

Copy-Item $fullpath $destpath
	}
				}
}

Open in new window


Give it a go ...
If you need any extra functionality like not copying files already present etc let me know.
0
 
LVL 28

Expert Comment

by:becraig
ID: 38740585
Were you able to test this and did you have any additional questions ?
0
 

Author Comment

by:DTS-Tech
ID: 38742328
Sorry for the delay in the update, I haven't moved the files yet, but at this stage I think I'll end up using the Richcopy application due to the GUI. Though I do appreciate the script you've written out
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I was supporting a handful of Windows 2008 (non-R2) 2 node clusters with shared quorum disks. Some had SQL 2008 installed and some were just a vendor application that we supported. For the purposes of this article it doesn’t really matter which so w…
This article is an update and follow-up of my previous article:   Storage 101: common concepts in the IT enterprise storage This time, I expand on more frequently used storage concepts.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now