yore 0.0.11 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +15 -12
- data/VERSION +1 -1
- data/bin/yore +11 -0
- data/lib/yore/AWSS3Client.rb +129 -0
- data/lib/yore/yore_core.rb +41 -22
- data/test/AWS_gem_test.rb +76 -0
- data/test/S3_test.rb +17 -19
- data/test/test_helper.rb +12 -1
- data/test/upload_test_content.yor +0 -0
- data/yore.gemspec +7 -3
- data/yore.vpw +1 -0
- metadata +6 -2
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= yore
|
2
2
|
|
3
|
-
*
|
3
|
+
* GitHub Project : http://github.com/buzzware/yore
|
4
4
|
* Author : http://www.buzzware.com.au
|
5
5
|
|
6
6
|
== DESCRIPTION:
|
@@ -28,16 +28,19 @@ can be manually configured.
|
|
28
28
|
|
29
29
|
Amazon S3
|
30
30
|
|
31
|
-
*
|
32
|
-
|
33
|
-
|
34
|
-
correctly before launching yore.
|
31
|
+
* You can and probably should create a seperate Amazon S3 account for backups. Unfortunately
|
32
|
+
you will need to supply your credit card details for this account, event though only your main
|
33
|
+
account will be charged.
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
Sadly you can't get a useable S3 account without giving them your credit card information,
|
36
|
+
even if you never plan to create your own buckets. Build a bridge, get over it and sign
|
37
|
+
up at http://aws.amazon.com/s3/. Then when you have logged in to the AWS website, go to
|
38
|
+
"Your Account" -> "Security Credentials"
|
39
|
+
to get an "Access Key ID" and click Show to get its "Secret Access Key"
|
40
|
+
|
41
|
+
* Create a bucket with backup permissions for an AWS account
|
42
|
+
|
43
|
+
yore new_backup_bucket --backup_email "blah@buzzware.com.au" testbucket
|
41
44
|
|
42
45
|
== SYNOPSIS:
|
43
46
|
|
@@ -48,8 +51,8 @@ eg.
|
|
48
51
|
|
49
52
|
== REQUIREMENTS:
|
50
53
|
|
51
|
-
*
|
52
|
-
*
|
54
|
+
* AWS S3 (http://github.com/marcel/aws-s3)
|
55
|
+
* buzzcore (http://github.com/buzzware/buzzcore)
|
53
56
|
* cmdparse (http://cmdparse.rubyforge.org)
|
54
57
|
* shairontoledo-popen4 (http://github.com/shairontoledo/popen4)
|
55
58
|
* tar, bzip2, openssl, mysql
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/bin/yore
CHANGED
@@ -69,6 +69,15 @@ encrypt_decrypt_option_parser = CmdParse::OptionParserWrapper.new do |opt|
|
|
69
69
|
#end
|
70
70
|
end
|
71
71
|
|
72
|
+
new_backup_bucket_option_parser = CmdParse::OptionParserWrapper.new do |opt|
|
73
|
+
opt.on( '--backup_id=S3 Access Key ID', String, 'S3 Access Key ID from Amazon' ) do |value|
|
74
|
+
CMD_OPTIONS[:backup_id] = value
|
75
|
+
end
|
76
|
+
opt.on( '--backup_email=AWS Account Email Address', String, 'AWS Account Email Address from Amazon' ) do |value|
|
77
|
+
CMD_OPTIONS[:backup_email] = value
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
72
81
|
command(cmd,yore,:backup,"Backup filelist to S3",option_parser)
|
73
82
|
|
74
83
|
command(cmd,yore,:save,"Save application data to local file",load_save_option_parser)
|
@@ -83,6 +92,8 @@ command(cmd,yore,:test_email,"Test email sending\n")
|
|
83
92
|
|
84
93
|
command(cmd,yore,:db_dump,"Dump database by name in job\n")
|
85
94
|
|
95
|
+
command(cmd,yore,:new_backup_bucket,"Create a new bucket with permissions for backup\n",new_backup_bucket_option_parser)
|
96
|
+
|
86
97
|
cmd.parse
|
87
98
|
|
88
99
|
yore.logger.info "\nComplete.\n"
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
gem 'buzzcore'; require 'buzzcore';
|
4
|
+
gem 'aws-s3'; require 'aws/s3'
|
5
|
+
|
6
|
+
# although this is implemented as an instantiable object, not a singleton,
|
7
|
+
# the AWS gem seems to operate as a singleton, so don't create more than one of these.
|
8
|
+
class AWSS3Client
|
9
|
+
|
10
|
+
attr_accessor :credentials
|
11
|
+
|
12
|
+
def initialize(aCredentials=nil)
|
13
|
+
@credentials = aCredentials || Credentials.new()
|
14
|
+
connect
|
15
|
+
end
|
16
|
+
|
17
|
+
def connect(aId=nil,aKey=nil)
|
18
|
+
aId ||= @credentials[:s3_access_key_id]
|
19
|
+
aKey ||= @credentials[:s3_secret_access_key]
|
20
|
+
AWS::S3::Base.establish_connection!(
|
21
|
+
:access_key_id => aId,
|
22
|
+
:secret_access_key => aKey
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def bucket(aName)
|
27
|
+
return AWS::S3::Bucket.find(aName)
|
28
|
+
end
|
29
|
+
|
30
|
+
def bucket_exists?(aName)
|
31
|
+
AWS::S3::Bucket.find(aName)
|
32
|
+
true
|
33
|
+
rescue
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
def ensure_clean_bucket(aName)
|
38
|
+
AWS::S3::Bucket.delete(aName, :force => true) if bucket_exists?(aName)
|
39
|
+
AWS::S3::Bucket.create(aName)
|
40
|
+
AWS::S3::Bucket.find(aName)
|
41
|
+
end
|
42
|
+
|
43
|
+
# ensures the destination bucket exists with the right permissions for upload_backup
|
44
|
+
# eg. @s3client.ensure_backup_bucket('a_bucket',{'email_address' => 'user@domain.com'})
|
45
|
+
def ensure_backup_bucket(aBucketName,aOtherUserAttrs=nil)
|
46
|
+
AWS::S3::Bucket.create(aBucketName) unless bucket_exists?(aBucketName)
|
47
|
+
grant_bucket_permissions(aBucketName,%w(WRITE READ_ACP),aOtherUserAttrs,true) if aOtherUserAttrs
|
48
|
+
end
|
49
|
+
|
50
|
+
def new_backup_bucket(aBucketName,aOtherUserAttrs)
|
51
|
+
AWS::S3::Bucket.create(aBucketName)
|
52
|
+
grant_bucket_permissions(aBucketName,%w(WRITE READ_ACP),aOtherUserAttrs,true)
|
53
|
+
end
|
54
|
+
|
55
|
+
# eg. policy = policy_add(policy,{'id' => 'dssdfsdf'},%w(READ WRITE))
|
56
|
+
def policy_add(aPolicy,aGranteeAttrs,aPermissions)
|
57
|
+
aPolicy ||= AWS::S3::ACL::Policy.new
|
58
|
+
grantee = AWS::S3::ACL::Grantee.new(aGranteeAttrs)
|
59
|
+
grantee.display_name ||= 'display_name'
|
60
|
+
aPermissions.each do |p|
|
61
|
+
grant = AWS::S3::ACL::Grant.new
|
62
|
+
grant.permission = p
|
63
|
+
grant.grantee = grantee
|
64
|
+
aPolicy.grants << grant
|
65
|
+
end
|
66
|
+
aPolicy
|
67
|
+
end
|
68
|
+
|
69
|
+
def grant_bucket_permissions(aBucketName,aPermissions,aGranteeAttrs,aMerge = false)
|
70
|
+
policy = (aMerge ? AWS::S3::Bucket.acl(aBucketName) : nil)
|
71
|
+
policy = policy_add(policy,aGranteeAttrs,aPermissions)
|
72
|
+
policy.owner ||= Owner.current
|
73
|
+
AWS::S3::Bucket.acl(aBucketName,policy)
|
74
|
+
policy
|
75
|
+
end
|
76
|
+
|
77
|
+
def grant_object_permissions(aBucketName,aObjectName,aPermissions,aGranteeAttrs,aMerge = false)
|
78
|
+
policy = (aMerge ? AWS::S3::S3Object.acl(aObjectName,aBucketName) : nil)
|
79
|
+
policy = policy_add(policy,aGranteeAttrs,aPermissions)
|
80
|
+
policy.owner ||= Owner.current
|
81
|
+
AWS::S3::S3Object.acl(aObjectName,aBucketName,policy) #S3Object.acl('kiss.jpg', 'marcel')
|
82
|
+
policy
|
83
|
+
end
|
84
|
+
|
85
|
+
def put_content(aFilename, aContent, aBucketName)
|
86
|
+
AWS::S3::S3Object.store(aFilename, aContent, aBucketName)
|
87
|
+
end
|
88
|
+
|
89
|
+
def upload(aFilename,aBucketName,aObjectName=nil)
|
90
|
+
aObjectName ||= File.basename(aFileName)
|
91
|
+
#AWS::S3::S3Object.store(aObjectName, MiscUtils.string_from_file(aFileName), aBucketName)
|
92
|
+
content = MiscUtils.string_from_file(aFileName)
|
93
|
+
|
94
|
+
put_content(aObjectName, content, aBucketName)
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_content(aFilename, aBucketName)
|
98
|
+
return AWS::S3::S3Object.value(aFilename, aBucketName)
|
99
|
+
end
|
100
|
+
|
101
|
+
def download(aFilename,aBucketName,aObjectName=nil)
|
102
|
+
aObjectName ||= File.basename(aFilename)
|
103
|
+
#AWS::S3::S3Object.store(aObjectName, MiscUtils.string_from_file(aFilename), aBucketName)
|
104
|
+
MiscUtils.string_to_file(get_content(aObjectName,aBucketName),aFilename)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Summary: Uploads the given file to the bucket, then gives up permissions to the bucket owner
|
108
|
+
# Details :
|
109
|
+
# * intended to allow files to be uploaded to S3, but not allowing the files to be interfered with should
|
110
|
+
# the web server get hacked.
|
111
|
+
# In truth, S3 permissions aren't adequate and the best we can do is that the file can't be read,
|
112
|
+
# but can be written over. The user also can't get a listing of the bucket
|
113
|
+
# * S3 won't allow objects (or buckets) to change owner, but we do everything else ie give FULL_CONTROL,
|
114
|
+
# and remove it from self, to hand control to the bucket owner
|
115
|
+
# * This requires the bucket to give WRITE & READ_ACP permissions to this user
|
116
|
+
def upload_backup(aFileName,aBucketName,aObjectName = nil)
|
117
|
+
aObjectName ||= File.basename(aFileName)
|
118
|
+
AWS::S3::S3Object.store(aObjectName, MiscUtils.string_from_file(aFileName), aBucketName)
|
119
|
+
bucket_owner = AWS::S3::Bucket.acl(aBucketName).owner
|
120
|
+
policy = AWS::S3::S3Object.acl(aObjectName,aBucketName)
|
121
|
+
policy.grants.clear
|
122
|
+
policy = policy_add(policy,{'id' => bucket_owner.id, 'display_name' => bucket_owner.display_name},'FULL_CONTROL')
|
123
|
+
|
124
|
+
# replace policy with full control to bucket owner, none to test_user
|
125
|
+
AWS::S3::S3Object.acl(aObjectName,aBucketName,policy)
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
data/lib/yore/yore_core.rb
CHANGED
@@ -4,6 +4,9 @@ gem 'buzzcore'; require 'buzzcore';
|
|
4
4
|
require 'fileutils'
|
5
5
|
require 'net/smtp'
|
6
6
|
|
7
|
+
require 'yore/AWSS3Client'
|
8
|
+
|
9
|
+
|
7
10
|
THIS_FILE = File.expand_path(__FILE__)
|
8
11
|
THIS_DIR = File.dirname(THIS_FILE)
|
9
12
|
|
@@ -70,8 +73,10 @@ module YoreCore
|
|
70
73
|
class Yore
|
71
74
|
|
72
75
|
DEFAULT_CONFIG = {
|
73
|
-
:kind =>
|
74
|
-
:basepath =>
|
76
|
+
:kind => String,
|
77
|
+
:basepath => String,
|
78
|
+
:backup_id => String,
|
79
|
+
:backup_email => String,
|
75
80
|
:keep_daily => 14,
|
76
81
|
:keep_weekly => 12,
|
77
82
|
:keep_monthly => 12,
|
@@ -80,26 +85,27 @@ module YoreCore
|
|
80
85
|
:first_hour => 4,
|
81
86
|
:prefix => 'backup',
|
82
87
|
:log_level => 'INFO',
|
83
|
-
:bucket =>
|
88
|
+
:bucket => String,
|
84
89
|
:email_report => false,
|
85
|
-
:mail_host =>
|
90
|
+
:mail_host => String,
|
86
91
|
:mail_port => 25,
|
87
|
-
:mail_helodomain =>
|
88
|
-
:mail_user =>
|
89
|
-
:mail_password =>
|
90
|
-
:mail_from =>
|
91
|
-
:mail_from_alias =>
|
92
|
-
:mail_to =>
|
93
|
-
:mail_to_alias =>
|
92
|
+
:mail_helodomain => String,
|
93
|
+
:mail_user => String,
|
94
|
+
:mail_password => String,
|
95
|
+
:mail_from => String,
|
96
|
+
:mail_from_alias => String,
|
97
|
+
:mail_to => String,
|
98
|
+
:mail_to_alias => String,
|
94
99
|
:mail_auth => :plain,
|
95
100
|
:mysqldump => 'mysqldump',
|
96
|
-
:RAILS_ENV =>
|
101
|
+
:RAILS_ENV => String
|
97
102
|
}
|
98
103
|
|
99
104
|
attr_reader :config
|
100
105
|
attr_reader :logger
|
101
106
|
attr_reader :reporter
|
102
107
|
attr_reader :keepers
|
108
|
+
attr_reader :s3client
|
103
109
|
|
104
110
|
def initialize(aConfig=nil)
|
105
111
|
DEFAULT_CONFIG[:email_report] = false # fixes some bug where this was nil
|
@@ -256,6 +262,8 @@ module YoreCore
|
|
256
262
|
@keepers << KeepDaily.new(config[:keep_daily])
|
257
263
|
@keepers << KeepWeekly.new(config[:keep_weekly])
|
258
264
|
@keepers << KeepMonthly.new(config[:keep_monthly])
|
265
|
+
|
266
|
+
@s3client = ::AWSS3Client.new()
|
259
267
|
end
|
260
268
|
|
261
269
|
def do_action(aAction,aArgs)
|
@@ -275,12 +283,6 @@ module YoreCore
|
|
275
283
|
return result[:stdout]
|
276
284
|
end
|
277
285
|
|
278
|
-
def s3shell(aCommandline)
|
279
|
-
shell(aCommandline) do |r|
|
280
|
-
r[:exitcode] = 1 if r[:stderr].length > 0
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
286
|
def get_log
|
285
287
|
logger.close
|
286
288
|
# read in log and return
|
@@ -364,22 +366,24 @@ module YoreCore
|
|
364
366
|
shell "openssl enc -d -aes-256-cbc -K #{config[:crypto_key]} -iv #{config[:crypto_iv]} -in #{aFileIn} -out #{aFileOut}"
|
365
367
|
end
|
366
368
|
|
367
|
-
def ensure_bucket(aBucket=nil)
|
369
|
+
def ensure_bucket(aBucket=nil,aUserEmail=nil)
|
368
370
|
aBucket ||= config[:bucket]
|
371
|
+
aUserEmail ||= config[:bucket_user_email]
|
369
372
|
logger.info "Ensuring S3 bucket #{aBucket} exists ..."
|
370
|
-
|
373
|
+
s3client.ensure_backup_bucket(aBucket,aUserEmail ? {'email_address' => aUserEmail} : nil)
|
371
374
|
end
|
372
375
|
|
373
376
|
# uploads the given file to the current bucket as its basename
|
374
377
|
def upload(aFile)
|
375
378
|
#ensure_bucket()
|
379
|
+
logger.debug "Uploading #{aFile} to S3 bucket #{config[:bucket]} ..."
|
376
380
|
logger.info "Uploading #{File.basename(aFile)} to S3 bucket #{config[:bucket]} ..."
|
377
|
-
|
381
|
+
s3client.upload_backup(aFile,config[:bucket],File.basename(aFile))
|
378
382
|
end
|
379
383
|
|
380
384
|
# downloads the given file from the current bucket as its basename
|
381
385
|
def download(aFile)
|
382
|
-
|
386
|
+
s3client.download(aFile,config[:bucket],File.basename(aFile))
|
383
387
|
end
|
384
388
|
|
385
389
|
# calculate the date (with no time component) based on :day_begins_hour and the local time
|
@@ -613,6 +617,21 @@ module YoreCore
|
|
613
617
|
uncompress(temp_file,folder)
|
614
618
|
end
|
615
619
|
|
620
|
+
def new_backup_bucket(aArgs)
|
621
|
+
bucket_name = aArgs[0]
|
622
|
+
if s3client.bucket_exists?(bucket_name)
|
623
|
+
puts "sorry, bucket already exists"
|
624
|
+
else
|
625
|
+
backup_user_attrs = {
|
626
|
+
'id' => config[:backup_id],
|
627
|
+
'display_name' => config[:backup_name] || 'backup_name',
|
628
|
+
'email_address' => config[:backup_email]
|
629
|
+
}
|
630
|
+
raise StandardError.new("Must provide backup_id or backup_email") unless backup_user_attrs['id'] || backup_user_attrs['email_address']
|
631
|
+
s3client.new_backup_bucket(bucket_name,backup_user_attrs)
|
632
|
+
end
|
633
|
+
end
|
634
|
+
|
616
635
|
def test_email(*aDb)
|
617
636
|
args = {
|
618
637
|
:host => config[:mail_host],
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.expand_path('test_helper',File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class AWSGemTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
puts "setup"
|
7
|
+
creds = Credentials.new()
|
8
|
+
assert(creds[:s3_access_key_id] && creds[:s3_secret_access_key] && creds[:s3_yore_test_bucket])
|
9
|
+
@s3client = AWSS3Client.new(creds)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "login" do
|
13
|
+
test_bucket = @s3client.ensure_clean_bucket(@s3client.credentials[:s3_yore_test_bucket])
|
14
|
+
puts test_bucket.inspect
|
15
|
+
assert !test_bucket.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
should "upload, download and compare" do
|
19
|
+
test_bucket = @s3client.ensure_clean_bucket(@s3client.credentials[:s3_yore_test_bucket])
|
20
|
+
test_filename = 'up_down_compare'
|
21
|
+
test_content = 'abc'
|
22
|
+
#AWS::S3::S3Object.store(test_filename, test_content, test_bucket.name)
|
23
|
+
@s3client.put_content(test_filename, test_content, test_bucket.name)
|
24
|
+
#after_content = AWS::S3::S3Object.value test_filename, test_bucket.name
|
25
|
+
after_content = @s3client.get_content(test_filename, test_bucket.name)
|
26
|
+
assert_equal test_content, after_content
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
should "create bucket writable (and not readable) by another user" do
|
31
|
+
test_user_bucket = @s3client.ensure_clean_bucket(@s3client.credentials[:s3_test_user_bucket])
|
32
|
+
@s3client.ensure_backup_bucket(@s3client.credentials[:s3_test_user_bucket],{'email_address' => @s3client.credentials[:s3_test_user_email]})
|
33
|
+
|
34
|
+
test_filename = 'up_down_compare'
|
35
|
+
test_content = 'xyz'
|
36
|
+
# reconnect as user
|
37
|
+
@s3client.connect(@s3client.credentials[:s3_test_access_id],@s3client.credentials[:s3_test_access_key])
|
38
|
+
temp_file = MiscUtils.make_temp_file(nil, nil, test_content)
|
39
|
+
@s3client.upload_backup(temp_file,@s3client.credentials[:s3_test_user_bucket],test_filename)
|
40
|
+
|
41
|
+
# should fail reading
|
42
|
+
begin
|
43
|
+
after_content = @s3client.get_content(test_filename, @s3client.credentials[:s3_test_user_bucket])
|
44
|
+
flunk
|
45
|
+
rescue AWS::S3::ResponseError => e
|
46
|
+
assert_equal e.class.to_s,"AWS::S3::AccessDenied"
|
47
|
+
end
|
48
|
+
|
49
|
+
# should fail overwriting
|
50
|
+
#new_content = '123'
|
51
|
+
#begin
|
52
|
+
# AWS::S3::S3Object.store(test_filename, new_content, @s3client.credentials[:s3_test_user_bucket])
|
53
|
+
# flunk "succeeded overwriting (should fail)"
|
54
|
+
#rescue AWS::S3::ResponseError => e
|
55
|
+
# assert_equal e.class.to_s,"AWS::S3::AccessDenied"
|
56
|
+
#end
|
57
|
+
|
58
|
+
# back to normal
|
59
|
+
@s3client.connect
|
60
|
+
|
61
|
+
test_user_bucket = @s3client.bucket(@s3client.credentials[:s3_test_user_bucket])
|
62
|
+
after_content = @s3client.get_content(test_filename, test_user_bucket.name)
|
63
|
+
assert_equal test_content, after_content
|
64
|
+
end
|
65
|
+
|
66
|
+
should "fail with wrong credentials" do
|
67
|
+
test_user_bucket = @s3client.ensure_clean_bucket(@s3client.credentials[:s3_test_user_bucket])
|
68
|
+
begin
|
69
|
+
permission = @s3client.grant_bucket_permissions(test_user_bucket,%w(WRITE READ_ACP),{'email_address' => 'asddsad@sdsddsadsa.com'},true)
|
70
|
+
flunk
|
71
|
+
rescue AWS::S3::ResponseError => e
|
72
|
+
assert_equal e.class.to_s,"AWS::S3::NoSuchBucket"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/test/S3_test.rb
CHANGED
@@ -1,16 +1,11 @@
|
|
1
|
-
require '
|
2
|
-
gem 'buzzcore'; require 'buzzcore';
|
3
|
-
require 'yore/yore_core'
|
4
|
-
require 'test/unit'
|
5
|
-
gem 'Shoulda'; require 'shoulda'
|
6
|
-
require 'fileutils'
|
1
|
+
require File.expand_path('test_helper',File.dirname(__FILE__))
|
7
2
|
|
8
3
|
def ensure_clean_bucket(aName)
|
9
4
|
`s3cmd createbucket #{aName}`
|
10
5
|
`s3cmd deleteall #{aName}`
|
11
6
|
end
|
12
7
|
|
13
|
-
#
|
8
|
+
# example : yore backup /var/www/joomla/deploy-system/yore.xml >/dev/null 2>&1
|
14
9
|
|
15
10
|
class S3Test < Test::Unit::TestCase
|
16
11
|
|
@@ -24,15 +19,17 @@ class S3Test < Test::Unit::TestCase
|
|
24
19
|
@yore.configure({
|
25
20
|
:bucket => bucket
|
26
21
|
})
|
27
|
-
content = 'this is my test content'
|
22
|
+
#content = 'this is my test content'
|
23
|
+
orig_file = File.expand_path('upload_test_content.yor',File.dirname(__FILE__)) # MiscUtils.make_temp_file(nil, temp_dir, content)
|
24
|
+
puts @yore.upload(orig_file)
|
25
|
+
#orig_file = temp_file+'.orig'
|
26
|
+
#File.rename(temp_file, orig_file)
|
28
27
|
temp_dir = MiscUtils.make_temp_dir()
|
29
|
-
temp_file =
|
30
|
-
puts @yore.upload(temp_file)
|
31
|
-
orig_file = temp_file+'.orig'
|
32
|
-
File.rename(temp_file, orig_file)
|
28
|
+
temp_file = File.join(temp_dir,File.basename(orig_file))
|
33
29
|
puts @yore.download(temp_file)
|
34
|
-
down_file_content = MiscUtils.string_from_file(temp_file)
|
35
|
-
assert_equal content, down_file_content
|
30
|
+
#down_file_content = MiscUtils.string_from_file(temp_file)
|
31
|
+
#assert_equal content, down_file_content
|
32
|
+
assert_equal nil, POpen4::shell_out("/usr/bin/diff #{orig_file} #{temp_file}")[:stdout]
|
36
33
|
end
|
37
34
|
|
38
35
|
should "backup and restore multiple directories of file" do
|
@@ -56,7 +53,6 @@ class S3Test < Test::Unit::TestCase
|
|
56
53
|
MiscUtils::make_temp_file(f,source2)
|
57
54
|
end
|
58
55
|
|
59
|
-
|
60
56
|
ensure_clean_bucket(bucket)
|
61
57
|
|
62
58
|
# create job file
|
@@ -67,7 +63,7 @@ class S3Test < Test::Unit::TestCase
|
|
67
63
|
<Item Name="crypto_iv">3A63775C1E3F291B0925578165EB917E</Item>
|
68
64
|
<Item Name="crypto_key">07692FC8656F04AE5518B80D38681E038A3C12050DF6CC97CEEC33D800D5E2FE</Item>
|
69
65
|
<Item Name="prefix">backup</Item>
|
70
|
-
<Item Name="log_level">
|
66
|
+
<Item Name="log_level">DEBUG</Item>
|
71
67
|
<Item Name="bucket">${BUCKET}</Item>
|
72
68
|
</SimpleItems>
|
73
69
|
<Sources>
|
@@ -85,11 +81,10 @@ class S3Test < Test::Unit::TestCase
|
|
85
81
|
})
|
86
82
|
MiscUtils::string_to_file(job_content,job_file = MiscUtils::temp_file)
|
87
83
|
|
88
|
-
# call yore script with ruby from the command line, then download result and check contents
|
89
84
|
begin
|
90
85
|
_xmlRoot = XmlUtils.get_xml_root(job_content)
|
91
86
|
cmd_options = {:config => job_file}
|
92
|
-
@yore_upload = YoreCore::Yore::launch(_xmlRoot,cmd_options,{:basepath => File.dirname(File.expand_path(job_file))})
|
87
|
+
@yore_upload = YoreCore::Yore::launch(_xmlRoot,cmd_options,{:basepath => File.dirname(File.expand_path(job_file)), :log_level => 'DEBUG'})
|
93
88
|
@yore_upload.backup([job_file])
|
94
89
|
rescue ::StandardError => e
|
95
90
|
flunk e.inspect
|
@@ -98,7 +93,10 @@ class S3Test < Test::Unit::TestCase
|
|
98
93
|
#puts result
|
99
94
|
yore = YoreCore::Yore.new()
|
100
95
|
yore.configure({
|
101
|
-
:
|
96
|
+
:crypto_iv => "3A63775C1E3F291B0925578165EB917E",
|
97
|
+
:crypto_key =>"07692FC8656F04AE5518B80D38681E038A3C12050DF6CC97CEEC33D800D5E2FE",
|
98
|
+
:bucket => bucket,
|
99
|
+
:log_level => 'DEBUG'
|
102
100
|
})
|
103
101
|
|
104
102
|
retrieved_fname = File.expand_path(yore.encode_file_name(), dest_dir)
|
data/test/test_helper.rb
CHANGED
@@ -4,7 +4,18 @@ require 'shoulda'
|
|
4
4
|
|
5
5
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
6
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
-
require 'yore'
|
8
7
|
|
9
8
|
class Test::Unit::TestCase
|
10
9
|
end
|
10
|
+
|
11
|
+
require File.expand_path('../../buzzcore/lib/buzzcore_dev.rb',File.dirname(__FILE__))
|
12
|
+
|
13
|
+
require_paths_first '../lib' # prefer local yore over installed gem
|
14
|
+
|
15
|
+
|
16
|
+
require 'yore/AWSS3Client'
|
17
|
+
require 'yore/yore_core'
|
18
|
+
require 'fileutils'
|
19
|
+
|
20
|
+
|
21
|
+
|
Binary file
|
data/yore.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{yore}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["buzzware"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-12-08}
|
13
13
|
s.default_executable = %q{yore}
|
14
14
|
s.description = %q{yore (as in "days of yore") is a user data management utility for web applications.}
|
15
15
|
s.email = %q{contact@buzzware.com.au}
|
@@ -26,13 +26,16 @@ Gem::Specification.new do |s|
|
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
28
|
"bin/yore",
|
29
|
+
"lib/yore/AWSS3Client.rb",
|
29
30
|
"lib/yore/yore_core.rb",
|
30
31
|
"notes.txt",
|
31
32
|
"test.crontab",
|
33
|
+
"test/AWS_gem_test.rb",
|
32
34
|
"test/S3_test.rb",
|
33
35
|
"test/test_helper.rb",
|
34
36
|
"test/test_job_a.xml",
|
35
37
|
"test/test_job_b.xml",
|
38
|
+
"test/upload_test_content.yor",
|
36
39
|
"test/yore_browsercms_loadsave_test.rb",
|
37
40
|
"test/yore_spree_loadsave_test.rb",
|
38
41
|
"test/yore_test.rb",
|
@@ -47,7 +50,8 @@ Gem::Specification.new do |s|
|
|
47
50
|
s.rubygems_version = %q{1.3.5}
|
48
51
|
s.summary = %q{yore (as in "days of yore") is a user data management utility for web applications.}
|
49
52
|
s.test_files = [
|
50
|
-
"test/
|
53
|
+
"test/AWS_gem_test.rb",
|
54
|
+
"test/S3_test.rb",
|
51
55
|
"test/test_helper.rb",
|
52
56
|
"test/yore_browsercms_loadsave_test.rb",
|
53
57
|
"test/yore_spree_loadsave_test.rb",
|
data/yore.vpw
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- buzzware
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-08 00:00:00 +08:00
|
13
13
|
default_executable: yore
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -49,13 +49,16 @@ files:
|
|
49
49
|
- Rakefile
|
50
50
|
- VERSION
|
51
51
|
- bin/yore
|
52
|
+
- lib/yore/AWSS3Client.rb
|
52
53
|
- lib/yore/yore_core.rb
|
53
54
|
- notes.txt
|
54
55
|
- test.crontab
|
56
|
+
- test/AWS_gem_test.rb
|
55
57
|
- test/S3_test.rb
|
56
58
|
- test/test_helper.rb
|
57
59
|
- test/test_job_a.xml
|
58
60
|
- test/test_job_b.xml
|
61
|
+
- test/upload_test_content.yor
|
59
62
|
- test/yore_browsercms_loadsave_test.rb
|
60
63
|
- test/yore_spree_loadsave_test.rb
|
61
64
|
- test/yore_test.rb
|
@@ -91,6 +94,7 @@ signing_key:
|
|
91
94
|
specification_version: 3
|
92
95
|
summary: yore (as in "days of yore") is a user data management utility for web applications.
|
93
96
|
test_files:
|
97
|
+
- test/AWS_gem_test.rb
|
94
98
|
- test/S3_test.rb
|
95
99
|
- test/test_helper.rb
|
96
100
|
- test/yore_browsercms_loadsave_test.rb
|