sqlup 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. data/History.txt +5 -0
  2. data/Manifest.txt +38 -0
  3. data/README.txt +122 -0
  4. data/Rakefile +18 -0
  5. data/bin/sqlup +107 -0
  6. data/bin/sqlup_control +25 -0
  7. data/config/environment.rb +0 -0
  8. data/lib/mysql_backup/entity/files/innodb.rb +77 -0
  9. data/lib/mysql_backup/entity/files/myisam.rb +62 -0
  10. data/lib/mysql_backup/entity/files.rb +95 -0
  11. data/lib/mysql_backup/entity/identifier.rb +179 -0
  12. data/lib/mysql_backup/entity/logs.rb +44 -0
  13. data/lib/mysql_backup/entity/mysqldump.rb +57 -0
  14. data/lib/mysql_backup/entity.rb +38 -0
  15. data/lib/mysql_backup/librarian/backup.rb +134 -0
  16. data/lib/mysql_backup/librarian/backup_collection.rb +63 -0
  17. data/lib/mysql_backup/librarian.rb +176 -0
  18. data/lib/mysql_backup/server.rb +237 -0
  19. data/lib/mysql_backup/storage/s3.rb +110 -0
  20. data/lib/mysql_backup/storage.rb +13 -0
  21. data/lib/mysql_backup/utilities/factory_create_method.rb +51 -0
  22. data/lib/mysql_backup.rb +8 -0
  23. data/lib/sqlup.rb +2 -0
  24. data/test/unit/mysql_backup/entity/files/files_test.rb +45 -0
  25. data/test/unit/mysql_backup/entity/files/innodb_test.rb +50 -0
  26. data/test/unit/mysql_backup/entity/files/myisam_test.rb +42 -0
  27. data/test/unit/mysql_backup/entity/identifier_test.rb +51 -0
  28. data/test/unit/mysql_backup/entity/logs_test.rb +13 -0
  29. data/test/unit/mysql_backup/entity/mysqldump_test.rb +64 -0
  30. data/test/unit/mysql_backup/librarian/backup_collection_test.rb +52 -0
  31. data/test/unit/mysql_backup/librarian/backup_test.rb +25 -0
  32. data/test/unit/mysql_backup/librarian/librarian_test.rb +103 -0
  33. data/test/unit/mysql_backup/server_test.rb +63 -0
  34. data/test/unit/mysql_backup/storage/s3_test.rb +69 -0
  35. data/test/unit/mysql_backup/storage/test_helper.rb +1 -0
  36. data/test/unit/mysql_backup/test_helper.rb +1 -0
  37. data/test/unit/mysql_backup/utilities/test_helper.rb +1 -0
  38. data/test/unit/test_helper.rb +10 -0
  39. metadata +116 -0
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+ require 'mysql_backup/librarian/backup_collection'
3
+
4
+ module MysqlBackup
5
+ class Librarian::BackupCollectionTest < Test::Unit::TestCase
6
+ def test_add_backup_group
7
+ i = Entity::Identifier.create_object :category => :full, :type => :binary
8
+ c = Librarian::BackupCollection.new
9
+ g = Librarian::Backup.create_object :identifier => i
10
+ c.add_backup_group g
11
+ assert_equal [g], c.groups
12
+ end
13
+
14
+ def test_add_identifier
15
+ i = Entity::Identifier.create_object :category => :full, :type => :binary
16
+ c = Librarian::BackupCollection.new
17
+ g = Librarian::Backup.create_object :identifier => i
18
+ c.add_identifier i
19
+ assert_equal 1, c.groups.length
20
+ assert_kind_of MysqlBackup::Entity::Identifier::Full, c.groups.first.identifiers.first
21
+ end
22
+
23
+ def test_find_group
24
+ c = standard_collection
25
+ backup_name = 'log:type_current:log_file_thelog.0000000006:log_position_0000000311'
26
+ g = c.find_group backup_name
27
+ assert_kind_of Librarian::Backup, g
28
+ assert_equal g.to_s, backup_name
29
+ end
30
+
31
+ def test_groupsf
32
+ strings = %w(log:type_complete:log_file_thelog.0000000006:log_position_0000000311)
33
+ c = Librarian::BackupCollection.new
34
+ strings.map do |str|
35
+ i = MysqlBackup::Entity::Identifier.create_object :string => str
36
+ c.add_identifier i
37
+ end
38
+ end
39
+
40
+ def standard_collection
41
+ strings = %w(log:type_current:log_file_thelog.0000000006:log_position_0000000311:n_parts_0000000001:part_number_0000000000
42
+ full:type_mysqldump:log_file_thelog.0000000006:log_position_0000000382:n_parts_0000000001:part_number_0000000000
43
+ full:type_binary:log_file_thelog.0000000006:log_position_0000000911:n_parts_0000000001:part_number_0000000000)
44
+ c = Librarian::BackupCollection.new
45
+ strings.map do |str|
46
+ i = MysqlBackup::Entity::Identifier.create_object :string => str
47
+ c.add_identifier i
48
+ end
49
+ c
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require 'mysql_backup/librarian/backup'
3
+
4
+ module MysqlBackup
5
+ class Librarian::BackupTest < Test::Unit::TestCase
6
+ def test_identifiers
7
+ end
8
+
9
+ def test_most_recent_eh
10
+ end
11
+
12
+ def test_write_files
13
+ end
14
+
15
+ def test_write_raw_files
16
+ end
17
+
18
+ def test_object_creation
19
+ i = Entity::Identifier.create_object :category => :full, :type => :binary
20
+ b = Librarian::Backup.create_object :identifier => i
21
+ assert_kind_of Librarian::Backup::Full::Binary, b
22
+ assert b.is_part_of_this_group?(i)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,103 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+ require 'mysql_backup/entity/mysqldump'
3
+ require 'mysql_backup/librarian'
4
+
5
+ class MysqlBackup::LibrarianTest < Test::Unit::TestCase
6
+ def test_backup_data_files
7
+ s3mock = mock('fakestorage')
8
+ s3mock.expects(:conditional_save).at_least_once.with do |args|
9
+ i = args[:identifier]
10
+ i.log_file == 'foo.0001' && i.log_position == 10 && i.n_parts == 1 && i.part_number == 1
11
+ end
12
+ m = stubbed_librarian
13
+ m.storage = s3mock
14
+ MysqlBackup::Entity::Files.expects(:tar_files).at_least_once.returns([Pathname.new('/tmp/foo.0001')])
15
+ m.backup_data_files
16
+ end
17
+
18
+ def test_backup_mysqldump
19
+ s3mock = mock
20
+ s3mock.expects(:conditional_save).with do |i|
21
+ i = i[:identifier]
22
+ assert_equal :full, i.category
23
+ assert_equal :mysqldump, i.type
24
+ assert_match(/full/, i.to_s)
25
+ i.log_file == 'foo.0001' && i.log_position == 10 && i.n_parts == 1 && i.part_number == 0
26
+ end
27
+ m = stubbed_librarian
28
+ m.expects(:storage).returns(s3mock)
29
+ dump = MysqlBackup::Entity::Mysqldump.new
30
+ dump.log_position = 10
31
+ dump.log_file = 'foo.0001'
32
+ dump.expects(:system).returns(true)
33
+ dump.expects(:get_log_position).returns(true)
34
+ dump.expects(:compress_and_split).returns([Pathname.new('/tmp/a01')])
35
+ MysqlBackup::Entity::Mysqldump.expects(:new).returns(dump)
36
+ m.backup_mysqldump
37
+ end
38
+
39
+ def test_backup_binary_logs
40
+ s3mock = mock
41
+ s3mock.expects(:conditional_save).with do |args|
42
+ i = args[:identifier]
43
+ result = i.log_file == 'foo.0001' && i.log_position == 10 && i.n_parts == 1 && i.part_number == 0
44
+ result &&= i.type == :current || i.type == :complete
45
+ end
46
+ m = stubbed_librarian
47
+ m.expects(:storage).returns(s3mock)
48
+ m.backup_binary_logs
49
+ end
50
+
51
+ def test_create_backup_group_collection_from_storage
52
+ librarian = stubbed_librarian_with_files
53
+ c = librarian.create_backup_group_collection_from_storage
54
+ end
55
+
56
+ def test_ls
57
+ l = stubbed_librarian_with_files
58
+ results = l.ls
59
+ assert l.ls.grep(%r(log:type_current:log_file_thelog.0000000006:log_position_0000000311))
60
+ assert l.ls.grep(%r(full:type_mysqldump:log_file_thelog.0000000006:log_position_0000000382))
61
+ assert l.ls.grep(%r(full:type_binary:log_file_thelog.0000000006:log_position_0000000911))
62
+ end
63
+
64
+ def test_get
65
+ l = stubbed_librarian
66
+ stubbed_file = stub("a_temp_file", :path => 'a_temp_file')
67
+ l.storage.expects(:retrieve_backup_and_then_yield_file).yields stubbed_file
68
+ l.expects(:find_group).returns 0
69
+ l.expects(:system).with {|v| v =~ /zcat.*a_temp_file/}
70
+ Tempfile.open 'testing' do |f|
71
+ p = Pathname.new f.to_s
72
+ l.get_full_binary 'full:type_binary:log_file_thelog.0000000006:log_position_0000000911', p.dirname
73
+ end
74
+ end
75
+
76
+ def stubbed_librarian
77
+ connection_stub = stub_everything('connection stub')
78
+ m = MysqlBackup::Librarian.new :bucket => 'foo', :access_key_id => 'key', :secret_access_key => 'secret_key' do |o|
79
+ o.stubs(:create_connection).returns(connection_stub)
80
+ end
81
+ m.mysql_server.stubs(:show_master_status).returns(:file => 'foo.0001', :position => 10)
82
+ m.mysql_server.stubs(:datadir).returns('/tmp')
83
+ m.mysql_server.stubs(:innodb_data_home_dir).returns('/tmp')
84
+ m.mysql_server.stubs(:innodb_data_file_path).returns('/tmp')
85
+ m
86
+ end
87
+
88
+ def stubbed_librarian_with_files
89
+ strings = %w(log:type_current:log_file_thelog.0000000006:log_position_0000000311:n_parts_0000000001:part_number_0000000000
90
+ full:type_mysqldump:log_file_thelog.0000000006:log_position_0000000382:n_parts_0000000001:part_number_0000000000
91
+ full:type_binary:log_file_thelog.0000000006:log_position_0000000911:n_parts_0000000001:part_number_0000000000)
92
+ identifiers = strings.map do |str|
93
+ MysqlBackup::Entity::Identifier.create_object :string => str
94
+ end
95
+ librarian = stubbed_librarian
96
+ storage = mock('storage')
97
+ storage.expects(:yield_identifiers).multiple_yields(*identifiers)
98
+ librarian.storage = storage
99
+ librarian
100
+ end
101
+ end
102
+
103
+ # Number of errors detected: 34
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require 'mysql_backup/server'
3
+
4
+ class MysqlBackup::ServerTest < Test::Unit::TestCase
5
+ def test_connection
6
+ end
7
+
8
+ def test_current_log_has_entries_eh
9
+ r = [{"Position"=>"98",
10
+ "Binlog_Do_DB"=>"",
11
+ "Binlog_Ignore_DB"=>"",
12
+ "File"=>"James-PC-bin.000002"}]
13
+ @repl.expects(:query_to_array).returns r
14
+
15
+ assert ! @repl.current_log_has_entries?
16
+
17
+ r = [{"Position"=>"98",
18
+ "Binlog_Do_DB"=>"",
19
+ "Binlog_Ignore_DB"=>"",
20
+ "File"=>"James-PC-bin.000002"}]
21
+ @repl.expects(:query_to_array).returns r
22
+
23
+ assert ! @repl.current_log_has_entries?
24
+ end
25
+
26
+ def test_completed_logs
27
+ @repl.expects(:query_to_list).returns(["James-PC-bin.000001", "James-PC-bin.000002"])
28
+ assert_equal ["James-PC-bin.000001"], @repl.completed_logs
29
+ end
30
+
31
+ def test_flush_logs_bang
32
+ @repl.expects(:query_to_array).with('flush logs')
33
+ @repl.flush_logs!
34
+ end
35
+
36
+ def test_query_to_array
37
+ end
38
+
39
+ def test_show_master_status
40
+ r = [{"Position"=>"98",
41
+ "Binlog_Do_DB"=>"",
42
+ "Binlog_Ignore_DB"=>"",
43
+ "File"=>"James-PC-bin.000002"}]
44
+ @repl.expects(:query_to_array).returns r
45
+ s = @repl.show_master_status
46
+
47
+ expected = {:position=>98,
48
+ :binlog_do_db=>"",
49
+ :file=>"James-PC-bin.000002",
50
+ :binlog_ignore_db=>""}
51
+ assert_equal expected, s
52
+ end
53
+
54
+ def test_innodb_data_file_path
55
+ x = 'ibdatad1:10M:autoextend'
56
+ @repl.expects(:show_variables).returns({:innodb_data_file_path => x})
57
+ assert_equal 'ibdatad', @repl.innodb_data_file_path
58
+ end
59
+
60
+ def setup
61
+ @repl = MysqlBackup::Server.new :host => 'localhost', :user => 'root'
62
+ end
63
+ end
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require 'mysql_backup/storage/s3'
3
+ require 'ostruct'
4
+
5
+ class MysqlBackup::Storage::S3Test < Test::Unit::TestCase
6
+ def test_save
7
+ Pathname.any_instance.stubs(:readable?).returns(true)
8
+ s = MysqlBackup::Storage::S3.new :bucket => 'banshee', :access_key_id => 'asdf', :secret_access_key => '332'
9
+ AWS::S3::S3Object.expects(:store).with do |name, file, bucket|
10
+ name == 'full:type_binary:log_file_log.0001:log_position_0000000012:n_parts_0000000002:part_number_0000000001'
11
+ end
12
+ p = Pathname.new '/tmp/log.0001'
13
+ p.expects(:open)
14
+ i = MysqlBackup::Entity::Identifier.create_object :category => :full, :log_file => 'tst', :log_file => 'log.0001', :log_position => 12, :type => :binary, :part_number => 1, :n_parts => 2
15
+ s.save :identifier => i, :file => p
16
+ end
17
+
18
+ def test_conditional_save
19
+ s = MysqlBackup::Storage::S3.new :bucket => 'banshee', :access_key_id => 'asdf', :secret_access_key => '332'
20
+ s.expects(:include?).returns(false)
21
+ args = {:identifier => nil, :file => nil}
22
+ s.expects(:save).with(args)
23
+ s.conditional_save args
24
+ end
25
+
26
+ def test_include_eh?
27
+ s = standard_s3
28
+ s.include? 'foo'
29
+ end
30
+
31
+ def test_s3_object_to_identifier
32
+ o = OpenStruct.new :key => 'full:type_binary:log_file_log.0001:log_position_12:n_parts_2:part_number_1', :last_modified => Time.now
33
+ s = MysqlBackup::Storage::S3.new :no_connect => true
34
+ i = s.s3_object_to_identifier o
35
+ end
36
+
37
+ def test_mark_as_existing
38
+ s = standard_s3
39
+ s.mark_as_existing 'foo'
40
+ end
41
+
42
+ def test_read_existing_objects
43
+ end
44
+
45
+ def test_yield_objets
46
+ s = standard_s3
47
+ expects(:must_call).with('a')
48
+ expects(:must_call).with('b')
49
+ s.bucket_obj = stubbed_bucket
50
+ s.yield_objects(1) do |o|
51
+ must_call o.key
52
+ end
53
+ end
54
+
55
+ def test_bucket_obj
56
+ end
57
+
58
+ def standard_s3
59
+ MysqlBackup::Storage::S3.new :access_key_id => 2, :secret_access_key => 'x'
60
+ end
61
+
62
+ def stubbed_bucket
63
+ fake_obj_a = stub(:key => 'a')
64
+ fake_obj_b = stub(:key => 'b')
65
+ b = stub("stubbed bucket")
66
+ b.stubs(:objects).times(0..100).returns([fake_obj_a], [fake_obj_b], [])
67
+ b
68
+ end
69
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit' unless defined? $ZENTEST and $ZENTEST
3
+ require 'mocha'
4
+ require 'pp'
5
+ require 'pathname'
6
+
7
+ $LIB_DIR = (Pathname.new(__FILE__).dirname + "../../lib").cleanpath.to_s
8
+ $:.unshift $LIB_DIR
9
+ require $LIB_DIR + "/sqlup"
10
+ require 'mysql_backup/entity/identifier'
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: sqlup
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-06-22 00:00:00 -07:00
8
+ summary: A backup tool for saving MySQL data to Amazon's S3 service
9
+ require_paths:
10
+ - lib
11
+ email: banshee@restphone.com
12
+ homepage: http://www.zenspider.com/ZSS/Products/sqlup/
13
+ rubyforge_project: sqlup
14
+ description: The author was too lazy to write a description
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - James Moore
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - bin/sqlup
37
+ - bin/sqlup_control
38
+ - test/unit/mysql_backup/librarian/librarian_test.rb
39
+ - test/unit/mysql_backup/librarian/backup_test.rb
40
+ - test/unit/mysql_backup/librarian/backup_collection_test.rb
41
+ - test/unit/mysql_backup/utilities/test_helper.rb
42
+ - test/unit/mysql_backup/storage/test_helper.rb
43
+ - test/unit/mysql_backup/storage/s3_test.rb
44
+ - test/unit/mysql_backup/entity/files/myisam_test.rb
45
+ - test/unit/mysql_backup/entity/files/files_test.rb
46
+ - test/unit/mysql_backup/entity/files/innodb_test.rb
47
+ - test/unit/mysql_backup/entity/logs_test.rb
48
+ - test/unit/mysql_backup/entity/mysqldump_test.rb
49
+ - test/unit/mysql_backup/entity/identifier_test.rb
50
+ - test/unit/mysql_backup/test_helper.rb
51
+ - test/unit/mysql_backup/server_test.rb
52
+ - test/unit/test_helper.rb
53
+ - lib/mysql_backup/librarian/backup.rb
54
+ - lib/mysql_backup/librarian/backup_collection.rb
55
+ - lib/mysql_backup/entity/files/myisam.rb
56
+ - lib/mysql_backup/entity/files/innodb.rb
57
+ - lib/mysql_backup/entity/identifier.rb
58
+ - lib/mysql_backup/entity/logs.rb
59
+ - lib/mysql_backup/entity/mysqldump.rb
60
+ - lib/mysql_backup/entity/files.rb
61
+ - lib/mysql_backup/storage/s3.rb
62
+ - lib/mysql_backup/utilities/factory_create_method.rb
63
+ - lib/mysql_backup/server.rb
64
+ - lib/mysql_backup/librarian.rb
65
+ - lib/mysql_backup/storage.rb
66
+ - lib/mysql_backup/entity.rb
67
+ - lib/mysql_backup.rb
68
+ - lib/sqlup.rb
69
+ - config/environment.rb
70
+ test_files:
71
+ - test/unit/test_helper.rb
72
+ - test/unit/mysql_backup/test_helper.rb
73
+ - test/unit/mysql_backup/utilities/test_helper.rb
74
+ - test/unit/mysql_backup/storage/test_helper.rb
75
+ rdoc_options:
76
+ - --main
77
+ - README.txt
78
+ extra_rdoc_files:
79
+ - History.txt
80
+ - Manifest.txt
81
+ - README.txt
82
+ executables:
83
+ - sqlup
84
+ - sqlup_control
85
+ extensions: []
86
+
87
+ requirements: []
88
+
89
+ dependencies:
90
+ - !ruby/object:Gem::Dependency
91
+ name: named_arguments
92
+ version_requirement:
93
+ version_requirements: !ruby/object:Gem::Version::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 0.0.5
98
+ version:
99
+ - !ruby/object:Gem::Dependency
100
+ name: optiflag
101
+ version_requirement:
102
+ version_requirements: !ruby/object:Gem::Version::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 0.6.5
107
+ version:
108
+ - !ruby/object:Gem::Dependency
109
+ name: hoe
110
+ version_requirement:
111
+ version_requirements: !ruby/object:Gem::Version::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 1.2.1
116
+ version: