backupit 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -2
- data/VERSION +1 -1
- data/backupit.gemspec +3 -3
- data/bin/backup +1 -1
- data/lib/backup/configuration/server.rb +1 -1
- data/lib/backup/storage.rb +16 -8
- metadata +4 -4
data/README
CHANGED
@@ -6,8 +6,10 @@ storage :file do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
server 'delonghi' do
|
9
|
-
|
10
|
-
|
9
|
+
host "delonghi@10.0.1.1"
|
10
|
+
port "222"
|
11
|
+
|
12
|
+
rsync ['/home/www/app/shared/config',{'/home/staging/app/shared/config' => 'staging_config'}, '/home/www/app/shared/attachments']
|
11
13
|
|
12
14
|
mysql 'delonghi' do
|
13
15
|
user 'root'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/backupit.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{backupit}
|
8
|
-
s.version = "0.0.
|
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 = ["Jinzhu"]
|
@@ -46,8 +46,8 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.rubygems_version = %q{1.3.7}
|
47
47
|
s.summary = %q{A tool to backup your servers}
|
48
48
|
s.test_files = [
|
49
|
-
"test/
|
50
|
-
"test/
|
49
|
+
"test/helper.rb",
|
50
|
+
"test/test_backupit.rb"
|
51
51
|
]
|
52
52
|
|
53
53
|
if s.respond_to? :specification_version then
|
data/bin/backup
CHANGED
data/lib/backup/storage.rb
CHANGED
@@ -15,6 +15,11 @@ 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
23
|
backup_rsync
|
19
24
|
backup_mysql
|
20
25
|
commit_changes
|
@@ -25,33 +30,36 @@ module Backup
|
|
25
30
|
FileUtils.mkdir_p target_path
|
26
31
|
|
27
32
|
@server_config.rsync.to_a.map do |path|
|
28
|
-
|
33
|
+
remote_path = path.is_a?(Hash) ? path.first[0] : path
|
34
|
+
target_name = File.basename(path.is_a?(Hash) ? path.first[1] : path)
|
35
|
+
Backup::Main.run "rsync -rav #{@rsync_host}:#{remote_path.sub(/\/?$/,'/')} '#{File.join(target_path, target_name)}'"
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
32
39
|
def backup_mysql
|
33
|
-
target_path = File.join(@backup_path, "
|
40
|
+
target_path = File.join(@backup_path, "mysql")
|
34
41
|
FileUtils.mkdir_p target_path
|
35
42
|
|
36
43
|
@server_config.mysql.map do |key, mysql|
|
37
44
|
mysql_config = ""
|
38
45
|
mysql_config += " -u#{mysql.user}" if mysql.user
|
39
|
-
mysql_config += " -p#{mysql.
|
46
|
+
mysql_config += " -p#{mysql.password}" if mysql.password
|
40
47
|
mysql_config += " --databases #{mysql.databases.to_a.join(' ')}" if mysql.databases
|
41
48
|
mysql_config += " --tables #{mysql.tables.to_a.join(' ')}" if mysql.tables
|
42
49
|
mysql_config += " #{mysql.options}" if mysql.options
|
43
50
|
|
44
51
|
tmpfile = Tempfile.new('mysql.sql')
|
45
|
-
Backup::Main.run("ssh
|
46
|
-
Backup::Main.run("scp
|
47
|
-
Backup::Main.run("ssh
|
52
|
+
Backup::Main.run("ssh #{@ssh_host} 'mysqldump #{mysql_config} > #{tmpfile.path}'") &&
|
53
|
+
Backup::Main.run("scp #{@scp_host}:#{tmpfile.path} '#{target_path}/#{key}.sql'") &&
|
54
|
+
Backup::Main.run("ssh #{@ssh_host} 'rm #{tmpfile.path}'")
|
48
55
|
end
|
49
56
|
end
|
50
57
|
|
51
58
|
def commit_changes
|
52
59
|
Dir.chdir(@backup_path) do
|
53
|
-
Backup::Main.run("
|
54
|
-
Backup::Main.run("
|
60
|
+
Backup::Main.run("git init") unless system("git status")
|
61
|
+
Backup::Main.run("git add .")
|
62
|
+
Backup::Main.run("git commit -am '#{Time.now.strftime("%Y-%m-%d %H:%M")}'")
|
55
63
|
end
|
56
64
|
end
|
57
65
|
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: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jinzhu
|
@@ -84,5 +84,5 @@ signing_key:
|
|
84
84
|
specification_version: 3
|
85
85
|
summary: A tool to backup your servers
|
86
86
|
test_files:
|
87
|
-
- test/test_backupit.rb
|
88
87
|
- test/helper.rb
|
88
|
+
- test/test_backupit.rb
|