Created
March 31, 2011 22:48
-
-
Save berislavbabic/897421 to your computer and use it in GitHub Desktop.
A backup script that backups the folder you wish into a 7z file, sort of versioning done stupid
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
# Author: babinho | |
# Name: SmartBackup | |
# Purpose: A friend needed a fast schedulable solution for directory backup | |
# and i made it worse :) The script is x-platform, haven't tryed on a mac because | |
# i am one short. Only prerequisite is 7zip archiver that is in system path | |
# Executing: ruby smart_backup.rb path(/home/username/dir_to_backup) | |
# it creates a dir_to_backup.7z file with current date in the name | |
@in_dir = ARGV[0] | |
separator = RUBY_PLATFORM.downcase.include?("mingw") ? "\\" : "/" | |
@filename = @in_dir[@in_dir.rindex(separator)+1..@in_dir.length] | |
@out_dir = @in_dir[0..@in_dir.rindex(separator)] | |
def backup | |
files = Dir.entries(@out_dir) | |
filename = "#{@filename}-#{Time.now.strftime('%Y-%m-%d')}" | |
fout = filename | |
i = 1 | |
until files.grep(/#{fout}/).empty? | |
fout = filename+"_#{i.to_s}" | |
i += 1 | |
end | |
if RUBY_PLATFORM.downcase.include?("mingw") | |
command = "7z.exe a -m0=lzma2 -mmt4" | |
else | |
command = "7za a -m0=lzma2 -mmt4" | |
end | |
system("#{command} #{@out_dir+fout}.7z #{@in_dir}") | |
puts "backup finished" | |
end | |
backup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment