OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Stream the SQL dump file when backing up (#18070)
Cyril Rohr8bc0c6b02383
diff --git a/app/workers/backup_job.rb b/app/workers/backup_job.rbindex 78f2a12ce95..69e75e75b58 100644--- a/app/workers/backup_job.rb+++ b/app/workers/backup_job.rb@@ -167,8 +167,7 @@ class BackupJob < ApplicationJobpaths_to_clean << get_cache_folder_path(attachment) if clean_up && attachment.file.cached?end-- zipfile.get_output_stream("openproject.sql") { |f| f.write File.read(db_dump_file_name) }+ zipfile.add "openproject.sql", db_dump_file_nameendremove_paths! paths_to_clean # delete locally cached files that were downloaded just for the backupdiff --git a/spec/workers/backup_job_spec.rb b/spec/workers/backup_job_spec.rbindex 58087092201..1a86459702c 100644--- a/spec/workers/backup_job_spec.rb+++ b/spec/workers/backup_job_spec.rb@@ -61,6 +61,12 @@ RSpec.describe BackupJob, type: :model dolet(:user) { create(:admin) }+ let(:openproject_sql) do+ Tempfile.new(["openproject", ".sql"]).tap do |f|+ f.write("SOME SQL")+ end+ end+before doprevious_backupbackup@@ -72,13 +78,12 @@ RSpec.describe BackupJob, type: :model doallow(Open3).to receive(:capture3).and_return [nil, "Dump failed", db_dump_process_status]allow_any_instance_of(BackupJob)- .to receive(:tmp_file_name).with("openproject", ".sql").and_return("/tmp/openproject.sql")+ .to receive(:tmp_file_name).with("openproject", ".sql").and_return(openproject_sql.path)allow_any_instance_of(BackupJob).to receive(:tmp_file_name).with("openproject-backup", ".zip").and_return("/tmp/openproject.zip")allow(File).to receive(:read).and_call_original- allow(File).to receive(:read).with("/tmp/openproject.sql").and_return "SOME SQL"enddef perform@@ -214,20 +219,18 @@ RSpec.describe BackupJob, type: :model do}}) do- let(:dummy_path) { "#{LocalFileUploader.cache_dir}/1639754082-3468-0002-0911/file.ext" }+ let(:dummy_file) { Pathname("#{LocalFileUploader.cache_dir}/1639754082-3468-0002-0911/file.ext") }before do- FileUtils.mkdir_p Pathname(dummy_path).parent.to_s- File.open(dummy_path, "w") { |f| f.puts "dummy" }+ dummy_file.parent.mkpath+ dummy_file.write("dummy")allow_any_instance_of(LocalFileUploader).to receive(:cached?).and_return(true)- allow_any_instance_of(LocalFileUploader)- .to receive(:local_file)- .and_return(File.new(dummy_path))+ allow_any_instance_of(LocalFileUploader).to receive(:local_file).and_return(File.new(dummy_file))endafter do- FileUtils.rm_rf dummy_path+ dummy_file.unlinkendit_behaves_like "it creates a backup", remote_storage: true