summaryrefslogtreecommitdiff
path: root/lib/tasks/backup.rake
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-02-26 09:22:10 -0500
committerPeter Kozak <spag@golwen.net>2013-02-26 09:22:10 -0500
commiteb0b73618dac66d5f9e1c4127af156886d362315 (patch)
tree0fdaaa0c26ae3365a21f4d02719533151db5e111 /lib/tasks/backup.rake
parent0a976c6b463288df4a9516bbd08f6232a37d427c (diff)
parent36919fb419a40688daa97e36734f579488cb56e2 (diff)
Merge branch 'develop' of github.com:amooma/GS5 into develop
Diffstat (limited to 'lib/tasks/backup.rake')
-rw-r--r--lib/tasks/backup.rake37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake
index c285e1f..d12bf5e 100644
--- a/lib/tasks/backup.rake
+++ b/lib/tasks/backup.rake
@@ -3,4 +3,41 @@ namespace :backup do
task :daily_backup => :environment do
# This would be the daily backup.
end
+
+ desc "Restore the system"
+ task :restore => :environment do
+ # This task takes the first RestoreJob to restore the system.
+ #
+ if RestoreJob.where(:state => 'new').any?
+ restore_job = RestoreJob.where(:state => 'new').order(:created_at).last
+ tmp_dir = "/tmp/gs5_restore_directory"
+ FileUtils.rm_rf tmp_dir
+ FileUtils.mkdir_p tmp_dir
+ system "cd #{tmp_dir} && tar xzf #{restore_job.backup_file.path}"
+ system "cd /tmp/gs5_restore_directory/*/ && tar xf GS5.tar && rm GS5.tar"
+
+ # Restore faxes
+ #
+ system "cd / && tar xzfP /tmp/gs5_restore_directory/*/GS5/archives/faxes.tar.gz"
+
+ # Restore voicemails
+ #
+ # system "cd / && tar xzfP /tmp/gs5_restore_directory/*/GS5/archives/voicemails.tar.gz"
+
+ # Restore the database
+ #
+ system_odbc_ini_file = '/var/lib/freeswitch/.odbc.ini'
+ system_odbc_configuration = IniFile.load(system_odbc_ini_file)
+ database = system_odbc_configuration['gemeinschaft']['DATABASE']
+ db_user = system_odbc_configuration['gemeinschaft']['USER']
+ db_password = system_odbc_configuration['gemeinschaft']['PASSWORD']
+
+ system "gunzip < /tmp/gs5_restore_directory/*/GS5/databases/MySQL/gemeinschaft.sql.gz | mysql -u #{db_user} -p#{db_password} #{database}"
+
+ FileUtils.rm_rf tmp_dir
+
+ system "cd /opt/gemeinschaft && rake db:migrate"
+ end
+ end
+
end \ No newline at end of file