backupit 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ begin
10
10
  gem.email = "wosmvp@gmail.com"
11
11
  gem.homepage = "http://github.com/jinzhu/backupit"
12
12
  gem.authors = ["Jinzhu"]
13
+ gem.add_dependency ['mail']
13
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
15
  end
15
16
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
@@ -1,61 +1,61 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backupit}
8
- s.version = "0.1.3"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jinzhu"]
12
- s.date = %q{2010-11-16}
12
+ s.date = %q{2011-06-28}
13
13
  s.default_executable = %q{backup}
14
14
  s.description = %q{A tool to backup your servers}
15
15
  s.email = %q{wosmvp@gmail.com}
16
16
  s.executables = ["backup"]
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE",
19
- "README.md"
19
+ "README.md"
20
20
  ]
21
21
  s.files = [
22
22
  ".document",
23
- ".gitignore",
24
- "LICENSE",
25
- "README.md",
26
- "Rakefile",
27
- "VERSION",
28
- "backupit.gemspec",
29
- "bin/backup",
30
- "lib/backup.rb",
31
- "lib/backup/attribute.rb",
32
- "lib/backup/configuration/base.rb",
33
- "lib/backup/configuration/mysql.rb",
34
- "lib/backup/configuration/server.rb",
35
- "lib/backup/configuration/storage.rb",
36
- "lib/backup/server.rb",
37
- "lib/backup/storage.rb",
38
- "test/helper.rb",
39
- "test/test_backupit.rb"
23
+ "LICENSE",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "backupit.gemspec",
28
+ "bin/backup",
29
+ "lib/backup.rb",
30
+ "lib/backup/attribute.rb",
31
+ "lib/backup/configuration/base.rb",
32
+ "lib/backup/configuration/mysql.rb",
33
+ "lib/backup/configuration/server.rb",
34
+ "lib/backup/configuration/storage.rb",
35
+ "lib/backup/server.rb",
36
+ "lib/backup/storage.rb",
37
+ "test/helper.rb",
38
+ "test/test_backupit.rb"
40
39
  ]
41
40
  s.homepage = %q{http://github.com/jinzhu/backupit}
42
- s.rdoc_options = ["--charset=UTF-8"]
43
41
  s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.3.7}
42
+ s.rubygems_version = %q{1.4.2}
45
43
  s.summary = %q{A tool to backup your servers}
46
44
  s.test_files = [
47
45
  "test/helper.rb",
48
- "test/test_backupit.rb"
46
+ "test/test_backupit.rb"
49
47
  ]
50
48
 
51
49
  if s.respond_to? :specification_version then
52
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
50
  s.specification_version = 3
54
51
 
55
52
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_runtime_dependency(%q<mail>, [">= 0"])
56
54
  else
55
+ s.add_dependency(%q<mail>, [">= 0"])
57
56
  end
58
57
  else
58
+ s.add_dependency(%q<mail>, [">= 0"])
59
59
  end
60
60
  end
61
61
 
@@ -1,4 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ gem 'mail'
3
+ require 'mail'
2
4
  require 'backup/attribute'
3
5
  require 'backup/configuration/base'
4
6
  require 'backup/server'
@@ -29,5 +31,12 @@ module Backup
29
31
  puts shell.red
30
32
  @@options[:pretend] ? true : system(shell)
31
33
  end
34
+
35
+ def self.email(options)
36
+ puts "sending email to #{options[:to]}"
37
+ unless @@options[:pretend]
38
+ Mail.new(options).deliver!
39
+ end
40
+ end
32
41
  end
33
42
  end
@@ -2,8 +2,7 @@ module Backup
2
2
  module Configuration
3
3
  class Server
4
4
  extend Backup::Attribute
5
-
6
- generate_attributes :host, :rsync, :port
5
+ generate_attributes :host, :rsync, :port, :email
7
6
 
8
7
  def mysql(name=nil,&block)
9
8
  @mysqls ||= {}
@@ -2,7 +2,7 @@ module Backup
2
2
  module Configuration
3
3
  class Storage
4
4
  extend Backup::Attribute
5
- generate_attributes :path
5
+ generate_attributes :path, :smtp
6
6
  end
7
7
  end
8
8
  end
@@ -15,19 +15,19 @@ module Backup
15
15
  @server_config = @server.config
16
16
  @backup_path = "#{config.path}/#{@server.name}"
17
17
 
18
- @ssh_host = "'#{@server_config.host}'"
19
- @scp_host = @server_config.port ? "-P#{@server_config.port} #{@ssh_host}" : @ssh_host
20
- @rsync_host = @server_config.port ? " -e 'ssh -p#{@server_config.port}' #{@ssh_host}" : @ssh_host
21
- @ssh_host = "'-p#{@server_config.port}' #{@ssh_host}" if @server_config.port
22
-
18
+ @ssh_host = "-p#{@server_config.port || 22} #{@server_config.host}"
19
+ @scp_host = "-P#{@server_config.port || 22} #{@server_config.host}"
20
+ @rsync_host = "-e 'ssh -p#{@server_config.port || 22}' #{@server_config.host}"
23
21
 
24
22
  backup_rsync
25
23
  backup_mysql
24
+ notice_changes
26
25
  commit_changes
27
26
  end
28
27
 
29
28
  def backup_rsync
30
29
  target_path = File.join(@backup_path, "rsync")
30
+
31
31
  FileUtils.mkdir_p target_path
32
32
 
33
33
  @server_config.rsync.to_a.map do |path|
@@ -56,6 +56,20 @@ module Backup
56
56
  end
57
57
  end
58
58
 
59
+ def notice_changes
60
+ Dir.chdir(@backup_path) do
61
+ smtp_config = config.smtp
62
+ Mail.defaults { delivery_method :smtp, smtp_config } if smtp_config
63
+
64
+ changes = `git diff`
65
+ Backup::Main.email(:from => @server_config.email,
66
+ :to => @server_config.email,
67
+ :subject => "#{@server.name} backed up at #{Time.now}, changes: #{changes.split("\n").size}",
68
+ :body => changes
69
+ ) if @server_config.email
70
+ end
71
+ end
72
+
59
73
  def commit_changes
60
74
  Dir.chdir(@backup_path) do
61
75
  Backup::Main.run("git init") unless system("git status")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backupit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jinzhu
@@ -15,10 +15,23 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-16 00:00:00 +08:00
18
+ date: 2011-06-28 00:00:00 +08:00
19
19
  default_executable: backup
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: mail
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
22
35
  description: A tool to backup your servers
23
36
  email: wosmvp@gmail.com
24
37
  executables:
@@ -30,7 +43,6 @@ extra_rdoc_files:
30
43
  - README.md
31
44
  files:
32
45
  - .document
33
- - .gitignore
34
46
  - LICENSE
35
47
  - README.md
36
48
  - Rakefile
@@ -52,8 +64,8 @@ homepage: http://github.com/jinzhu/backupit
52
64
  licenses: []
53
65
 
54
66
  post_install_message:
55
- rdoc_options:
56
- - --charset=UTF-8
67
+ rdoc_options: []
68
+
57
69
  require_paths:
58
70
  - lib
59
71
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -77,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
89
  requirements: []
78
90
 
79
91
  rubyforge_project:
80
- rubygems_version: 1.3.7
92
+ rubygems_version: 1.4.2
81
93
  signing_key:
82
94
  specification_version: 3
83
95
  summary: A tool to backup your servers
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC