s3backup 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -10,3 +10,10 @@
10
10
  * mod bug if directory name has non english and shell special char
11
11
  * retry 5 times if data post fails.
12
12
 
13
+ === 0.6.6 2010-01-19
14
+ * add config max_retry_count
15
+ * if ocurred "Connection reset by peer",retry max_retry_count times. default 6 waiting (30*try_count) second next post.
16
+ * show http://scie.nti.st/2008/3/14/amazon-s3-and-connection-reset-by-peer
17
+ * don't use raise,change exit and error log
18
+ * config BUFESIZE to buffer_size
19
+ * mod bug if directory name has '\'
@@ -11,14 +11,14 @@ module S3backup
11
11
  @s3_obj = S3Wrapper.new(config,true)
12
12
  rescue => err
13
13
  S3log.error(err.backtrace.join("\n")+"\n"+err.message)
14
- exit -1
14
+ exit(-1)
15
15
  end
16
16
  @manager = Manager.new(@s3_obj,config)
17
17
  end
18
18
  def check_config(config)
19
19
  unless config["directories"]
20
20
  S3log.error("directories doesn't exist in config file.")
21
- exit -1
21
+ exit(-1)
22
22
  end
23
23
  unless config["directories"].class == Array
24
24
  dir = config["directories"]
@@ -28,11 +28,11 @@ module S3backup
28
28
  config["directories"].each do |dir|
29
29
  unless File.directory? dir
30
30
  S3log.error("#{dir} isn't exist.")
31
- exit -1
31
+ exit(-1)
32
32
  end
33
33
  if File.expand_path(dir) != dir
34
34
  S3log.error("#{dir.length} must be absolute path.")
35
- exit -1
35
+ exit(-1)
36
36
  end
37
37
  end
38
38
  end
@@ -44,7 +44,7 @@ module S3backup
44
44
  end
45
45
  rescue => err
46
46
  S3log.error(err.backtrace.join("\n")+"\n"+err.message)
47
- exit -1
47
+ exit(-1)
48
48
  end
49
49
  end
50
50
  end
data/lib/s3backup/cli.rb CHANGED
@@ -35,18 +35,18 @@ module S3backup
35
35
  }
36
36
  opt.on("-h","--help","print this message and quit") {
37
37
  puts opt.help
38
- exit 0
38
+ exit(0)
39
39
  }
40
40
  opt.parse!(arguments)
41
41
  end
42
42
  rescue OptionParser::ParseError => err
43
43
  S3log.error(err.message)
44
- exit 1
44
+ exit(-1)
45
45
  end
46
46
  S3log.set_debug(options[:verbose])
47
47
  if !File.file?(options[:config_file])
48
48
  S3log.error("config #{options[:config_file]} is not exist.")
49
- exit 1
49
+ exit(-1)
50
50
  end
51
51
  if options[:log]
52
52
  S3log.set_logfile(File.open(options[:log],"a"))
@@ -55,7 +55,7 @@ module S3backup
55
55
  require 's3backup/restore'
56
56
  if !File.directory?(options[:output_dir])
57
57
  S3log.error("output directory #{options[:output_dir]} is not exist.")
58
- exit 1
58
+ exit(-1)
59
59
  end
60
60
  rt = Restore.new(options[:output_dir],YAML.load_file(options[:config_file]))
61
61
  rt.start
@@ -6,9 +6,9 @@ require 's3backup/tree_info'
6
6
  require 's3backup/crypt'
7
7
  module S3backup
8
8
  class Manager
9
- DEFAULT_BUF_READ_SIZE=1024*1024*64
9
+ DEFAULT_BUF_READ_SIZE=1024*1024*32
10
10
  def shell_name(str)
