Commit 905ad819 authored by egarcia's avatar egarcia

backup now tracks error messages on shell commands

parent 790a73ed
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# * git # * git
# * wget client (avaliable from the command line) # * wget client (avaliable from the command line)
# * rdiff-backup v1.2.8 # * rdiff-backup v1.2.8
# * ruby gems: open3 & pony (sudo gem install open3 pony)
# #
# The user executing the rakefile must have: # The user executing the rakefile must have:
# * Permissions to administrate svn repositories on LOCAL_REPOSITORY_PATH # * Permissions to administrate svn repositories on LOCAL_REPOSITORY_PATH
...@@ -35,6 +36,9 @@ ...@@ -35,6 +36,9 @@
# All of the above # All of the above
# rake backup:all # rake backup:all
require 'rubygems'
require 'open4'
require 'pony'
require 'rake' require 'rake'
# =========== CUSTOMIZABLE SETTINGS ============= # =========== CUSTOMIZABLE SETTINGS =============
...@@ -79,10 +83,14 @@ REMOTE_REPOSITORY_URLS = { ...@@ -79,10 +83,14 @@ REMOTE_REPOSITORY_URLS = {
'production' => 'http://svn.ohwr.org' 'production' => 'http://svn.ohwr.org'
} }
def title(text, level = 0)
puts
log text, level
puts
end
def log(message, level = 0) def log(message, level = 0)
puts ""
puts "#{'==' * level}> #{message}" puts "#{'==' * level}> #{message}"
puts ""
end end
def remote_repository_url(repository) def remote_repository_url(repository)
...@@ -110,12 +118,23 @@ def repository_exists?(repository) ...@@ -110,12 +118,23 @@ def repository_exists?(repository)
end end
def shell(command) def shell(command)
sh command
err = StringIO.new
status = Open4::popen4(command) do |pid, stdin, stdout, stderr|
err << stderr.read.strip
end
if status.exitstatus == 0 then
log "#{command} - ok"
else
fail("Command failed(#{status.exitstatus}) - #{command}:\n#{err.string}")
end
end end
def init_repository(repository) def init_repository(repository)
log "Initializing repository #{repository}", 2 title "Initializing repository #{repository}", 2
path = File.join(LOCAL_REPOSITORY_PATH, repository) path = File.join(LOCAL_REPOSITORY_PATH, repository)
pre_file_path = "#{path}/hooks/pre-revprop-change" pre_file_path = "#{path}/hooks/pre-revprop-change"
...@@ -127,7 +146,7 @@ def init_repository(repository) ...@@ -127,7 +146,7 @@ def init_repository(repository)
end end
def sync_repository(repository) def sync_repository(repository)
log "Syncing repository #{repository}", 2 title "Syncing repository #{repository}", 2
path = File.join(LOCAL_REPOSITORY_PATH, repository) path = File.join(LOCAL_REPOSITORY_PATH, repository)
shell "svnsync sync file://#{path}" shell "svnsync sync file://#{path}"
end end
...@@ -141,13 +160,13 @@ def git_exists?(repository) ...@@ -141,13 +160,13 @@ def git_exists?(repository)
end end
def init_git_repository(repository) def init_git_repository(repository)
log "Initializing git repository #{repository}", 2 title "Initializing git repository #{repository}", 2
path = File.join(LOCAL_GIT_PATH) path = File.join(LOCAL_GIT_PATH)
shell "cd #{path} && git clone #{repository}" shell "cd #{path} && git clone #{repository}"
end end
def sync_git_repository(repository) def sync_git_repository(repository)
log "Syncing repository #{repository}", 2 title "Syncing repository #{repository}", 2
path = File.join(LOCAL_GIT_PATH, repository) path = File.join(LOCAL_GIT_PATH, repository)
shell "cd #{path} && git pull" shell "cd #{path} && git pull"
end end
...@@ -160,7 +179,7 @@ namespace :backup do ...@@ -160,7 +179,7 @@ namespace :backup do
desc "Creates initial folders if they don't exist" desc "Creates initial folders if they don't exist"
task :prepare_folders do task :prepare_folders do
log "Preparing local folders" title "Preparing local folders"
[LOCAL_REPOSITORY_PATH, LOCAL_GIT_PATH, LOCAL_DB_PATH, LOCAL_FILES_PATH, File.join(LOCAL_SYMPA_PATH,'arc'), File.join(LOCAL_SYMPA_PATH,'list_data')].each do |path| [LOCAL_REPOSITORY_PATH, LOCAL_GIT_PATH, LOCAL_DB_PATH, LOCAL_FILES_PATH, File.join(LOCAL_SYMPA_PATH,'arc'), File.join(LOCAL_SYMPA_PATH,'list_data')].each do |path|
shell "mkdir -p #{path}" shell "mkdir -p #{path}"
end end
...@@ -168,10 +187,10 @@ namespace :backup do ...@@ -168,10 +187,10 @@ namespace :backup do
desc "Implements the svn repositories backup" desc "Implements the svn repositories backup"
task :svn => :prepare_folders do task :svn => :prepare_folders do
log "Getting svn list from #{server_url}" title "Getting svn list from #{server_url}"
shell "wget -m -nd #{server_url}/svn_list.txt -O #{LOCAL_SVNLIST_PATH}" shell "wget -m -nd #{server_url}/svn_list.txt -O #{LOCAL_SVNLIST_PATH}"
log "Initializing new SVN repositories and updating existing ones" title "Initializing new SVN repositories and updating existing ones"
file = File.new(LOCAL_SVNLIST_PATH, "r") file = File.new(LOCAL_SVNLIST_PATH, "r")
while (repository = file.gets) while (repository = file.gets)
repository.strip! repository.strip!
...@@ -180,13 +199,13 @@ namespace :backup do ...@@ -180,13 +199,13 @@ namespace :backup do
end end
file.close file.close
end end
desc "Implements the git repositories backup" desc "Implements the git repositories backup"
task :git => :prepare_folders do task :git => :prepare_folders do
log "Getting git list from #{server_url}" title "Getting git list from #{server_url}"
shell "wget -m -nd #{server_url}/git_list.txt -O #{LOCAL_GITLIST_PATH}" shell "wget -m -nd #{server_url}/git_list.txt -O #{LOCAL_GITLIST_PATH}"
log "Initializing new GIT repositories and updating existing ones" title "Initializing new GIT repositories and updating existing ones"
file = File.new(LOCAL_GITLIST_PATH, "r") file = File.new(LOCAL_GITLIST_PATH, "r")
while (repository = file.gets) while (repository = file.gets)
repository.strip! repository.strip!
...@@ -199,19 +218,19 @@ namespace :backup do ...@@ -199,19 +218,19 @@ namespace :backup do
desc "Implements the database backup" desc "Implements the database backup"
task :db => :prepare_folders do task :db => :prepare_folders do
log "Backing up databases" title "Backing up databases"
rdiff_get '/var/backup/ohwr/db', LOCAL_DB_PATH rdiff_get '/var/backup/ohwr/db', LOCAL_DB_PATH
end end
desc "Implements the redmine files backup" desc "Implements the redmine files backup"
task :files => :prepare_folders do task :files => :prepare_folders do
log "Backing up redmine files" title "Backing up redmine files"
rdiff_get '/var/rails/ohwr/shared/files', LOCAL_FILES_PATH rdiff_get '/var/rails/ohwr/shared/files', LOCAL_FILES_PATH
end end
desc "Implements the sympa files backup" desc "Implements the sympa files backup"
task :sympa => :prepare_folders do task :sympa => :prepare_folders do
log "Backing up sympa files & config" title "Backing up sympa files & config"
rdiff_get '/home/sympa/arc', File.join(LOCAL_SYMPA_PATH,'arc') rdiff_get '/home/sympa/arc', File.join(LOCAL_SYMPA_PATH,'arc')
rdiff_get '/home/sympa/list_data', File.join(LOCAL_SYMPA_PATH,'list_data') rdiff_get '/home/sympa/list_data', File.join(LOCAL_SYMPA_PATH,'list_data')
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment