Skip to content

Instantly share code, notes, and snippets.

Created September 16, 2013 20:46
Show Gist options
  • Save anonymous/6586372 to your computer and use it in GitHub Desktop.
Save anonymous/6586372 to your computer and use it in GitHub Desktop.
Script for taking a list of directories containing files to be archived to tape, determining which are equal to or more than 25GB, then creating a .PS1 file containing the directories for archiving.
require 'colored'
require 'win32console'
require 'find'
time = Time.new
date = time.strftime("%d-%m-%Y")
File.open 'Scripter Output.ps1', 'a' do |p|
p.puts "Import-Module BEMCLI"
end
root = 'S:/'
input = 'input.txt'
puts "Scan In Progress...".green
if root.encoding.to_s != 'UTF-8'
root.encode!('UTF-8')
File.readlines(input).each do |line|
c1, c2 = line.strip.split("-")
File.open 'Scripter Output.ps1', 'a' do |p|
#1234/ABC-1
p1 =("#{root}#{c1}")
paths = [p1]
Dir.glob(paths).each do |result|
puts "found #{result}"
dirsize =0
puts "Calculating #{result} dir size...".magenta
Find.find("#{result}") do |f| dirsize += File.stat(f).size end
if dirsize >= 26843545600 #25GB = 26843545600 bytes
puts "writing #{result} to PS1 file".bold.cyan
p.puts "\n"
p.print 'New-BEBackupDefinition -BackupJobDefault BackupToTape -FileSystemSelection '
p.print '"'
p.print "#{result}"
p.print '"'
p.print ' -Name '
p.print '"'
p.print "#{c1} Archive #{date}"
p.print '"'
p.print ' -AgentServer '
p.print '"mdcbkupdfu1c"'
p.print ' | Save-BEBackupDefinition'
p.puts "\n"
end
end
end
end
end
end
puts '***Search Complete***'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment