itgwiki_mirror 0.0.26.pre → 0.1.0.pre
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/bin/itgwiki_mirror_backup +7 -10
- data/bin/itgwiki_mirror_install_backup +97 -0
- data/lib/itgwiki_mirror/backuper.rb +4 -4
- metadata +16 -5
data/bin/itgwiki_mirror_backup
CHANGED
@@ -4,7 +4,7 @@ require 'itgwiki_mirror'
|
|
4
4
|
require 'itgwiki_mirror/backuper'
|
5
5
|
require 'optparse'
|
6
6
|
|
7
|
-
USAGE = 'Usage: itgwiki_mirror_backup [options] user@host[:port]'
|
7
|
+
USAGE = 'Usage: itgwiki_mirror_backup [options] user@host[:port]:/path/to/mirror'
|
8
8
|
|
9
9
|
def usage
|
10
10
|
puts USAGE
|
@@ -23,7 +23,7 @@ OptionParser.new do |opts|
|
|
23
23
|
options[:db_user] = u
|
24
24
|
end
|
25
25
|
|
26
|
-
opts.on '-p', '--
|
26
|
+
opts.on '-p', '--db-password PASSWORD', 'PASSWORD for mysqldump' do |p|
|
27
27
|
options[:db_pass] = p
|
28
28
|
end
|
29
29
|
|
@@ -35,18 +35,15 @@ OptionParser.new do |opts|
|
|
35
35
|
options[:wiki_root] = w.sub(/\/$/, '') # remove trailing slash
|
36
36
|
end
|
37
37
|
|
38
|
-
opts.on '-t', '--remote-rsync-target TARGET', 'The remote rsync TARGET (i.e. destination directory)' do |t|
|
39
|
-
options[:rsync_target] = t
|
40
|
-
end
|
41
|
-
|
42
38
|
end.parse!
|
43
39
|
|
44
|
-
# set user, host, and
|
40
|
+
# set user, host, port, and mirror target path from ARGV (port is optional)
|
45
41
|
#
|
46
42
|
begin
|
47
|
-
options[:user]
|
48
|
-
options[:host]
|
49
|
-
options[:port]
|
43
|
+
options[:user] = /^(.+)@/.match(ARGV[0])[1]
|
44
|
+
options[:host] = /@([^:]+)/.match(ARGV[0])[1]
|
45
|
+
options[:port] = /:(\d+)/.match(ARGV[0])[1].to_i if /:.*:/.match ARGV[0]
|
46
|
+
options[:rsync] = /:([^:]+$)/.match(ARGV[0])[1]
|
50
47
|
rescue
|
51
48
|
usage
|
52
49
|
exit 1
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'highline/import'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
def usage
|
7
|
+
say "To install #{File.basename __FILE__} you must"
|
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"
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
|
18
|
+
# check that user is (effectively) root?
|
19
|
+
#
|
20
|
+
def check_root
|
21
|
+
unless Process.euid == 0
|
22
|
+
raise "Must be run as root"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# is program prog in path?
|
27
|
+
#
|
28
|
+
def installed? prog
|
29
|
+
bin = `which #{prog}`.chomp
|
30
|
+
File.executable? bin
|
31
|
+
rescue Errno::ENOENT
|
32
|
+
say "You don't seem to have the `which` command in your path."
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
def check_mysqldump
|
37
|
+
unless installed? 'mysqldump'
|
38
|
+
raise "Can't find mysqldump in path"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def check_rsync
|
43
|
+
unless installed? 'rsync'
|
44
|
+
raise "Can't find rsync in path"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def check_cron
|
49
|
+
unless File.directory? '/etc/cron.daily'
|
50
|
+
raise "Can't find /etc/cron.daily"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
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
|
+
|
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
|
+
|
97
|
+
end
|
@@ -30,7 +30,7 @@ module ITGwikiMirror
|
|
30
30
|
|
31
31
|
# rsync target
|
32
32
|
#
|
33
|
-
@
|
33
|
+
@rsync = opts[:rsync]
|
34
34
|
|
35
35
|
# mysqldump temporary file
|
36
36
|
#
|
@@ -139,12 +139,12 @@ module ITGwikiMirror
|
|
139
139
|
|
140
140
|
|
141
141
|
def rsync_mysqldump
|
142
|
-
rsync @dumpfile, "#{@user}@#{@host}:#{@
|
142
|
+
rsync @dumpfile, "#{@user}@#{@host}:#{@rsync}/itgwiki.mysqldump"
|
143
143
|
end
|
144
144
|
|
145
145
|
|
146
146
|
def rsync_wiki_dir
|
147
|
-
rsync @wiki_root, "#{@user}@#{@host}:#{@
|
147
|
+
rsync @wiki_root, "#{@user}@#{@host}:#{@rsync}"
|
148
148
|
end
|
149
149
|
|
150
150
|
|
@@ -156,7 +156,7 @@ module ITGwikiMirror
|
|
156
156
|
|
157
157
|
# just touch a file called "complete" in the mirror target
|
158
158
|
#
|
159
|
-
%x( ssh #{@user}@#{@host} #{port} touch #{@
|
159
|
+
%x( ssh #{@user}@#{@host} #{port} touch #{@rsync}/complete )
|
160
160
|
end
|
161
161
|
end
|
162
162
|
end
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itgwiki_mirror
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0.pre
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Justin Force
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rb-inotify
|
16
|
-
requirement: &
|
16
|
+
requirement: &85082430 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,18 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *85082430
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: highline
|
27
|
+
requirement: &85082130 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *85082130
|
25
36
|
description: ! "\n Use two scripts, itgwiki_mirror_backup and itgwiki_mirror_deploy,
|
26
37
|
to\n maintain a read-only mirror of ITGwiki. itgwiki_mirror_backup runs\n periodically
|
27
38
|
and automatically on the live instance of ITGwiki to create a\n backup and copy
|