Created
July 1, 2010 20:07
-
-
Save abrader/460489 to your computer and use it in GitHub Desktop.
This file contains 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/env ruby | |
class ItmatArchive | |
def self.compress(dir, comp_file) | |
system("tar -czf #{comp_file} #{dir}") | |
system("split -b 20m -a 3 #{comp_file} #{dir}.") | |
system("rm -rf #{comp_file}") | |
end | |
def self.decompress_all(work_dir, split_file_prefix) | |
system("cat #{split_file_prefix}.a* >> #{work_dir}/#{split_file_prefix}.tar.gz") | |
system("rm -rf #{split_file_prefix}.a*") | |
curdir = Dir.getwd | |
Dir.chdir(work_dir) | |
restore_dir = "restore-" + Time.now.to_i.to_s | |
system("mkdir #{work_dir}/#{restore_dir}") | |
system("tar -C #{restore_dir} -zxf #{split_file_prefix}.tar.gz") | |
system("rm -rf #{split_file_prefix}.tar.gz") | |
Dir.chdir(curdir) | |
puts "All files successfully restored under #{work_dir}/#{restore_dir}/#{split_file_prefix}" | |
end | |
def self.decompress_file(work_dir, split_file_prefix, file_name) | |
system("cat #{split_file_prefix}.a* >> #{work_dir}/#{split_file_prefix}.tar.gz") | |
system("rm -rf #{split_file_prefix}.a*") | |
curdir = Dir.getwd | |
Dir.chdir(work_dir) | |
restore_dir = "restore-" + Time.now.to_i.to_s | |
system("mkdir #{work_dir}/#{restore_dir}") | |
system("tar --include #{file_name} -C #{restore_dir} -zxf #{split_file_prefix}.tar.gz") | |
system("rm -rf #{split_file_prefix}.tar.gz") | |
Dir.chdir(curdir) | |
puts "#{file_name} was successfully restored under #{work_dir}/#{restore_dir}/#{split_file_prefix}" | |
end | |
comp_dir = "Pictures" | |
ItmatArchive.compress(comp_dir, comp_dir + ".tar.gz") | |
#ItmatArchive.decompress_all("/tmp", comp_dir) | |
#ItmatArchive.decompress_file("/tmp", comp_dir, "*.JPG") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment