itgwiki_mirror 0.1.0.pre → 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/itgwiki_mirror_backup +0 -1
- data/bin/itgwiki_mirror_install_backup +59 -53
- data/bin/itgwiki_mirror_install_deploy +127 -0
- data/lib/itgwiki_mirror/backuper.rb +0 -1
- data/lib/itgwiki_mirror.rb +0 -1
- metadata +62 -41
data/bin/itgwiki_mirror_backup
CHANGED
@@ -40,7 +40,6 @@ end.parse!
|
|
40
40
|
# set user, host, port, and mirror target path from ARGV (port is optional)
|
41
41
|
#
|
42
42
|
begin
|
43
|
-
options[:user] = /^(.+)@/.match(ARGV[0])[1]
|
44
43
|
options[:host] = /@([^:]+)/.match(ARGV[0])[1]
|
45
44
|
options[:port] = /:(\d+)/.match(ARGV[0])[1].to_i if /:.*:/.match ARGV[0]
|
46
45
|
options[:rsync] = /:([^:]+$)/.match(ARGV[0])[1]
|
@@ -3,15 +3,19 @@
|
|
3
3
|
require 'highline/import'
|
4
4
|
require 'fileutils'
|
5
5
|
|
6
|
+
USAGE = <<-EOF
|
7
|
+
To install #{File.basename __FILE__} you must
|
8
|
+
1. Be root.
|
9
|
+
2. Have these commands:
|
10
|
+
a. which
|
11
|
+
b. mysqldump
|
12
|
+
c. rsync
|
13
|
+
3. Have ISC Cron-style /etc/cron.daily folder.
|
14
|
+
4. Answer all prompts.
|
15
|
+
EOF
|
16
|
+
|
6
17
|
def usage
|
7
|
-
say
|
8
|
-
say " 1. Be root"
|
9
|
-
say " 2. Have these commands:"
|
10
|
-
say " a. which"
|
11
|
-
say " b. mysqldump"
|
12
|
-
say " c. rsync"
|
13
|
-
say " 3. Have ISC Cron-style /etc/cron.daily folder"
|
14
|
-
say " 4. Answer all prompts"
|
18
|
+
say USAGE
|
15
19
|
exit 1
|
16
20
|
end
|
17
21
|
|
@@ -19,7 +23,7 @@ end
|
|
19
23
|
#
|
20
24
|
def check_root
|
21
25
|
unless Process.euid == 0
|
22
|
-
raise "Must be run as root"
|
26
|
+
raise "Must be run as root."
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
@@ -35,63 +39,65 @@ end
|
|
35
39
|
|
36
40
|
def check_mysqldump
|
37
41
|
unless installed? 'mysqldump'
|
38
|
-
raise "Can't find mysqldump in path"
|
42
|
+
raise "Can't find mysqldump in path."
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
42
46
|
def check_rsync
|
43
47
|
unless installed? 'rsync'
|
44
|
-
raise "Can't find rsync in path"
|
48
|
+
raise "Can't find rsync in path."
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
48
52
|
def check_cron
|
49
53
|
unless File.directory? '/etc/cron.daily'
|
50
|
-
raise "Can't find /etc/cron.daily"
|
54
|
+
raise "Can't find /etc/cron.daily."
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
54
|
-
if __FILE__ == $0
|
55
|
-
|
56
|
-
# get installation directory
|
57
|
-
#
|
58
|
-
dir = File.absolute_path "#{File.dirname __FILE__}/.."
|
59
|
-
|
60
|
-
# check requirements
|
61
|
-
#
|
62
|
-
begin
|
63
|
-
#check_root
|
64
|
-
check_mysqldump
|
65
|
-
check_rsync
|
66
|
-
check_cron
|
67
|
-
rescue Exception => e
|
68
|
-
puts e.message
|
69
|
-
usage
|
70
|
-
end
|
71
58
|
|
72
|
-
# prompt for settings
|
73
|
-
#
|
74
|
-
dbname = ask "Name of the MediaWiki MySQL database (such as wikidb)?"
|
75
|
-
dbuser = ask "Username for read access on #{dbname}?"
|
76
|
-
dbpass = ask("Password for read access on #{dbname}?") { |p| p.echo = false }
|
77
|
-
wiki = ask "Full path to MediaWiki root (e.g. /var/www/w)?"
|
78
|
-
rsync = ask "rsync user@host:port:/path/to/mirror string (port is optional)?"
|
79
|
-
|
80
|
-
user = /^(.+)@/.match(rsync)[1]
|
81
|
-
|
82
|
-
# set up cron job
|
83
|
-
#
|
84
|
-
begin
|
85
|
-
bin = File.absolute_path "#{dir}/bin/itgwiki_mirror_backup"
|
86
|
-
command = "sudo -u#{user} #{bin} -u#{dbuser} -p#{dbpass} -d#{dbname} -w#{wiki} #{rsync}"
|
87
|
-
File.open '/etc/cron.daily/itgwiki_mirror_backup', 'w', 0700 do |f|
|
88
|
-
f.write "#!/bin/sh\n"
|
89
|
-
f.write command
|
90
|
-
end
|
91
|
-
rescue Exception => e
|
92
|
-
puts "Couldn't set up cron job."
|
93
|
-
puts e.message
|
94
|
-
exit 2
|
95
|
-
end
|
96
59
|
|
60
|
+
|
61
|
+
#
|
62
|
+
# main
|
63
|
+
#
|
64
|
+
|
65
|
+
# get installation directory
|
66
|
+
#
|
67
|
+
dir = File.expand_path "#{File.dirname __FILE__}/.."
|
68
|
+
|
69
|
+
# check requirements
|
70
|
+
#
|
71
|
+
begin
|
72
|
+
#check_root
|
73
|
+
check_mysqldump
|
74
|
+
check_rsync
|
75
|
+
check_cron
|
76
|
+
rescue Exception => e
|
77
|
+
puts e.message
|
78
|
+
usage
|
79
|
+
end
|
80
|
+
|
81
|
+
# prompt for settings
|
82
|
+
#
|
83
|
+
user = ask "Username of the account that will run the backup task?"
|
84
|
+
dbname = ask "Name of the MediaWiki MySQL database (such as wikidb)?"
|
85
|
+
dbuser = ask "Username for read access on #{dbname}?"
|
86
|
+
dbpass = ask("Password for read access on #{dbname}?") { |p| p.echo = false }
|
87
|
+
wiki = ask "Full path to MediaWiki root (e.g. /var/www/w)?"
|
88
|
+
rsync = ask "rsync user@host:port:/path/to/mirror string (port is optional)?"
|
89
|
+
|
90
|
+
# set up cron job
|
91
|
+
#
|
92
|
+
begin
|
93
|
+
bin = `which itgwiki_mirror_backup`.chomp
|
94
|
+
command = "sudo -u#{user} #{bin} -u#{dbuser} -p#{dbpass} -d#{dbname} -w#{wiki} #{rsync}"
|
95
|
+
File.open '/etc/cron.daily/itgwiki_mirror_backup', 'w', 0700 do |f|
|
96
|
+
f.puts "#!/bin/sh"
|
97
|
+
f.puts command
|
98
|
+
end
|
99
|
+
rescue Exception => e
|
100
|
+
puts "Couldn't set up cron job."
|
101
|
+
puts e.message
|
102
|
+
exit 2
|
97
103
|
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'highline/import'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
UPSTART_TEMPLATE = <<-EOF
|
7
|
+
# itgwiki_mirror_deploy - watch the appropriate directory and deploy ITGwiki backups as needed
|
8
|
+
|
9
|
+
start on startup
|
10
|
+
stop on shutdown
|
11
|
+
|
12
|
+
respawn
|
13
|
+
|
14
|
+
EOF
|
15
|
+
|
16
|
+
USAGE = <<-EOF
|
17
|
+
To install #{File.basename __FILE__} you must
|
18
|
+
1. Be root.
|
19
|
+
2. Have these commands:
|
20
|
+
a. which
|
21
|
+
b. mysql
|
22
|
+
c. rsync
|
23
|
+
3. Have Upstart installed.
|
24
|
+
4. Have MySQL installed, the wiki database created, and a user account with
|
25
|
+
all privileges granted for database creation/deletion/updating.
|
26
|
+
5. Answer all prompts.
|
27
|
+
EOF
|
28
|
+
|
29
|
+
def usage
|
30
|
+
say USAGE
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
# check that user is (effectively) root?
|
35
|
+
#
|
36
|
+
def check_root
|
37
|
+
unless Process.euid == 0
|
38
|
+
raise "Must be run as root"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# is program prog in path?
|
43
|
+
#
|
44
|
+
def installed? prog
|
45
|
+
bin = `which #{prog}`.chomp
|
46
|
+
File.executable? bin
|
47
|
+
rescue Errno::ENOENT
|
48
|
+
say "You don't seem to have the `which` command in your path."
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
52
|
+
def check_mysql
|
53
|
+
unless installed? 'mysql'
|
54
|
+
raise "Can't find mysql in path."
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_rsync
|
59
|
+
unless installed? 'rsync'
|
60
|
+
raise "Can't find rsync in path."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def check_upstart
|
65
|
+
unless `init --version`.match /upstart/
|
66
|
+
raise "It looks like Upstart isn't installed."
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
#
|
74
|
+
# main
|
75
|
+
#
|
76
|
+
|
77
|
+
# get installation directory
|
78
|
+
#
|
79
|
+
dir = File.expand_path "#{File.dirname __FILE__}/.."
|
80
|
+
|
81
|
+
# check requirements
|
82
|
+
#
|
83
|
+
begin
|
84
|
+
#check_root
|
85
|
+
check_mysql
|
86
|
+
check_rsync
|
87
|
+
check_upstart
|
88
|
+
rescue Exception => e
|
89
|
+
puts e.message
|
90
|
+
usage
|
91
|
+
end
|
92
|
+
|
93
|
+
# prompt for settings
|
94
|
+
#
|
95
|
+
user = ask "Username of the account that will run the deploy task?"
|
96
|
+
dbname = ask "Name of the MediaWiki MySQL database (such as wikidb)?"
|
97
|
+
dbuser = ask "Username for import access on #{dbname}?"
|
98
|
+
dbpass = ask("Password for import access on #{dbname}?") { |p| p.echo = false }
|
99
|
+
wiki = ask "Full path to MediaWiki root (e.g. /var/www/w)?"
|
100
|
+
mirror = ask "Path to the mirror target directory (where the backup script put its files such as /var/mirror)?"
|
101
|
+
|
102
|
+
# make directories and and set ownership
|
103
|
+
#
|
104
|
+
# XXX initial "complete" file must be present for deploy daemon to operate
|
105
|
+
#
|
106
|
+
FileUtils.mkdir_p mirror
|
107
|
+
FileUtils.touch "#{mirror}/complete"
|
108
|
+
FileUtils.chown_R user, user, mirror
|
109
|
+
|
110
|
+
FileUtils.mkdir_p wiki
|
111
|
+
FileUtils.chown_R user, user, wiki
|
112
|
+
|
113
|
+
|
114
|
+
# set up cron job
|
115
|
+
#
|
116
|
+
begin
|
117
|
+
bin = `which itgwiki_mirror_deploy`.chomp
|
118
|
+
command = "exec sudo -u#{user} #{bin} -d#{dbname} -u#{dbuser} -p#{dbpass} -w#{wiki} -m#{mirror}"
|
119
|
+
File.open '/etc/init/itgwiki_mirror_deploy.conf', 'w', 0600 do |f|
|
120
|
+
f.puts UPSTART_TEMPLATE
|
121
|
+
f.puts command
|
122
|
+
end
|
123
|
+
rescue Exception => e
|
124
|
+
puts "Couldn't set up Upstart configuration."
|
125
|
+
puts e.message
|
126
|
+
exit 2
|
127
|
+
end
|
data/lib/itgwiki_mirror.rb
CHANGED
metadata
CHANGED
@@ -1,53 +1,63 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: itgwiki_mirror
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 62065864
|
5
5
|
prerelease: 6
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
- pre
|
11
|
+
version: 1.0.0.pre
|
6
12
|
platform: ruby
|
7
|
-
authors:
|
13
|
+
authors:
|
8
14
|
- Justin Force
|
9
15
|
autorequire:
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
18
|
+
|
19
|
+
date: 2012-01-24 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
15
22
|
name: rb-inotify
|
16
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
25
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
22
33
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
26
36
|
name: highline
|
27
|
-
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
33
47
|
type: :runtime
|
34
|
-
|
35
|
-
|
36
|
-
description: ! "\n Use two scripts, itgwiki_mirror_backup and itgwiki_mirror_deploy,
|
37
|
-
to\n maintain a read-only mirror of ITGwiki. itgwiki_mirror_backup runs\n periodically
|
38
|
-
and automatically on the live instance of ITGwiki to create a\n backup and copy
|
39
|
-
it to the mirror. itgwiki_mirror_deploy runs on the mirror\n and is triggered
|
40
|
-
by itgwiki_mirror_backup, imports and adjusts the backup\n to be read-only, then
|
41
|
-
deploys it on the mirror server. Requires rsync and\n mysqldump.\n "
|
48
|
+
version_requirements: *id002
|
49
|
+
description: "\n Use two scripts, itgwiki_mirror_backup and itgwiki_mirror_deploy, to\n maintain a read-only mirror of ITGwiki. itgwiki_mirror_backup runs\n periodically and automatically on the live instance of ITGwiki to create a\n backup and copy it to the mirror. itgwiki_mirror_deploy runs on the mirror\n and is triggered by itgwiki_mirror_backup, imports and adjusts the backup\n to be read-only, then deploys it on the mirror server. Requires rsync and\n mysqldump.\n "
|
42
50
|
email: justin.force@gmail.com
|
43
|
-
executables:
|
51
|
+
executables:
|
44
52
|
- itgwiki_mirror_backup
|
45
53
|
- itgwiki_mirror_deploy
|
46
54
|
- itgwiki_mirror_install_backup
|
47
55
|
- itgwiki_mirror_install_deploy
|
48
56
|
extensions: []
|
57
|
+
|
49
58
|
extra_rdoc_files: []
|
50
|
-
|
59
|
+
|
60
|
+
files:
|
51
61
|
- lib/itgwiki_mirror.rb
|
52
62
|
- lib/itgwiki_mirror/backuper.rb
|
53
63
|
- lib/itgwiki_mirror/deployer.rb
|
@@ -59,23 +69,33 @@ files:
|
|
59
69
|
- bin/itgwiki_mirror_install_deploy
|
60
70
|
homepage: https://github.com/sidewaysmilk/itgwiki_mirror
|
61
71
|
licenses: []
|
72
|
+
|
62
73
|
post_install_message:
|
63
74
|
rdoc_options: []
|
64
|
-
|
75
|
+
|
76
|
+
require_paths:
|
65
77
|
- lib
|
66
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
79
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
88
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
89
|
+
requirements:
|
90
|
+
- - ">"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 25
|
93
|
+
segments:
|
94
|
+
- 1
|
95
|
+
- 3
|
96
|
+
- 1
|
77
97
|
version: 1.3.1
|
78
|
-
requirements:
|
98
|
+
requirements:
|
79
99
|
- mysqldump
|
80
100
|
- rsync
|
81
101
|
- sed
|
@@ -85,3 +105,4 @@ signing_key:
|
|
85
105
|
specification_version: 3
|
86
106
|
summary: Maintain a read-only mirror of ITGwiki
|
87
107
|
test_files: []
|
108
|
+
|