backzilla 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  tmp/*
2
+ pkg/*
3
+
@@ -9,23 +9,43 @@ It can backup multiple entities (for example: MySQL database, directory, etc) to
9
9
 
10
10
  Usage
11
11
  =====
12
- No gem available currently, so:
12
+ To install gem type:
13
13
 
14
- git clone git://github.com/amberbit/backzilla.git
14
+ gem install backzilla
15
15
 
16
- Backzilla will look for ~/.backzilla/projects.yaml and ~/.backzilla/stores.yaml files. Just copy from /examples and customize. Be sure to generate your own GNU PGP passphrase and put it to stores.yaml.
16
+ Backzilla will look for ~/.backzilla/projects.yaml and ~/.backzilla/stores.yaml files. You can copy them from /examples and customize for your oun purpose. Be sure to generate your own GNU PGP passphrase and put it to stores.yaml. It's basic of storing and restorign security of your backups.
17
17
 
18
18
  To backup all entities:
19
19
 
20
- backzilla/bin/backzilla -b all
20
+ backzilla -b all
21
21
 
22
22
  To backup a whole project or single entity:
23
23
 
24
- backzilla/bin/backzilla -b project_name[:entity_name]
24
+ backzilla -b project_name[:entity_name]
25
+
26
+ To restore all entities:
27
+
28
+ backzilla -r all
29
+
30
+ To backup a whole project or single entity:
31
+
32
+ backzilla -r project_name[:entity_name]
33
+
34
+ To remove backups of given project from all stores:
35
+
36
+ backzilla --remove project_name[:entity_name]
37
+
38
+ To remove all backups from all stores:
39
+
40
+ backzilla --remove all
41
+
42
+ For other options type:
43
+
44
+ backzilla -h
25
45
 
26
46
  Current state aka TODOs
27
47
  =======================
28
- Backup part is generally done. Needs some polishing and specs. Restore isn't implemented completely. Probably the script should also catch CTRL+C or any other interruptions and perform some wise cleanup.
48
+ Backup and restore works correctly. Same goes with te rspec tests.
29
49
 
30
50
  - -m switch - move project_name to new_project_name or project_name:entity_name to new_project_name:new_entity_name in all stores
31
51
  - always backup ~/.backzilla too
@@ -47,18 +67,18 @@ Backup part is generally done. Needs some polishing and specs. Restore isn't imp
47
67
  entity1:
48
68
  ...
49
69
  in such case amberbit-www entity3 would be accessed like this amberbit:www:entity3
50
- - -rm BACKUP_PATH - removes this backup from all stores
51
70
  - if not present, sample config files should be created
52
- - add more entity types
53
- - add more store types
71
+ - restore from some given date...
72
+
73
+ We are planning to add some more entity and store types to extend backzilla options.
54
74
 
55
- Supported entity types
75
+ Currently supported entity types
56
76
  ======================
57
77
  - MySQL
58
78
  - MongoDB
59
79
  - Directory
60
80
 
61
- Supported store types
81
+ Currently supported store types
62
82
  =====================
63
83
  - FTP
64
84
  - SSH
data/VERSION CHANGED
@@ -1,2 +1,2 @@
1
- 0.0.1
1
+ 0.0.2
2
2
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backzilla}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wojtek Piekutowski, Pawe\305\202 Sobolewski"]
12
- s.date = %q{2010-07-30}
12
+ s.date = %q{2010-08-02}
13
13
  s.default_executable = %q{backzilla}
14
14
  s.description = %q{Backzilla can backup multiple entities to multiple destinations.}
15
15
  s.email = %q{pawel.sobolewski@amberbit.com}
@@ -66,7 +66,8 @@ Gem::Specification.new do |s|
66
66
  s.rubygems_version = %q{1.3.5}
67
67
  s.summary = %q{Multi-purpose backup tool}
68
68
  s.test_files = [
69
- "spec/spec_helper.rb",
69
+ "spec/remove_spec.rb",
70
+ "spec/spec_helper.rb",
70
71
  "spec/entities/directory_spec.rb",
71
72
  "spec/entities/mysql_spec.rb",
72
73
  "spec/entities/mongodb_spec.rb"
@@ -27,6 +27,11 @@ OptionParser.new do |cmd_options|
27
27
  options[:spec] = spec
28
28
  end
29
29
 
30
+ cmd_options.on("--remove PROJECT_SPEC", "Removes backups of PROJECT_SPEC from given stores") do |spec|
31
+ options[:remove] = true
32
+ options[:spec] = spec
33
+ end
34
+
30
35
  cmd_options.on("-q", "--quite", "Supress log messages with level lower than ERROR") do |spec|
31
36
  options[:quiet] = true
32
37
  end
@@ -58,6 +58,20 @@ module Backzilla
58
58
  stores.each { |s| s.get path, project_name, entity_name }
59
59
  end
60
60
 
61
+ def self.remove(path, project_name, entity_name)
62
+ info "Removing #{project_name}[:#{entity_name}]..."
63
+
64
+ restores_file = File.expand_path STORES_CONFIG
65
+ data = YAML.load_file restores_file
66
+ Store.gnugpg_passphrase = data['gnupg_passphrase']
67
+ stores = data['stores'].map do |store_name, store_options|
68
+ klass = Backzilla::Store.const_get(store_options['type'])
69
+ klass.new(store_name, store_options)
70
+ end
71
+
72
+ stores.each { |s| s.delete path, project_name, entity_name }
73
+ end
74
+
61
75
  def self.logger
62
76
  return @logger if @logger
63
77
  @logger = Logger.new(STDOUT)
@@ -76,11 +90,11 @@ module Backzilla
76
90
  config.send "#{key}=", value
77
91
  end
78
92
 
79
- if config.backup && config.restore
80
- fatal "Use -r or -b separately"
93
+ if config.backup && config.restore && config.remove
94
+ fatal "Use --remove, -r or -b separately"
81
95
  exit -1
82
- elsif !config.backup && !config.restore
83
- fatal "-r or -b required"
96
+ elsif !config.backup && !config.restore && !config.remove
97
+ fatal "--remove, -r or -b required"
84
98
  exit -1
85
99
  end
86
100
 
@@ -93,7 +107,14 @@ module Backzilla
93
107
  project.setup_entities data[project_name]
94
108
  projects << project
95
109
  end
96
- projects.each { |p| config.restore ? p.restore : p.backup }
110
+
111
+ if config.backup
112
+ projects.each { |p| p.backup }
113
+ elsif config.restore
114
+ projects.each { |p| p.restore }
115
+ elsif config.remove
116
+ projects.each { |p| p.remove }
117
+ end
97
118
  else
98
119
  spec_parts = config.spec.split(':')
99
120
  project_name = spec_parts.shift
@@ -109,6 +130,8 @@ module Backzilla
109
130
  project.backup spec_parts
110
131
  elsif config.restore
111
132
  project.restore spec_parts
133
+ elsif config.remove
134
+ project.remove spec_parts
112
135
  end
113
136
  end
114
137
  end
@@ -30,6 +30,11 @@ class Backzilla::Entity::Directory < Backzilla::Entity
30
30
  @path
31
31
  end
32
32
 
33
+ def remove
34
+ Backzilla.remove @path, project.name, self.name
35
+ @path
36
+ end
37
+
33
38
  private
34
39
 
35
40
  def validate_path
@@ -43,5 +43,10 @@ class Backzilla::Entity::MongoDB < Backzilla::Entity
43
43
  Backzilla.restore path, project.name, self.name
44
44
  finalize_restore(:path => path)
45
45
  end
46
+
47
+ def remove
48
+ Backzilla.remove @path, project.name, self.name
49
+ @path
50
+ end
46
51
  end
47
52
 
@@ -53,6 +53,11 @@ class Backzilla::Entity::MySQL < Backzilla::Entity
53
53
  finalize_restore(:path => path)
54
54
  end
55
55
 
56
+ def remove
57
+ Backzilla.remove @path, project.name, self.name
58
+ @path
59
+ end
60
+
56
61
  private
57
62
 
58
63
  def mysql_options
@@ -37,5 +37,14 @@ class Backzilla::Project
37
37
  @entities[spec_parts.shift].restore
38
38
  end
39
39
  end
40
+
41
+ def remove(spec_parts=[])
42
+ info "Project #{name}:"
43
+ if spec_parts.empty?
44
+ @entities.each { |name, entity| entity.remove }
45
+ else
46
+ @entities[spec_parts.shift].remove
47
+ end
48
+ end
40
49
  end
41
50
 
@@ -17,6 +17,7 @@ class Backzilla::Store
17
17
  end
18
18
 
19
19
  def put(source_path, project_name, entity_name)
20
+ pp uri
20
21
  cmd =<<-CMD
21
22
  PASSPHRASE='#{@@gnugpg_passphrase}' #{env_options} \\
22
23
  duplicity #{source_path} #{protocol}://#{uri}/#{project_name}/#{entity_name}
@@ -32,6 +33,10 @@ class Backzilla::Store
32
33
  execute cmd
33
34
  end
34
35
 
36
+ def delete(source_path, project_name, entity_name)
37
+ FileUtils.rm_rf "#{uri}/#{project_name}/#{entity_name}"
38
+ end
39
+
35
40
  private
36
41
 
37
42
  def env_options
@@ -0,0 +1,89 @@
1
+ require 'spec/spec_helper'
2
+
3
+ PROJECTS_CONFIG = 'spec/configs/remove_files/projects.yaml'
4
+ STORES_CONFIG = 'spec/configs/remove_files/stores.yaml'
5
+
6
+ def clean_up
7
+ FileUtils.rm_rf "/tmp/backzilla/"
8
+ drop_mongodb_database
9
+ end
10
+
11
+ def create_mongodb_database
12
+ cmd =<<-CMD
13
+ echo "use backzilla_test
14
+ db.users.insert({name: 'Paweł', email: 'cokolwiek@amberbit.com', password: 'qweqwe'})
15
+ db.users.insert({name: 'Łukasz1', email: 'cokolwiek@amberbit.com', password: 'qweqwe'})
16
+ db.users.insert({name: 'Łukasz2', email: 'cokolwiek@amberbit.com', password: 'qweqwe'})
17
+ db.users.insert({name: 'Wojtek', email: 'cokolwiek@amberbit.com', password: 'qweqwe'})
18
+ db.users.insert({name: 'Marcin', email: 'cokolwiek@amberbit.com', password: 'qweqwe'})
19
+ db.users.insert({name: 'Hubert', email: 'cokolwiek@amberbit.com', password: 'qweqwe'})" |\
20
+ mongo
21
+ CMD
22
+ `#{cmd}`
23
+ end
24
+
25
+ def drop_mongodb_database
26
+ cmd =<<-CMD
27
+ echo "use backzilla_test
28
+ db.dropDatabase()" |\
29
+ mongo
30
+ CMD
31
+ `#{cmd}`
32
+ end
33
+
34
+ describe "Backzilla", "Remove" do
35
+ before :each do
36
+ setup_directory
37
+ create_mongodb_database
38
+ end
39
+
40
+ after(:all) do
41
+ clean_up
42
+ end
43
+
44
+ it "should remove given project from all stores" do
45
+ cmd = "./bin/backzilla -b test1"
46
+ cmd = "BACKZILLA_STORES_CONFIG=spec/configs/remove_files/stores.yaml " + cmd
47
+ cmd = "BACKZILLA_PROJECTS_CONFIG=spec/configs/remove_files/projects.yaml " + cmd
48
+ `sh -c "#{cmd}"`
49
+
50
+ cmd = "./bin/backzilla --remove test1"
51
+ cmd = "BACKZILLA_STORES_CONFIG=spec/configs/remove_files/stores.yaml " + cmd
52
+ cmd = "BACKZILLA_PROJECTS_CONFIG=spec/configs/remove_files/projects.yaml " + cmd
53
+ `sh -c "#{cmd}"`
54
+
55
+ cmd = "ls spec/backups/remove_files_spec1/test1/|wc -l"
56
+ files = `#{cmd}`
57
+ files.to_i.should == 0
58
+ cmd = "ls spec/backups/remove_files_spec2/test1/|wc -l"
59
+ files = `#{cmd}`
60
+ files.to_i.should == 0
61
+ end
62
+
63
+ it "should remove all projects from all stores" do
64
+ cmd = "./bin/backzilla -b all"
65
+ cmd = "BACKZILLA_STORES_CONFIG=spec/configs/remove_files/stores.yaml " + cmd
66
+ cmd = "BACKZILLA_PROJECTS_CONFIG=spec/configs/remove_files/projects.yaml " + cmd
67
+ `sh -c "#{cmd}"`
68
+
69
+ cmd = "./bin/backzilla --remove all"
70
+ cmd = "BACKZILLA_STORES_CONFIG=spec/configs/remove_files/stores.yaml " + cmd
71
+ cmd = "BACKZILLA_PROJECTS_CONFIG=spec/configs/remove_files/projects.yaml " + cmd
72
+ `sh -c "#{cmd}"`
73
+
74
+ cmd = "ls spec/backups/remove_files_spec1/test1/|wc -l"
75
+ files = `#{cmd}`
76
+ files.to_i.should == 0
77
+ cmd = "ls spec/backups/remove_files_spec2/test1/|wc -l"
78
+ files = `#{cmd}`
79
+ files.to_i.should == 0
80
+ cmd = "ls spec/backups/remove_files_spec1/test2/|wc -l"
81
+ files = `#{cmd}`
82
+ files.to_i.should == 0
83
+ cmd = "ls spec/backups/remove_files_spec2/test2/|wc -l"
84
+ files = `#{cmd}`
85
+ files.to_i.should == 0
86
+ end
87
+
88
+ end
89
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backzilla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Wojtek Piekutowski, Pawe\xC5\x82 Sobolewski"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-07-30 00:00:00 +02:00
12
+ date: 2010-08-02 00:00:00 +02:00
13
13
  default_executable: backzilla
14
14
  dependencies: []
15
15
 
@@ -92,6 +92,7 @@ signing_key:
92
92
  specification_version: 3
93
93
  summary: Multi-purpose backup tool
94
94
  test_files:
95
+ - spec/remove_spec.rb
95
96
  - spec/spec_helper.rb
96
97
  - spec/entities/directory_spec.rb
97
98
  - spec/entities/mysql_spec.rb