lib/s3backup/manager.rb in s3backup-0.6.5 vs lib/s3backup/manager.rb in s3backup-0.6.6
- old
+ new
@@ -4,13 +4,13 @@
require 's3backup/s3log'
require 's3backup/tree_info'
require 's3backup/crypt'
module S3backup
class Manager
- DEFAULT_BUF_READ_SIZE=1024*1024*64
+ DEFAULT_BUF_READ_SIZE=1024*1024*32
def shell_name(str)
- str.gsub!(/[!"$&'()*,:;<=>?\[\]^`{|}\s]/, '\\\\\&')
+ str.gsub!(/[!"$&'()*,:;<=>?\[\]\\^`{|}\s]/, '\\\\\&')
a=[]
str.each_byte{|i|
if i < 0x80
a.push(sprintf("%c",i))
else
@@ -24,20 +24,27 @@
set_config(config)
end
def set_config(config)
if config["password"] and config["password"] != ""
unless config["salt"]
- raise "salt doesn't exist in config file.\n"
+ S3log.error("salt doesn't exist in config file.\n")
+ exit(-1)
end
unless config["salt"] =~ /[0-9A-Fa-f]{16}/
- raise "salt format shoud be HexString and length should be 16.\n"
+ S3log.error("salt format shoud be HexString and length should be 16.\n")
+ exit(-1)
end
- if config["BUF_SIEZE"]
- size=config["BUF_SIEZE"]
- if size > 1000*1000*1000*5
- raise "BUF_SIZE must be less than 5G"
+ if config["buffer_size"]
+ if config["buffer_size"].class == String
+ @buf_size = config["buffer_size"].to_i
+ else
+ @buf_size = config["buffer_size"]
end
+ if @buf_size > 1000*1000*1000*5
+ S3log.error("buffer_size must be less than 5G\n")
+ exit(-1)
+ end
else
@buf_size = DEFAULT_BUF_READ_SIZE
end
@aes = Crypt.new(config["password"],config["salt"])
end
@@ -55,18 +62,20 @@
cmd = "(cd #{shell_name(File.dirname(dir))};tar -czvf #{shell_name(path)} #{exclude} #{shell_name(File.basename(dir))}" +
" > /dev/null 2>&1)"
S3log.debug(cmd)
system(cmd)
unless $?.success?
- raise "feiled #{cmd} execute. #{$?.inspect}"
+ S3log.error("feiled #{cmd} execute. #{$?.inspect}")
+ exit(-1)
end
end
def from_tgz(path,dir)
cmd = "tar -xzvf #{shell_name(path)} -C #{shell_name(dir)} > /dev/null 2>&1"
S3log.debug(cmd)
system(cmd)
unless $?.success?
- raise "feiled #{cmd} execute. #{$?.inspect}"
+ S3log.error("feiled #{cmd} execute. #{$?.inspect}")
+ exit(-1)
end
end
def get_chain(key)
data = nil
data_set = nil