Created
September 9, 2010 09:14
-
-
Save tricknotes/571630 to your computer and use it in GitHub Desktop.
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
require "fileutils" | |
require "pathname" | |
require "date" | |
require "rubygems" | |
require "zipruby" | |
BACKUP_FOLDER = Pathname.new("/path/to/backup") | |
timestamp = DateTime.now.strftime("%Y%m%d%H%M%S") | |
folder = BACKUP_FOLDER + Date.today.strftime("%Y%m%d") | |
FileUtils.mkdir(folder) unless File.exist?(folder) | |
ARGV.each do |path| | |
Zip::Archive.open((folder + (File.basename(path) + "-" + timestamp)).to_s + ".zip", Zip::CREATE) do |zip| | |
target = Pathname.new(path) | |
case File::ftype(target) | |
when "file" | |
zip.add_file(target.to_s) | |
when "directory" | |
Dir[target + "**/**"].each do |file| | |
file_path = file.sub(File.dirname(target), "") | |
case File::ftype(file) | |
when "file" | |
zip.add_file(file_path, file) | |
when "directory" | |
zip.add_dir(file_path) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment