Commit e6234a15 authored by Mark Chao's avatar Mark Chao

Merge branch 'fix_backup_tar_non_existing_dir' into 'master'

Fix backup.rake from trying to tar non-existent directories

See merge request gitlab-org/gitlab!67090
parents 17fb5c2b 042a203f
...@@ -232,7 +232,7 @@ module Backup ...@@ -232,7 +232,7 @@ module Backup
end end
def folders_to_backup def folders_to_backup
FOLDERS_TO_BACKUP.reject { |name| skipped?(name) } FOLDERS_TO_BACKUP.select { |name| !skipped?(name) && Dir.exist?(File.join(backup_path, name)) }
end end
def disabled_features def disabled_features
......
...@@ -12,20 +12,13 @@ RSpec.describe Backup::Manager do ...@@ -12,20 +12,13 @@ RSpec.describe Backup::Manager do
before do before do
allow(progress).to receive(:puts) allow(progress).to receive(:puts)
allow(progress).to receive(:print) allow(progress).to receive(:print)
@old_progress = $progress # rubocop:disable Style/GlobalVars
$progress = progress # rubocop:disable Style/GlobalVars
end
after do
$progress = @old_progress # rubocop:disable Style/GlobalVars
end end
describe '#pack' do describe '#pack' do
let(:backup_contents) { ['backup_contents'] } let(:expected_backup_contents) { %w(repositories db uploads.tar.gz builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz backup_information.yml) }
let(:tar_file) { '1546300800_2019_01_01_12.3_gitlab_backup.tar' }
let(:tar_system_options) { { out: [tar_file, 'w', Gitlab.config.backup.archive_permissions] } } let(:tar_system_options) { { out: [tar_file, 'w', Gitlab.config.backup.archive_permissions] } }
let(:tar_cmdline) { ['tar', '-cf', '-', *backup_contents, tar_system_options] } let(:tar_cmdline) { ['tar', '-cf', '-', *expected_backup_contents, tar_system_options] }
let(:backup_information) do let(:backup_information) do
{ {
backup_created_at: Time.zone.parse('2019-01-01'), backup_created_at: Time.zone.parse('2019-01-01'),
...@@ -36,21 +29,21 @@ RSpec.describe Backup::Manager do ...@@ -36,21 +29,21 @@ RSpec.describe Backup::Manager do
before do before do
allow(ActiveRecord::Base.connection).to receive(:reconnect!) allow(ActiveRecord::Base.connection).to receive(:reconnect!)
allow(Kernel).to receive(:system).and_return(true) allow(Kernel).to receive(:system).and_return(true)
allow(YAML).to receive(:load_file).and_return(backup_information)
::Backup::Manager::FOLDERS_TO_BACKUP.each do |folder|
allow(Dir).to receive(:exist?).with(File.join(Gitlab.config.backup.path, folder)).and_return(true)
end
allow(subject).to receive(:backup_contents).and_return(backup_contents)
allow(subject).to receive(:backup_information).and_return(backup_information) allow(subject).to receive(:backup_information).and_return(backup_information)
allow(subject).to receive(:upload) allow(subject).to receive(:upload)
end end
context 'when BACKUP is not set' do it 'executes tar' do
let(:tar_file) { '1546300800_2019_01_01_12.3_gitlab_backup.tar' }
it 'uses the default tar file name' do
subject.pack subject.pack
expect(Kernel).to have_received(:system).with(*tar_cmdline) expect(Kernel).to have_received(:system).with(*tar_cmdline)
end end
end
context 'when BACKUP is set' do context 'when BACKUP is set' do
let(:tar_file) { 'custom_gitlab_backup.tar' } let(:tar_file) { 'custom_gitlab_backup.tar' }
...@@ -62,6 +55,37 @@ RSpec.describe Backup::Manager do ...@@ -62,6 +55,37 @@ RSpec.describe Backup::Manager do
expect(Kernel).to have_received(:system).with(*tar_cmdline) expect(Kernel).to have_received(:system).with(*tar_cmdline)
end end
end end
context 'when skipped is set in backup_information.yml' do
let(:expected_backup_contents) { %w{db uploads.tar.gz builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz backup_information.yml} }
let(:backup_information) do
{
backup_created_at: Time.zone.parse('2019-01-01'),
gitlab_version: '12.3',
skipped: ['repositories']
}
end
it 'executes tar' do
subject.pack
expect(Kernel).to have_received(:system).with(*tar_cmdline)
end
end
context 'when a directory does not exist' do
let(:expected_backup_contents) { %w{db uploads.tar.gz builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz backup_information.yml} }
before do
expect(Dir).to receive(:exist?).with(File.join(Gitlab.config.backup.path, 'repositories')).and_return(false)
end
it 'executes tar' do
subject.pack
expect(Kernel).to have_received(:system).with(*tar_cmdline)
end
end
end end
describe '#remove_old' do describe '#remove_old' do
......
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