backupit 0.2.0 → 0.2.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.
- data/VERSION +1 -1
- data/lib/backup.rb +7 -1
- data/lib/backup/storage.rb +14 -12
- metadata +7 -8
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.1
|
data/lib/backup.rb
CHANGED
|
@@ -29,7 +29,13 @@ module Backup
|
|
|
29
29
|
|
|
30
30
|
def self.run(shell)
|
|
31
31
|
puts shell.red
|
|
32
|
-
@@options[:pretend]
|
|
32
|
+
if @@options[:pretend]
|
|
33
|
+
true
|
|
34
|
+
else
|
|
35
|
+
results = `#{shell}`
|
|
36
|
+
return false if $?.to_i > 0
|
|
37
|
+
results
|
|
38
|
+
end
|
|
33
39
|
end
|
|
34
40
|
|
|
35
41
|
def self.email(options)
|
data/lib/backup/storage.rb
CHANGED
|
@@ -3,7 +3,7 @@ require 'tempfile'
|
|
|
3
3
|
module Backup
|
|
4
4
|
class Storage
|
|
5
5
|
extend Backup::Attribute
|
|
6
|
-
attr_accessor :name, :config
|
|
6
|
+
attr_accessor :name, :config, :changes
|
|
7
7
|
|
|
8
8
|
def initialize(name, config)
|
|
9
9
|
self.name = name
|
|
@@ -19,10 +19,12 @@ module Backup
|
|
|
19
19
|
@scp_host = "-P#{@server_config.port || 22} #{@server_config.host}"
|
|
20
20
|
@rsync_host = "-e 'ssh -p#{@server_config.port || 22}' #{@server_config.host}"
|
|
21
21
|
|
|
22
|
+
self.changes = []
|
|
23
|
+
|
|
22
24
|
backup_rsync
|
|
23
25
|
backup_mysql
|
|
24
|
-
notice_changes
|
|
25
26
|
commit_changes
|
|
27
|
+
notice_changes
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
def backup_rsync
|
|
@@ -33,7 +35,7 @@ module Backup
|
|
|
33
35
|
@server_config.rsync.to_a.map do |path|
|
|
34
36
|
remote_path = path.is_a?(Hash) ? path.first[0] : path
|
|
35
37
|
target_name = File.basename(path.is_a?(Hash) ? path.first[1] : path)
|
|
36
|
-
Backup::Main.run "rsync -ravk #{@rsync_host}:#{remote_path.sub(/\/?$/,'/')} '#{File.join(target_path, target_name)}'"
|
|
38
|
+
self.changes << Backup::Main.run "rsync -ravk #{@rsync_host}:#{remote_path.sub(/\/?$/,'/')} '#{File.join(target_path, target_name)}'"
|
|
37
39
|
end
|
|
38
40
|
end
|
|
39
41
|
|
|
@@ -50,9 +52,9 @@ module Backup
|
|
|
50
52
|
mysql_config += " #{mysql.options}" if mysql.options
|
|
51
53
|
|
|
52
54
|
tmpfile = Tempfile.new('mysql.sql')
|
|
53
|
-
Backup::Main.run("ssh #{@ssh_host} 'mysqldump #{mysql_config} > #{tmpfile.path}'") &&
|
|
54
|
-
Backup::Main.run("scp #{@scp_host}:#{tmpfile.path} '#{target_path}/#{key}.sql'") &&
|
|
55
|
-
Backup::Main.run("ssh #{@ssh_host} 'rm #{tmpfile.path}'")
|
|
55
|
+
self.changes << Backup::Main.run("ssh #{@ssh_host} 'mysqldump #{mysql_config} > #{tmpfile.path}'") &&
|
|
56
|
+
self.changes << Backup::Main.run("scp #{@scp_host}:#{tmpfile.path} '#{target_path}/#{key}.sql'") &&
|
|
57
|
+
self.changes << Backup::Main.run("ssh #{@ssh_host} 'rm #{tmpfile.path}'")
|
|
56
58
|
end
|
|
57
59
|
end
|
|
58
60
|
|
|
@@ -61,20 +63,20 @@ module Backup
|
|
|
61
63
|
smtp_config = config.smtp
|
|
62
64
|
Mail.defaults { delivery_method :smtp, smtp_config } if smtp_config
|
|
63
65
|
|
|
64
|
-
changes = `git diff`
|
|
65
66
|
Backup::Main.email(:from => @server_config.email,
|
|
66
67
|
:to => @server_config.email,
|
|
67
|
-
:subject => "#{@server.name} backed up at #{Time.now}
|
|
68
|
-
:body => changes
|
|
68
|
+
:subject => "#{@server.name} backed up at #{Time.now}",
|
|
69
|
+
:body => changes.join("\n"),
|
|
70
|
+
:charset => 'utf-8', :content_type => 'text/plain; charset=utf-8'
|
|
69
71
|
) if @server_config.email
|
|
70
72
|
end
|
|
71
73
|
end
|
|
72
74
|
|
|
73
75
|
def commit_changes
|
|
74
76
|
Dir.chdir(@backup_path) do
|
|
75
|
-
Backup::Main.run("git init") unless system("git status")
|
|
76
|
-
Backup::Main.run("git add .")
|
|
77
|
-
Backup::Main.run("git commit -am '#{Time.now.strftime("%Y-%m-%d %H:%M")}'")
|
|
77
|
+
(self.changes << Backup::Main.run("git init")) unless system("git status")
|
|
78
|
+
self.changes << Backup::Main.run("git add .")
|
|
79
|
+
self.changes << Backup::Main.run("git commit -am '#{Time.now.strftime("%Y-%m-%d %H:%M")}'")
|
|
78
80
|
end
|
|
79
81
|
end
|
|
80
82
|
end
|
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:
|
|
4
|
+
hash: 21
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 2
|
|
9
|
-
-
|
|
10
|
-
version: 0.2.
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.2.1
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Jinzhu
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2011-
|
|
18
|
+
date: 2011-07-11 00:00:00 +08:00
|
|
19
19
|
default_executable: backup
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -89,10 +89,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
89
89
|
requirements: []
|
|
90
90
|
|
|
91
91
|
rubyforge_project:
|
|
92
|
-
rubygems_version: 1.
|
|
92
|
+
rubygems_version: 1.6.2
|
|
93
93
|
signing_key:
|
|
94
94
|
specification_version: 3
|
|
95
95
|
summary: A tool to backup your servers
|
|
96
|
-
test_files:
|
|
97
|
-
|
|
98
|
-
- test/test_backupit.rb
|
|
96
|
+
test_files: []
|
|
97
|
+
|