Script to calculate how much I can fit on a disk?

Hi There,

Basically I have a large network disk 10TBs.

Occasionally I want to back this up to two 5TB USB disks.

Every time I do this I have to try and find out how much I can fit on the first disk - basically by trial and error.  i.e. I select a load of folders (all in alphabetical order) from say Australia to Denmark then check the size.  I want to fill the first disk as much as possible.  If I don't fill the disk enough or have too much data I will select and check the size again.

Is there any way I could script this so that when I tell the script the size of the first disk it returns something like:

on this 5TB disk you can fit from Australia to Latvia.

Hope that makes sense any help greatly appreciated!

Regards

Rob
LVL 1
robclarke41Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
What about a script doing the copy?
Do you want to have each folder on exact one of both disks only?
0
Bill PrewCommented:
We could probably adapt some of the code in this prior solution:

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_27482608.html#accepted-solution

It only copied one file after checking if it fit, but with a little adjustment we could process multiple files to two locations.  A few questions though:

Do you care about optimization at all?  Meaning, if we just process folders alphabetically say, when we get to the next folder that wont fit on the first destination, we will start sending to the second.  But there could be a smaller folder after the one that didn't fit that would fit.  Do you care?

There are plenty of utilities that exist for this purpose, have you looked at / considered any of those, or does this have to be a "no install" scripting solution?

~bp
0
robclarke41Author Commented:
Hi Qlemo,
I can handle the copy but if you know of a way of integrating it with a script that would be perfect :)

I want to fill the first disk with as much as can fit on it from the network share.  Once the first part is calculated it is easy for me to see what's left and just copy it over to the second disk. i.e. the script works out I can copy from Australia to Canada on my 5TB disk and then I can just copy everything after Canada to the second disk.

Hi Bill,
Thanks for this I'll take a look at the script and see if I can use it.

I don't care about optimisation at all, all I want is to get as much as will fit on the disk alphabetically from the share.

I always prefer a scripted solution if possible, I'm guess an installed app would be overkill for what I need?

Thanks for your replies guys!
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Bill PrewCommented:
Are the two drives both connected when you start, with different drive letters, or do you have to swap them when one is full, and they use the same drive letter?

Are you copying from the root of the large drive to the root of the backup drives, meaning the folders are in the root of the large drive, and getting copied to the same place on the USB drives?

~bp
0
robclarke41Author Commented:
Hi Bill,

Both drives will use the same drive letter I just swap them when one is full.

I am copying from the root of the large drive (mapped drive) i.e X: to a folder on the USB i.e F:\Countries

Thanks for your help so far!

Rob
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
In that case we would either have to stop as soon as the space is exhausted for the first time, or keep a list of files which did not make it to the first disk (or did make it).
The simple approach in PowerShell, just telling you the full name of first "offending" file:
$maxsize = 5000gb
$size = 0
Get-ChildItem X:\* -recursive | ? { !$_.PsIsContainer } | % {
  $size += $_.Length
  if ($size -gt 1gb) { write-host $_.FullName; break }
}

Open in new window

0
Bill PrewCommented:
Here's a small VBS that should do what you need.  Check it out and give it a test.

' Specify file to be copied, and folder copying to (need trailing backslash!)
strBaseDir = "X:\"
strDestDir  = "F:\Countries\"

' Establish esveral objects needed
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objBaseDir = objFSO.GetFolder(strBaseDir)
Set objDestDrive = objFSO.GetDrive(Left(strDestDir, 2))

' Process each subfolder, copy if space available
For Each objFolder in objBaseDir.SubFolders
   Wscript.Echo "Copying folder: " & objFolder.Path
   blnCopied = False
   Do Until blnCopied = True
      If objFolder.Size < objDestDrive.FreeSpace Then
         objFSO.CopyFolder objFolder.Path, strDestDir & objFolder.Name
         blnCopied = True
      Else
         Wscript.Echo "Insufficient space on destination drive, swap drives now, then press ENTER to continue:"
         WScript.StdIn.ReadLine
      End If
   Loop
Next

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robclarke41Author Commented:
Thanks guys will test both solutions, hopefully at lunchtime and get back to you. Thanks for all your help so far!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.