production-sync 0.0.1 → 0.1.0
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/Readme +3 -1
- data/bin/production-sync +54 -2
- data/lib/production-sync/read_config.rb +23 -0
- data/lib/production-sync/version.rb +3 -0
- data/lib/production-sync.rb +49 -78
- metadata +15 -4
data/Readme
CHANGED
data/bin/production-sync
CHANGED
@@ -2,6 +2,58 @@
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'production-sync'
|
5
|
+
require 'optparse'
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
#Defaults
|
8
|
+
show_command = false
|
9
|
+
|
10
|
+
ARGV.options do |opts|
|
11
|
+
|
12
|
+
#Set the config file
|
13
|
+
opts.on("-f /etc/rmybackup.conf","--config-file /etc/rmybackup.conf","Set Config File",String) do |o|
|
14
|
+
ProductionSync.config(o)
|
15
|
+
end
|
16
|
+
|
17
|
+
#Version
|
18
|
+
opts.on("-v","--version","Outputs version") {
|
19
|
+
puts "Production Sync - #{ProductionSync::VERSION}"
|
20
|
+
exit
|
21
|
+
}
|
22
|
+
|
23
|
+
opts.on('-s',"--show-command","Shows the command to run",String) {
|
24
|
+
show_command = true
|
25
|
+
}
|
26
|
+
|
27
|
+
opts.on('-l',"--list","Lists sites") {
|
28
|
+
ProductionSync.config.each do |name,value|
|
29
|
+
if name != "global"
|
30
|
+
puts "#{name}:\n"
|
31
|
+
value.each { |k,v| puts "\s\s#{k}: #{v}\n" }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
exit
|
35
|
+
}
|
36
|
+
|
37
|
+
opts.parse!
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
#Pull the site name from the remaining ARGV
|
42
|
+
site_name = ARGV.shift
|
43
|
+
|
44
|
+
#Check to make sure site name is defined
|
45
|
+
if not site_name
|
46
|
+
puts 'Please provide a site name'
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
#Instantiate the base
|
52
|
+
prod = ProductionSync::Base.new(site_name)
|
53
|
+
|
54
|
+
#See if we're showing or running the command
|
55
|
+
if show_command
|
56
|
+
puts prod.command
|
57
|
+
else
|
58
|
+
prod.run_command
|
59
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#Read the config File
|
2
|
+
module ProductionSync
|
3
|
+
def self.config(file=false)
|
4
|
+
|
5
|
+
if file and not File.exists?(File.expand_path(file))
|
6
|
+
puts "Can't read config file"
|
7
|
+
exit
|
8
|
+
end
|
9
|
+
|
10
|
+
#Try the default locations if file isn't set
|
11
|
+
if not file
|
12
|
+
if File.exists? File.expand_path('~/.production-sync.yml')
|
13
|
+
file = "~/.production-sync.yml"
|
14
|
+
else
|
15
|
+
file = '/etc/production-sync.yml'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
config_file = File.expand_path(file)
|
20
|
+
return false if not File.exist? config_file
|
21
|
+
@options ||= YAML::load(File.open(config_file))
|
22
|
+
end
|
23
|
+
end
|
data/lib/production-sync.rb
CHANGED
@@ -1,90 +1,61 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
1
|
require 'optparse'
|
4
2
|
require 'ostruct'
|
5
3
|
require 'yaml'
|
6
4
|
require 'date'
|
7
|
-
require 'rdoc/usage'
|
8
|
-
|
9
|
-
class ProductionSync
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
puts e
|
55
|
-
puts opts
|
56
|
-
exit
|
6
|
+
require File.expand_path('../production-sync/read_config', __FILE__)
|
7
|
+
require File.expand_path('../production-sync/version', __FILE__)
|
8
|
+
|
9
|
+
|
10
|
+
module ProductionSync
|
11
|
+
|
12
|
+
class Base
|
13
|
+
|
14
|
+
attr_reader :site, :config, :rsync
|
15
|
+
|
16
|
+
def initialize(site_name)
|
17
|
+
@config = ProductionSync.config
|
18
|
+
@site = @config[site_name] || false
|
19
|
+
|
20
|
+
if not @site
|
21
|
+
puts "No site found - #{site_name}"
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
25
|
+
@rsync = "/usr/bin/rsync"
|
26
|
+
|
27
|
+
#See if we have any global options we need to read
|
28
|
+
if @config['global']
|
29
|
+
@rsync = @config['global']['rsync'] if @config['global']['rsync']
|
30
|
+
end
|
31
|
+
|
32
|
+
#Check to see if we can find rsync
|
33
|
+
if not File.exists?(@rsync)
|
34
|
+
puts "Can't find rsync at: #{@rsync}"
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
|
38
|
+
#Sanitize inputs
|
39
|
+
@site['source'] = File.expand_path(@site['source'])
|
40
|
+
if not File.exists?(@site['source'])
|
41
|
+
puts "Source path #{@site['source']} doesn't exist."
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
|
45
|
+
#Sanitize the / at the end of destination, we don't check to see if this exists
|
46
|
+
@site['destination'] += "/" if @site['destination'][-1,1] != "/"
|
47
|
+
|
48
|
+
|
57
49
|
end
|
58
|
-
true #Return true if the parser was successful
|
59
|
-
end
|
60
|
-
|
61
|
-
def parse_file
|
62
50
|
|
63
|
-
#
|
64
|
-
|
65
|
-
|
66
|
-
config_file = YAML::load(File.open(File.expand_path(@options.file)))
|
67
|
-
#Check global settings
|
68
|
-
if config_file['global']
|
69
|
-
@options.rsync = config_file['global']['rsync'] if config_file['global']['rsync']
|
51
|
+
#Define the command to run
|
52
|
+
def command
|
53
|
+
@command = "#{@rsync} -rv --delete --exclude '.git' --exclude '.svn' --exclude '.gitignore' --exclude '.rsyncignore' --exclude-from #{@site['source'] + "/.rsyncignore"} #{File.expand_path(@site['source']) + "/"} #{@site['username']}@#{@site['server']}:#{@site['destination']}"
|
70
54
|
end
|
71
55
|
|
72
|
-
|
73
|
-
|
74
|
-
|
56
|
+
#Run the command
|
57
|
+
def run_command
|
58
|
+
exec command
|
75
59
|
end
|
76
|
-
@options.debug = true if config_file[@options.site_name]['debug']
|
77
|
-
@options.destination = config_file[@options.site_name]['destination'][-1,1] == "/" ? config_file[@options.site_name]['destination'] : config_file[@options.site_name]['destination'] + "/"
|
78
|
-
@options.source = config_file[@options.site_name]['source'][-1,1] == "/" ? config_file[@options.site_name]['source'] : config_file[@options.site_name]['source'] + "/"
|
79
|
-
@options.user = config_file[@options.site_name]['username']
|
80
|
-
@options.server = config_file[@options.site_name]['server']
|
81
|
-
rescue
|
82
|
-
puts "Can't read configuration file - #{File.expand_path @options.file}"
|
83
|
-
exit
|
84
60
|
end
|
85
|
-
|
86
61
|
end
|
87
|
-
|
88
|
-
|
89
|
-
#Basic rsync script that will update the site
|
90
|
-
# rsync -avz --delete --exclude '.git' --exclude '.gitignore' --exclude-from '/Users/bshelton/copyexperts/.gitignore' /Users/bshelton/copyexperts/ /Users/bshelton/cclone/
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: production-sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Bryan Shelton
|
@@ -24,6 +29,8 @@ extra_rdoc_files: []
|
|
24
29
|
files:
|
25
30
|
- bin/production-sync
|
26
31
|
- lib/production-sync.rb
|
32
|
+
- lib/production-sync/read_config.rb
|
33
|
+
- lib/production-sync/version.rb
|
27
34
|
- Readme
|
28
35
|
has_rdoc: true
|
29
36
|
homepage: http://github.com/bshelton229/production-sync
|
@@ -35,21 +42,25 @@ rdoc_options: []
|
|
35
42
|
require_paths:
|
36
43
|
- lib
|
37
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
38
46
|
requirements:
|
39
47
|
- - ">="
|
40
48
|
- !ruby/object:Gem::Version
|
49
|
+
segments:
|
50
|
+
- 0
|
41
51
|
version: "0"
|
42
|
-
version:
|
43
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
44
54
|
requirements:
|
45
55
|
- - ">="
|
46
56
|
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
47
59
|
version: "0"
|
48
|
-
version:
|
49
60
|
requirements: []
|
50
61
|
|
51
62
|
rubyforge_project:
|
52
|
-
rubygems_version: 1.3.
|
63
|
+
rubygems_version: 1.3.7
|
53
64
|
signing_key:
|
54
65
|
specification_version: 3
|
55
66
|
summary: Git Sync
|