Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2020-12-14 00:10:01 +00:00
parent a479cde263
commit 4540acc237
4 changed files with 29 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
title: Retry rsync when source files vanish during backup
merge_request: 48568
author:
type: added

View file

@ -138,6 +138,7 @@ module Gitlab
import_url
elasticsearch_url
search
jwt
otp_attempt
sentry_dsn
trace

View file

@ -26,9 +26,15 @@ module Backup
FileUtils.rm_f(backup_tarball)
if ENV['STRATEGY'] == 'copy'
cmd = [%w[rsync -a], exclude_dirs(:rsync), %W[#{app_files_dir} #{Gitlab.config.backup.path}]].flatten
cmd = [%w[rsync -a --delete], exclude_dirs(:rsync), %W[#{app_files_dir} #{Gitlab.config.backup.path}]].flatten
output, status = Gitlab::Popen.popen(cmd)
# Retry if rsync source files vanish
if status == 24
$stdout.puts "Warning: files vanished during rsync, retrying..."
output, status = Gitlab::Popen.popen(cmd)
end
unless status == 0
puts output
raise Backup::Error, 'Backup failed'

View file

@ -149,13 +149,27 @@ RSpec.describe Backup::Files do
end
it 'excludes tmp dirs from rsync' do
expect(Gitlab::Popen).to receive(:popen).with(%w(rsync -a --exclude=lost+found --exclude=/@pages.tmp /var/gitlab-pages /var/gitlab-backup)).and_return(['', 0])
expect(Gitlab::Popen).to receive(:popen)
.with(%w(rsync -a --delete --exclude=lost+found --exclude=/@pages.tmp /var/gitlab-pages /var/gitlab-backup))
.and_return(['', 0])
subject.dump
end
it 'retries if rsync fails due to vanishing files' do
expect(Gitlab::Popen).to receive(:popen)
.with(%w(rsync -a --delete --exclude=lost+found --exclude=/@pages.tmp /var/gitlab-pages /var/gitlab-backup))
.and_return(['rsync failed', 24], ['', 0])
expect do
subject.dump
end.to output(/files vanished during rsync, retrying/).to_stdout
end
it 'raises an error and outputs an error message if rsync failed' do
allow(Gitlab::Popen).to receive(:popen).with(%w(rsync -a --exclude=lost+found --exclude=/@pages.tmp /var/gitlab-pages /var/gitlab-backup)).and_return(['rsync failed', 1])
allow(Gitlab::Popen).to receive(:popen)
.with(%w(rsync -a --delete --exclude=lost+found --exclude=/@pages.tmp /var/gitlab-pages /var/gitlab-backup))
.and_return(['rsync failed', 1])
expect do
subject.dump