Class: ITGwikiMirror::Backuper

Inherits:
Object
  • Object
show all
Defined in:
lib/itgwiki_mirror/backuper.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Backuper

Returns a new instance of Backuper.



9
10
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
# File 'lib/itgwiki_mirror/backuper.rb', line 9

def initialize opts

  # verbose mode
  #
  @verbose = opts[:verbose]

  # mysql options
  #
  @db_user = opts[:db_user]
  @db_pass = opts[:db_pass]
  @db_name = opts[:db_name]

  # ssh options
  #
  @user = opts[:user]
  @host = opts[:host]
  @port = opts[:port]

  # MediaWiki root
  #
  @wiki_root = opts[:wiki_root]

  # rsync target
  #
  @rsync = opts[:rsync]
  
  # mysqldump temporary file
  #
  @dumpfile = Tempfile.new('itgwiki_mirror_mysqldump').path
end

Instance Method Details

#backupObject

Perform the backup

Dump the database, rsync the database, the wiki directory, and any other specified files (configuration, etc.) to the remote host. If any of these steps fails, stop and return false. If they’re all successful, return true.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/itgwiki_mirror/backuper.rb', line 49

def backup

  #
  # FIXME I repeat the $?.success? block over and over. Probably extract to a method.
  #

  # print immediately so we get the nice 'msg...' -> 'msg...OK' transition
  # instead of waiting until the jobs is finished to print the message.
  #
  STDOUT.sync = true


  print 'mysqldump...' if @verbose
  mysqldump
  if $?.success?
    puts 'OK' if @verbose
  else
    STDERR.puts 'mysqldump failed'
    return false
  end

  print 'rsyncing mysqldump...' if @verbose
  rsync_mysqldump
  if $?.success?
    puts 'OK' if @verbose
  else
    STDERR.puts 'rsyncing mysqldump failed'
    return false
  end


  print 'rsyncing wiki directory...' if @verbose
  rsync_wiki_dir
  if $?.success?
    puts 'OK' if @verbose
  else
    STDERR.puts 'rsyncing wiki directory failed'
    return false
  end

  print 'Notifying mirror that backup is complete...' if @verbose
  notify_complete
  if $?.success?
    puts 'OK' if @verbose
  else
    STDERR.puts 'Notifying mirror failed'
    return false
  end

  return true
end