Commit 905ad819 authored by egarcia's avatar egarcia

backup now tracks error messages on shell commands

parent 790a73ed
......@@ -5,6 +5,7 @@
# * git
# * wget client (avaliable from the command line)
# * rdiff-backup v1.2.8
# * ruby gems: open3 & pony (sudo gem install open3 pony)
#
# The user executing the rakefile must have:
# * Permissions to administrate svn repositories on LOCAL_REPOSITORY_PATH
......@@ -35,6 +36,9 @@
# All of the above
# rake backup:all
require 'rubygems'
require 'open4'
require 'pony'
require 'rake'
# =========== CUSTOMIZABLE SETTINGS =============
......@@ -79,10 +83,14 @@ REMOTE_REPOSITORY_URLS = {
'production' => 'http://svn.ohwr.org'
}
def title(text, level = 0)
puts
log text, level
puts
end
def log(message, level = 0)
puts ""
puts "#{'==' * level}> #{message}"
puts ""
end
def remote_repository_url(repository)
......@@ -110,12 +118,23 @@ def repository_exists?(repository)
end
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
def init_repository(repository)
log "Initializing repository #{repository}", 2
title "Initializing repository #{repository}", 2
path = File.join(LOCAL_REPOSITORY_PATH, repository)
pre_file_path = "#{path}/hooks/pre-revprop-change"
......@@ -127,7 +146,7 @@ def init_repository(repository)
end
def sync_repository(repository)
log "Syncing repository #{repository}", 2
title "Syncing repository #{repository}", 2
path = File.join(LOCAL_REPOSITORY_PATH, repository)
shell "svnsync sync file://#{path}"
end
......@@ -141,13 +160,13 @@ def git_exists?(repository)
end
def init_git_repository(repository)
log "Initializing git repository #{repository}", 2
title "Initializing git repository #{repository}", 2
path = File.join(LOCAL_GIT_PATH)
shell "cd #{path} && git clone #{repository}"
end
def sync_git_repository(repository)
log "Syncing repository #{repository}", 2
title "Syncing repository #{repository}", 2
path = File.join(LOCAL_GIT_PATH, repository)
shell "cd #{path} && git pull"
end
......@@ -160,7 +179,7 @@ namespace :backup do
desc "Creates initial folders if they don't exist"
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|
shell "mkdir -p #{path}"
end
......@@ -168,10 +187,10 @@ namespace :backup do
desc "Implements the svn repositories backup"
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}"
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")
while (repository = file.gets)
repository.strip!
......@@ -180,13 +199,13 @@ namespace :backup do
end
file.close
end
desc "Implements the git repositories backup"
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}"
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")
while (repository = file.gets)
repository.strip!
......@@ -199,19 +218,19 @@ namespace :backup do
desc "Implements the database backup"
task :db => :prepare_folders do
log "Backing up databases"
title "Backing up databases"
rdiff_get '/var/backup/ohwr/db', LOCAL_DB_PATH
end
desc "Implements the redmine files backup"
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
end
desc "Implements the sympa files backup"
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/list_data', File.join(LOCAL_SYMPA_PATH,'list_data')
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