Created
August 1, 2009 21:01
-
-
Save jmcarbo/159809 to your computer and use it in GitHub Desktop.
Backup directory to DVD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
#Backup directory to DVD | |
require 'fileutils' | |
if !ARGV[1] | |
puts "Usage: backupdvd.rb <Directory to backup> <disk no>" | |
exit | |
end | |
@disk_count = ARGV[1].to_i | |
@current_size = 0 | |
def explore(path,destination_path=".") | |
#FileUtils.mkpath File.join(destination_path,"DISK#{@disk_count}",path) | |
#puts File.join(destination_path,"DISK#{@disk_count}",path) | |
Dir.entries(path).each do |e| | |
if e.match(/^\.\./) || e.match(/^\.$/) | |
next | |
end | |
size=`du -ks \"#{path}/#{e}\"` | |
size,dir_name= size.split(/\t/) | |
dir_name.gsub!(/\n/,"") | |
if(size.to_i>4000000) | |
if File.directory?(dir_name) | |
puts "#Should recurse" | |
explore(dir_name, File.join(destination_path,e)) | |
else | |
puts "#Should split file" | |
end | |
else | |
if((@current_size + size.to_i) >=4000000) | |
@current_size = 0 | |
puts "#Creating disk ............" | |
`cd DISK#{@disk_count};find . >contenido.txt;cp contenido.txt ../DISK#{@disk_count}.txt` | |
`mkisofs -J -R -o DISK#{@disk_count}.iso DISK#{@disk_count}` | |
`rm -rf DISK#{@disk_count}` | |
@disk_count = @disk_count + 1 | |
end | |
@current_size = @current_size + size.to_i | |
target = destination_path.sub /^\.\/*/,"" | |
target.sub!(/\/$/,"") | |
FileUtils.mkpath(File.join("DISK#{@disk_count}",target)) | |
FileUtils.cp_r( dir_name, File.join("DISK#{@disk_count}",target)) | |
#puts "#{size}\t#{dir_name}" | |
end | |
end | |
end | |
explore(ARGV[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment