backzilla 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +1 -0
  2. data/COPYING +340 -0
  3. data/LICENSE +57 -0
  4. data/README.markdown +70 -0
  5. data/Rakefile +28 -0
  6. data/VERSION +2 -0
  7. data/backzilla.gemspec +85 -0
  8. data/bin/backzilla +40 -0
  9. data/examples/projects.yaml +31 -0
  10. data/examples/stores.yaml +12 -0
  11. data/lib/backzilla.rb +116 -0
  12. data/lib/backzilla/configuration.rb +6 -0
  13. data/lib/backzilla/connection.rb +5 -0
  14. data/lib/backzilla/entity.rb +31 -0
  15. data/lib/backzilla/entity/directory.rb +46 -0
  16. data/lib/backzilla/entity/mongo_db.rb +47 -0
  17. data/lib/backzilla/entity/my_sql.rb +68 -0
  18. data/lib/backzilla/executor.rb +17 -0
  19. data/lib/backzilla/logger_helper.rb +31 -0
  20. data/lib/backzilla/project.rb +41 -0
  21. data/lib/backzilla/store.rb +49 -0
  22. data/lib/backzilla/store/directory.rb +21 -0
  23. data/lib/backzilla/store/ftp.rb +37 -0
  24. data/lib/backzilla/store/ssh.rb +37 -0
  25. data/lib/backzilla/version.rb +4 -0
  26. data/spec/configs/directory/projects.yaml +5 -0
  27. data/spec/configs/directory/stores.yaml +6 -0
  28. data/spec/configs/mongodb/projects.yaml +5 -0
  29. data/spec/configs/mongodb/stores.yaml +11 -0
  30. data/spec/configs/mysql/projects.yaml +7 -0
  31. data/spec/configs/mysql/stores.yaml +11 -0
  32. data/spec/entities/directory_spec.rb +46 -0
  33. data/spec/entities/mongodb_spec.rb +104 -0
  34. data/spec/entities/mysql_spec.rb +126 -0
  35. data/spec/fixtures/directory/a.txt +2 -0
  36. data/spec/fixtures/directory/b.txt +1 -0
  37. data/spec/fixtures/directory/some/nested/stuff/c.txt +1 -0
  38. data/spec/fixtures/mysql/backzilla_test.sql +54 -0
  39. data/spec/spec.opts +1 -0
  40. data/spec/spec_helper.rb +47 -0
  41. metadata +98 -0
@@ -0,0 +1,126 @@
1
+ require 'spec/spec_helper'
2
+
3
+ PROJECTS_CONFIG = 'spec/configs/mysql/projects.yaml'
4
+ STORES_CONFIG = 'spec/configs/mysql/stores.yaml'
5
+
6
+ def create_mysql_database
7
+ cmd =<<-CMD
8
+ echo "create database backzilla_test;
9
+ create table backzilla_test.users
10
+ (user_id INT NOT NULL AUTO_INCREMENT,
11
+ email VARCHAR(80) NOT NULL,
12
+ name VARCHAR(50) NOT NULL,
13
+ password CHAR(41) NOT NULL,
14
+ PRIMARY KEY (user_id),
15
+ UNIQUE INDEX (email));
16
+ insert into backzilla_test.users
17
+ (user_id, email, name, password)
18
+ values
19
+ ('1', 'Lukas@amberbit.com', 'Lukas Kowalski', 'qweasd');
20
+ insert into backzilla_test.users
21
+ (user_id, email, name, password)
22
+ values
23
+ ('2', 'Martin@amberbit.com', 'Martin Kowalski', 'qwezxc');
24
+ insert into backzilla_test.users
25
+ (user_id, email, name, password)
26
+ values
27
+ ('3', 'Wojtek@amberbit.com', 'Wojtek Kowalski', 'qwerty');
28
+ insert into backzilla_test.users
29
+ (user_id, email, name, password)
30
+ values
31
+ ('4', 'Paul@amberbit.com', 'Paul Kowalski', 'qweasd');
32
+ insert into backzilla_test.users
33
+ (user_id, email, name, password)
34
+ values
35
+ ('5', 'Hubert@amberbit.com', 'Hubert Kowalski', 'qweqwe');
36
+ insert into backzilla_test.users
37
+ (user_id, email, name, password)
38
+ values
39
+ ('6', 'Lukas2@amberbit.com', 'Lukas2 Kowalski', 'qweqwe');" | \
40
+ mysql -u #{$user} -p#{$password}
41
+ CMD
42
+ system(cmd)
43
+ end
44
+
45
+ def modify_mysql_database
46
+ cmd =<<-CMD
47
+ echo "update backzilla_test.users set
48
+ name = 'Kacper the friendly ghoust'
49
+ where user_id = 1" | \
50
+ mysql -u #{$user} -p#{$password}
51
+ CMD
52
+ system(cmd)
53
+ end
54
+
55
+ def drop_mysql_database
56
+ cmd =<<-CMD
57
+ echo "drop database backzilla_test; " |\
58
+ mysql -u #{$user} -p#{$password}
59
+ CMD
60
+ `#{cmd}`
61
+ end
62
+
63
+ describe "Backzilla", "mysql", "backup preparation" do
64
+ before :each do
65
+ projects_file = File.expand_path PROJECTS_CONFIG
66
+ data = YAML.load_file projects_file
67
+ projects = data.inject([]) do |projects, project_data|
68
+ project_name, project_entities_data = *project_data
69
+ data[project_name].each do |entity_name, entity_data|
70
+ $password = entity_data['password']
71
+ $user = entity_data['user']
72
+ @mysql = Backzilla::Entity::MySQL.new('test', entity_data)
73
+ end
74
+ end
75
+ create_mysql_database
76
+ @mysql.project = Backzilla::Project.new('test')
77
+ end
78
+
79
+ it "should prepare mysql database to be backed up" do
80
+ path = Pathname.new(@mysql.prepare_backup)
81
+ path.should == Pathname.new("/tmp/backzilla/test/test/backzilla_test.sql")
82
+ flaga = false
83
+ file1 = File.new(path, "r")
84
+ file2 = File.new('spec/fixtures/mysql/backzilla_test.sql', "r")
85
+ while (line1 = file1.gets)
86
+ line2 = file2.gets
87
+ unless line1.include? "-- Dump completed"
88
+ unless line1.include? "-- Server version"
89
+ line1.should == line2
90
+ end
91
+ end
92
+ end
93
+ file1.close
94
+ file2.close
95
+ end
96
+ end
97
+
98
+ describe "Backzilla", "mysql", "finalize restore" do
99
+ before :each do
100
+ projects_file = File.expand_path PROJECTS_CONFIG
101
+ data = YAML.load_file projects_file
102
+ projects = data.inject([]) do |projects, project_data|
103
+ project_name, project_entities_data = *project_data
104
+ data[project_name].each do |entity_name, entity_data|
105
+ @mysql = Backzilla::Entity::MySQL.new('test', entity_data)
106
+ end
107
+ end
108
+ @mysql.project = Backzilla::Project.new('test')
109
+ end
110
+
111
+ after(:all) do
112
+ drop_mysql_database
113
+ end
114
+
115
+ it "should restore mysql database from given file" do
116
+ modify_mysql_database
117
+ @mysql.finalize_restore(:path => '/tmp/backzilla/test/test/')
118
+ cmd =<<-CMD
119
+ echo "select * from backzilla_test.users; " |\
120
+ mysql -u #{$user} -p#{$password}
121
+ CMD
122
+ tmp = `#{cmd}`
123
+ tmp.should_not include "Kacper the friendly ghoust"
124
+ end
125
+ end
126
+
@@ -0,0 +1,2 @@
1
+ aaa
2
+
@@ -0,0 +1 @@
1
+ bbb
@@ -0,0 +1,54 @@
1
+ -- MySQL dump 10.13 Distrib 5.1.41, for debian-linux-gnu (x86_64)
2
+ --
3
+ -- Host: localhost Database: backzilla_test
4
+ -- ------------------------------------------------------
5
+ -- Server version 5.1.41-3ubuntu12.3
6
+
7
+ /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8
+ /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9
+ /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10
+ /*!40101 SET NAMES utf8 */;
11
+ /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12
+ /*!40103 SET TIME_ZONE='+00:00' */;
13
+ /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14
+ /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15
+ /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16
+ /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17
+
18
+ --
19
+ -- Table structure for table `users`
20
+ --
21
+
22
+ DROP TABLE IF EXISTS `users`;
23
+ /*!40101 SET @saved_cs_client = @@character_set_client */;
24
+ /*!40101 SET character_set_client = utf8 */;
25
+ CREATE TABLE `users` (
26
+ `user_id` int(11) NOT NULL AUTO_INCREMENT,
27
+ `email` varchar(80) NOT NULL,
28
+ `name` varchar(50) NOT NULL,
29
+ `password` char(41) NOT NULL,
30
+ PRIMARY KEY (`user_id`),
31
+ UNIQUE KEY `email` (`email`)
32
+ ) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
33
+ /*!40101 SET character_set_client = @saved_cs_client */;
34
+
35
+ --
36
+ -- Dumping data for table `users`
37
+ --
38
+
39
+ LOCK TABLES `users` WRITE;
40
+ /*!40000 ALTER TABLE `users` DISABLE KEYS */;
41
+ INSERT INTO `users` VALUES (1,'Lukas@amberbit.com','Lukas Kowalski','qweasd'),(2,'Martin@amberbit.com','Martin Kowalski','qwezxc'),(3,'Wojtek@amberbit.com','Wojtek Kowalski','qwerty'),(4,'Paul@amberbit.com','Paul Kowalski','qweasd'),(5,'Hubert@amberbit.com','Hubert Kowalski','qweqwe'),(6,'Lukas2@amberbit.com','Lukas2 Kowalski','qweqwe');
42
+ /*!40000 ALTER TABLE `users` ENABLE KEYS */;
43
+ UNLOCK TABLES;
44
+ /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
45
+
46
+ /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
47
+ /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
48
+ /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
49
+ /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
50
+ /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
51
+ /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
52
+ /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
53
+
54
+ -- Dump completed on 2010-07-19 12:11:40
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,47 @@
1
+ require 'fileutils'
2
+ $LOAD_PATH.unshift "lib"
3
+ require "backzilla"
4
+
5
+ Spec::Runner.configure do |config|
6
+ # == Mock Framework
7
+ #
8
+ # RSpec uses it's own mocking framework by default. If you prefer to
9
+ # use mocha, flexmock or RR, uncomment the appropriate line:
10
+ #
11
+ # config.mock_with :mocha
12
+ # config.mock_with :flexmock
13
+ # config.mock_with :rr
14
+ #
15
+ # == Notes
16
+ #
17
+ # For more information take a look at Spec::Example::Configuration and Spec::Runner
18
+
19
+ def prefix_configs(prefix)
20
+ @prefix = prefix
21
+ end
22
+
23
+ def run_backzilla(options)
24
+ option = options[:option]
25
+ cmd = "./bin/backzilla #{option} #{options[:project_name]}"
26
+ if @prefix
27
+ cmd = "BACKZILLA_STORES_CONFIG=spec/configs/#{@prefix}/stores.yaml " + cmd
28
+ cmd = "BACKZILLA_PROJECTS_CONFIG=spec/configs/#{@prefix}/projects.yaml " + cmd
29
+ end
30
+ `sh -c "#{cmd}"`
31
+ end
32
+
33
+ def directory_path
34
+ if !File.exist? "/tmp/backzilla/#{@prefix}"
35
+ if !File.exist? "/tmp/backzilla"
36
+ FileUtils.mkdir "/tmp/backzilla"
37
+ end
38
+ FileUtils.mkdir "/tmp/backzilla/#{@prefix}"
39
+ end
40
+ "/tmp/backzilla/#{@prefix}"
41
+ end
42
+
43
+ def setup_directory
44
+ FileUtils.cp_r "spec/fixtures/directory", "/tmp/backzilla/"
45
+ end
46
+ end
47
+
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backzilla
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "Wojtek Piekutowski, Pawe\xC5\x82 Sobolewski"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-07-30 00:00:00 +02:00
13
+ default_executable: backzilla
14
+ dependencies: []
15
+
16
+ description: Backzilla can backup multiple entities to multiple destinations.
17
+ email: pawel.sobolewski@amberbit.com
18
+ executables:
19
+ - backzilla
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.markdown
25
+ files:
26
+ - .gitignore
27
+ - COPYING
28
+ - LICENSE
29
+ - README.markdown
30
+ - Rakefile
31
+ - VERSION
32
+ - backzilla.gemspec
33
+ - bin/backzilla
34
+ - examples/projects.yaml
35
+ - examples/stores.yaml
36
+ - lib/backzilla.rb
37
+ - lib/backzilla/configuration.rb
38
+ - lib/backzilla/connection.rb
39
+ - lib/backzilla/entity.rb
40
+ - lib/backzilla/entity/directory.rb
41
+ - lib/backzilla/entity/mongo_db.rb
42
+ - lib/backzilla/entity/my_sql.rb
43
+ - lib/backzilla/executor.rb
44
+ - lib/backzilla/logger_helper.rb
45
+ - lib/backzilla/project.rb
46
+ - lib/backzilla/store.rb
47
+ - lib/backzilla/store/directory.rb
48
+ - lib/backzilla/store/ftp.rb
49
+ - lib/backzilla/store/ssh.rb
50
+ - lib/backzilla/version.rb
51
+ - spec/configs/directory/projects.yaml
52
+ - spec/configs/directory/stores.yaml
53
+ - spec/configs/mongodb/projects.yaml
54
+ - spec/configs/mongodb/stores.yaml
55
+ - spec/configs/mysql/projects.yaml
56
+ - spec/configs/mysql/stores.yaml
57
+ - spec/entities/directory_spec.rb
58
+ - spec/entities/mongodb_spec.rb
59
+ - spec/entities/mysql_spec.rb
60
+ - spec/fixtures/directory/a.txt
61
+ - spec/fixtures/directory/b.txt
62
+ - spec/fixtures/directory/some/nested/stuff/c.txt
63
+ - spec/fixtures/mysql/backzilla_test.sql
64
+ - spec/spec.opts
65
+ - spec/spec_helper.rb
66
+ has_rdoc: true
67
+ homepage: http://amberbit.com/
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --charset=UTF-8
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.5
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Multi-purpose backup tool
94
+ test_files:
95
+ - spec/spec_helper.rb
96
+ - spec/entities/directory_spec.rb
97
+ - spec/entities/mysql_spec.rb
98
+ - spec/entities/mongodb_spec.rb