summaryrefslogtreecommitdiff
path: root/lib/tasks
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-27 12:22:29 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-27 12:22:29 +0100
commit67c1a0a951403a546250ea860a3e3d199cae2fce (patch)
treef86ec6cedf081a1a57005eca1661e9bead34e4de /lib/tasks
parent5d8ce5f4775ac8bc5f523964e6e36f63ff3c4683 (diff)
parent211f558a86ae30cdd5b392ab1376e1393f97e22c (diff)
Merge branch 'develop'5.1-beta6
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/backup.rake52
-rw-r--r--lib/tasks/send_fax_notifications.rake2
2 files changed, 53 insertions, 1 deletions
diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake
index c285e1f..21b0fac 100644
--- a/lib/tasks/backup.rake
+++ b/lib/tasks/backup.rake
@@ -3,4 +3,56 @@ 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} && sudo /bin/tar xzf #{restore_job.backup_file.path}"
+ restore_directory = Dir.glob("/tmp/gs5_restore_directory/*").first
+ system "cd #{restore_directory} && sudo /bin/tar xf GS5.tar && rm GS5.tar"
+
+ # Restore faxes
+ #
+ system "cd / && sudo /bin/tar xzfP #{restore_directory}/GS5/archives/faxes.tar.gz"
+
+ # Restore voicemails
+ #
+ system "cd / && sudo /bin/tar xzfP #{restore_directory}/GS5/archives/voicemails.tar.gz"
+
+ # Delete the archive tar.gz to get more air to breathe
+ #
+ FileUtils.mkdir_p "#{restore_directory}/GS5/archives"
+
+ # 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 < #{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"
+
+ # Rebuild the thumbnails
+ #
+ FaxDocument.all.each do |fax_document|
+ fax_document.render_thumbnails
+ end
+
+ # Delete the restore_job. No need to waste that space.
+ #
+ restore_job.destroy
+ end
+ end
+
end \ No newline at end of file
diff --git a/lib/tasks/send_fax_notifications.rake b/lib/tasks/send_fax_notifications.rake
index 2ac74c8..b456466 100644
--- a/lib/tasks/send_fax_notifications.rake
+++ b/lib/tasks/send_fax_notifications.rake
@@ -6,7 +6,7 @@ task :send_fax_notifications => :environment do
FaxDocument.where(:state => 'received').each do |fax_document|
TIFF_FUFFIX = ".tiff"
PDF_SUFFIX = ".pdf"
- TMP_DIR = "/tmp/"
+ TMP_DIR = "/var/spool/freeswitch/"
tiff_file = File.basename(fax_document.tiff.to_s)