11
- str.gsub!(/[!"$&'()*,:;<=>?\[\]^`{|}\s]/, '\\\\\&')
11
+ str.gsub!(/[!"$&'()*,:;<=>?\[\]\\^`{|}\s]/, '\\\\\&')
12
12
  a=[]
13
13
  str.each_byte{|i|
14
14
  if i < 0x80
@@ -26,15 +26,22 @@ module S3backup
26
26
  def set_config(config)
27
27
  if config["password"] and config["password"] != ""
28
28
  unless config["salt"]
29
- raise "salt doesn't exist in config file.\n"
29
+ S3log.error("salt doesn't exist in config file.\n")
30
+ exit(-1)
30
31
  end
31
32
  unless config["salt"] =~ /[0-9A-Fa-f]{16}/
32
- raise "salt format shoud be HexString and length should be 16.\n"
33
+ S3log.error("salt format shoud be HexString and length should be 16.\n")
34
+ exit(-1)
33
35
  end
34
- if config["BUF_SIEZE"]
35
- size=config["BUF_SIEZE"]
36
- if size > 1000*1000*1000*5
37
- raise "BUF_SIZE must be less than 5G"
36
+ if config["buffer_size"]
37
+ if config["buffer_size"].class == String
38
+ @buf_size = config["buffer_size"].to_i
39
+ else
40
+ @buf_size = config["buffer_size"]
41
+ end
42
+ if @buf_size > 1000*1000*1000*5
43
+ S3log.error("buffer_size must be less than 5G\n")
44
+ exit(-1)
38
45
  end
39
46
  else
40
47
  @buf_size = DEFAULT_BUF_READ_SIZE
@@ -57,7 +64,8 @@ module S3backup
57
64
  S3log.debug(cmd)
58
65
  system(cmd)
59
66
  unless $?.success?
60
- raise "feiled #{cmd} execute. #{$?.inspect}"
67
+ S3log.error("feiled #{cmd} execute. #{$?.inspect}")
68
+ exit(-1)
61
69
  end
62
70
  end
63
71
  def from_tgz(path,dir)
@@ -65,7 +73,8 @@ module S3backup
65
73
  S3log.debug(cmd)
66
74
  system(cmd)
67
75
  unless $?.success?
68
- raise "feiled #{cmd} execute. #{$?.inspect}"
76
+ S3log.error("feiled #{cmd} execute. #{$?.inspect}")
77
+ exit(-1)
69
78
  end
70
79
  end
71
80
  def get_chain(key)
@@ -11,7 +11,7 @@ module S3backup
11
11
  @s3_obj = S3Wrapper.new(config,false)
12
12
  rescue => err
13
13
  S3log.error(err.backtrace.join("\n")+"\n"+err.message)
14
- exit -1
14
+ exit(-1)
15
15
  end
16
16
  @manager = Manager.new(@s3_obj,config)
17
17
  end
@@ -33,7 +33,7 @@ module S3backup
33
33
  end
34
34
  rescue => err
35
35
  S3log.error(err.backtrace.join("\n")+"\n"+err.message)
36
- exit -1
36
+ exit(-1)
37
37
  end
38
38
  end
39
39
  end
@@ -3,7 +3,7 @@ require 'aws/s3'
3
3
  module S3backup
4
4
  class S3Wrapper
5
5
  attr_reader :bucket
6
- MAX_TRY_COUNT = 5
6
+ DEFAULT_MAX_RETRY_COUNT = 6
7
7
  def initialize(config,create_flg)
8
8
  @bucket= nil
9
9
  @s3objects =nil
@@ -35,7 +35,8 @@ module S3backup
35
35
  #Bucket作成
36
36
  ret = AWS::S3::Bucket.create(@bucket_name)
37
37
  unless ret
38
- raise "AWS::S3::Bucket create error"
38
+ S3log.error("AWS::S3::Bucket create error possibly already exist #{@bucket_name} by anyone else?)")
39
+ exit(-1)
39
40
  end
40
41
  end
41
42
  def rename(orig,dest)
@@ -57,18 +58,22 @@ module S3backup
57
58
  key_name = CGI.escape(key)
58
59
  S3log.info("S3Object.store(#{key_name})")
59
60
  count = 0;
60
- while count < MAX_TRY_COUNT do
61
+ while true do
61
62
  begin
62
63
  AWS::S3::S3Object.store(key_name,val,@bucket_name)
63
64
  break;
64
65
  rescue => ex
65
66
  count+=1;
67
+ S3log.debug("post #{count} times failed. #{key_name}\n")
68
+ if count >= @max_retry_count
69
+ raise ex
70
+ S3log.error("post #{count} times failed #{key_name} #{ex.class}:#{ex.message}\n")
71
+ exit(-1)
72
+ end
73
+ sleep(count*30)
66
74
  AWS::S3::Base.establish_connection!(@args)
67
75
  end
68
76
  end
69
- if count >= MAX_TRY_COUNT
70
- raise "post error occurd path #{key_name} \n"
71
- end
72
77
  end
73
78
  def set_config(config)
74
79
  err_msg = ""
@@ -83,6 +88,15 @@ module S3backup
83
88
  unless config["bucket"]
84
89
  err_msg += "bucket doesn't exist in config file.\n"
85
90
  end
91
+ if config["max_retry_count"]
92
+ if config["max_retry_count"].class == String
93
+ @max_retry_count = config["max_retry_count"].to_i
94
+ else
95
+ @max_retry_count = config["max_retry_count"]
96
+ end
97
+ else
98
+ @max_retry_count = DEFAULT_MAX_RETRY_COUNT
99
+ end
86
100
  @proxy = {}
87
101
  @proxy[:host] = config["proxy_host"] if config["proxy_host"]
88
102
  @proxy[:port] = config["proxy_port"] if config["proxy_port"]
@@ -90,7 +104,8 @@ module S3backup
90
104
  @proxy[:password] = config["proxy_password"] if config["proxy_password"]
91
105
  @bucket_name = config["bucket"]
92
106
  if err_msg != ""
93
- raise err_msg
107
+ S3log.error(err_msg)
108
+ exit(-1)
94
109
  end
95
110
  end
96
111
  def delete(key)
data/lib/s3backup.rb CHANGED
@@ -2,5 +2,5 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module S3backup
5
- VERSION = '0.6.5'
5
+ VERSION = '0.6.6'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeshi Morita
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-18 00:00:00 +09:00
12
+ date: 2010-01-19 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency