Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
25e7fb5a
Commit
25e7fb5a
authored
Aug 19, 2021
by
James Fargher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove feature flag gitaly_backup
This feature has been enabled by default since 14.2 Changelog: removed
parent
8c9a9c45
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
3 additions
and
327 deletions
+3
-327
config/feature_flags/development/gitaly_backup.yml
config/feature_flags/development/gitaly_backup.yml
+0
-8
doc/raketasks/backup_restore.md
doc/raketasks/backup_restore.md
+0
-27
lib/backup/gitaly_rpc_backup.rb
lib/backup/gitaly_rpc_backup.rb
+0
-132
lib/tasks/gitlab/backup.rake
lib/tasks/gitlab/backup.rake
+3
-7
spec/lib/backup/gitaly_rpc_backup_spec.rb
spec/lib/backup/gitaly_rpc_backup_spec.rb
+0
-153
No files found.
config/feature_flags/development/gitaly_backup.yml
deleted
100644 → 0
View file @
8c9a9c45
---
name
:
gitaly_backup
introduced_by_url
:
https://gitlab.com/gitlab-org/gitaly/-/merge_requests/3554
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/333034
milestone
:
'
14.0'
type
:
development
group
:
group::gitaly
default_enabled
:
true
doc/raketasks/backup_restore.md
View file @
25e7fb5a
...
...
@@ -1477,16 +1477,8 @@ If this happens, examine the following:
### `gitaly-backup` for repository backup and restore **(FREE SELF)**
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/333034) in GitLab 14.2.
> - [Deployed behind a feature flag](../user/feature_flags.md), enabled by default.
> - Recommended for production use.
> - For GitLab self-managed instances, GitLab administrators can opt to [disable it](#disable-or-enable-gitaly-backup).
There can be
[
risks when disabling released features
](
../administration/feature_flags.md#risks-when-disabling-released-features
)
.
Refer to this feature's version history for more details.
`gitaly-backup`
is used by the backup Rake task to create and restore repository backups from Gitaly.
`gitaly-backup`
replaces the previous backup method that directly calls RPCs on Gitaly from GitLab.
The backup Rake task must be able to find this executable. It can be configured in Omnibus GitLab packages:
...
...
@@ -1498,22 +1490,3 @@ The backup Rake task must be able to find this executable. It can be configured
1.
[
Reconfigure GitLab
](
../administration/restart_gitlab.md#omnibus-gitlab-reconfigure
)
for the changes to take effect
#### Disable or enable `gitaly-backup`
`gitaly-backup`
is under development but ready for production use.
It is deployed behind a feature flag that is
**enabled by default**
.
[
GitLab administrators with access to the GitLab Rails console
](
../administration/feature_flags.md
)
can opt to disable it.
To disable it:
```
ruby
Feature
.
disable
(
:gitaly_backup
)
```
To enable it:
```
ruby
Feature
.
enable
(
:gitaly_backup
)
```
lib/backup/gitaly_rpc_backup.rb
deleted
100644 → 0
View file @
8c9a9c45
# frozen_string_literal: true
module
Backup
# Backup and restores repositories using the gitaly RPC
class
GitalyRpcBackup
def
initialize
(
progress
)
@progress
=
progress
end
def
start
(
type
)
raise
Error
,
'already started'
if
@type
@type
=
type
case
type
when
:create
FileUtils
.
rm_rf
(
backup_repos_path
)
FileUtils
.
mkdir_p
(
Gitlab
.
config
.
backup
.
path
)
FileUtils
.
mkdir
(
backup_repos_path
,
mode:
0700
)
when
:restore
# no op
else
raise
Error
,
"unknown backup type:
#{
type
}
"
end
end
def
wait
@type
=
nil
end
def
enqueue
(
container
,
repository_type
)
backup_restore
=
BackupRestore
.
new
(
progress
,
repository_type
.
repository_for
(
container
),
backup_repos_path
)
case
@type
when
:create
backup_restore
.
backup
when
:restore
backup_restore
.
restore
(
always_create:
repository_type
.
project?
)
else
raise
Error
,
'not started'
end
end
def
parallel_enqueue?
true
end
private
attr_reader
:progress
def
backup_repos_path
@backup_repos_path
||=
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'repositories'
)
end
class
BackupRestore
attr_accessor
:progress
,
:repository
,
:backup_repos_path
def
initialize
(
progress
,
repository
,
backup_repos_path
)
@progress
=
progress
@repository
=
repository
@backup_repos_path
=
backup_repos_path
end
def
backup
progress
.
puts
" *
#{
display_repo_path
}
... "
if
repository
.
empty?
progress
.
puts
" *
#{
display_repo_path
}
... "
+
"[EMPTY] [SKIPPED]"
.
color
(
:cyan
)
return
end
FileUtils
.
mkdir_p
(
repository_backup_path
)
repository
.
bundle_to_disk
(
path_to_bundle
)
repository
.
gitaly_repository_client
.
backup_custom_hooks
(
custom_hooks_tar
)
progress
.
puts
" *
#{
display_repo_path
}
... "
+
"[DONE]"
.
color
(
:green
)
rescue
StandardError
=>
e
progress
.
puts
"[Failed] backing up
#{
display_repo_path
}
"
.
color
(
:red
)
progress
.
puts
"Error
#{
e
}
"
.
color
(
:red
)
end
def
restore
(
always_create:
false
)
progress
.
puts
" *
#{
display_repo_path
}
... "
repository
.
remove
rescue
nil
if
File
.
exist?
(
path_to_bundle
)
repository
.
create_from_bundle
(
path_to_bundle
)
restore_custom_hooks
elsif
always_create
repository
.
create_repository
end
progress
.
puts
" *
#{
display_repo_path
}
... "
+
"[DONE]"
.
color
(
:green
)
rescue
StandardError
=>
e
progress
.
puts
"[Failed] restoring
#{
display_repo_path
}
"
.
color
(
:red
)
progress
.
puts
"Error
#{
e
}
"
.
color
(
:red
)
end
private
def
display_repo_path
"
#{
repository
.
full_path
}
(
#{
repository
.
disk_path
}
)"
end
def
repository_backup_path
@repository_backup_path
||=
File
.
join
(
backup_repos_path
,
repository
.
disk_path
)
end
def
path_to_bundle
@path_to_bundle
||=
File
.
join
(
backup_repos_path
,
repository
.
disk_path
+
'.bundle'
)
end
def
restore_custom_hooks
return
unless
File
.
exist?
(
custom_hooks_tar
)
repository
.
gitaly_repository_client
.
restore_custom_hooks
(
custom_hooks_tar
)
end
def
custom_hooks_tar
File
.
join
(
repository_backup_path
,
"custom_hooks.tar"
)
end
end
end
end
lib/tasks/gitlab/backup.rake
View file @
25e7fb5a
...
...
@@ -299,13 +299,9 @@ namespace :gitlab do
end
def
repository_backup_strategy
if
Feature
.
enabled?
(
:gitaly_backup
,
default_enabled: :yaml
)
max_concurrency
=
ENV
[
'GITLAB_BACKUP_MAX_CONCURRENCY'
].
presence
max_storage_concurrency
=
ENV
[
'GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY'
].
presence
Backup
::
GitalyBackup
.
new
(
progress
,
parallel:
max_concurrency
,
parallel_storage:
max_storage_concurrency
)
else
Backup
::
GitalyRpcBackup
.
new
(
progress
)
end
max_concurrency
=
ENV
[
'GITLAB_BACKUP_MAX_CONCURRENCY'
].
presence
max_storage_concurrency
=
ENV
[
'GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY'
].
presence
Backup
::
GitalyBackup
.
new
(
progress
,
parallel:
max_concurrency
,
parallel_storage:
max_storage_concurrency
)
end
end
# namespace end: backup
...
...
spec/lib/backup/gitaly_rpc_backup_spec.rb
deleted
100644 → 0
View file @
8c9a9c45
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Backup
::
GitalyRpcBackup
do
let
(
:progress
)
{
spy
(
:stdout
)
}
subject
{
described_class
.
new
(
progress
)
}
after
do
# make sure we do not leave behind any backup files
FileUtils
.
rm_rf
(
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'repositories'
))
end
context
'unknown'
do
it
'fails to start unknown'
do
expect
{
subject
.
start
(
:unknown
)
}.
to
raise_error
(
::
Backup
::
Error
,
'unknown backup type: unknown'
)
end
end
context
'create'
do
RSpec
.
shared_examples
'creates a repository backup'
do
it
'creates repository bundles'
,
:aggregate_failures
do
# Add data to the wiki, design repositories, and snippets, so they will be included in the dump.
create
(
:wiki_page
,
container:
project
)
create
(
:design
,
:with_file
,
issue:
create
(
:issue
,
project:
project
))
project_snippet
=
create
(
:project_snippet
,
:repository
,
project:
project
)
personal_snippet
=
create
(
:personal_snippet
,
:repository
,
author:
project
.
owner
)
subject
.
start
(
:create
)
subject
.
enqueue
(
project
,
Gitlab
::
GlRepository
::
PROJECT
)
subject
.
enqueue
(
project
,
Gitlab
::
GlRepository
::
WIKI
)
subject
.
enqueue
(
project
,
Gitlab
::
GlRepository
::
DESIGN
)
subject
.
enqueue
(
personal_snippet
,
Gitlab
::
GlRepository
::
SNIPPET
)
subject
.
enqueue
(
project_snippet
,
Gitlab
::
GlRepository
::
SNIPPET
)
subject
.
wait
expect
(
File
).
to
exist
(
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'repositories'
,
project
.
disk_path
+
'.bundle'
))
expect
(
File
).
to
exist
(
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'repositories'
,
project
.
disk_path
+
'.wiki.bundle'
))
expect
(
File
).
to
exist
(
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'repositories'
,
project
.
disk_path
+
'.design.bundle'
))
expect
(
File
).
to
exist
(
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'repositories'
,
personal_snippet
.
disk_path
+
'.bundle'
))
expect
(
File
).
to
exist
(
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'repositories'
,
project_snippet
.
disk_path
+
'.bundle'
))
end
context
'failure'
do
before
do
allow_next_instance_of
(
Repository
)
do
|
repository
|
allow
(
repository
).
to
receive
(
:bundle_to_disk
)
{
raise
'Fail in tests'
}
end
end
it
'logs an appropriate message'
,
:aggregate_failures
do
subject
.
start
(
:create
)
subject
.
enqueue
(
project
,
Gitlab
::
GlRepository
::
PROJECT
)
subject
.
wait
expect
(
progress
).
to
have_received
(
:puts
).
with
(
"[Failed] backing up
#{
project
.
full_path
}
(
#{
project
.
disk_path
}
)"
)
expect
(
progress
).
to
have_received
(
:puts
).
with
(
"Error Fail in tests"
)
end
end
end
context
'hashed storage'
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
it_behaves_like
'creates a repository backup'
end
context
'legacy storage'
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
,
:legacy_storage
)
}
it_behaves_like
'creates a repository backup'
end
end
context
'restore'
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:personal_snippet
)
{
create
(
:personal_snippet
,
author:
project
.
owner
)
}
let_it_be
(
:project_snippet
)
{
create
(
:project_snippet
,
project:
project
,
author:
project
.
owner
)
}
def
copy_bundle_to_backup_path
(
bundle_name
,
destination
)
FileUtils
.
mkdir_p
(
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'repositories'
,
File
.
dirname
(
destination
)))
FileUtils
.
cp
(
Rails
.
root
.
join
(
'spec/fixtures/lib/backup'
,
bundle_name
),
File
.
join
(
Gitlab
.
config
.
backup
.
path
,
'repositories'
,
destination
))
end
it
'restores from repository bundles'
,
:aggregate_failures
do
copy_bundle_to_backup_path
(
'project_repo.bundle'
,
project
.
disk_path
+
'.bundle'
)
copy_bundle_to_backup_path
(
'wiki_repo.bundle'
,
project
.
disk_path
+
'.wiki.bundle'
)
copy_bundle_to_backup_path
(
'design_repo.bundle'
,
project
.
disk_path
+
'.design.bundle'
)
copy_bundle_to_backup_path
(
'personal_snippet_repo.bundle'
,
personal_snippet
.
disk_path
+
'.bundle'
)
copy_bundle_to_backup_path
(
'project_snippet_repo.bundle'
,
project_snippet
.
disk_path
+
'.bundle'
)
subject
.
start
(
:restore
)
subject
.
enqueue
(
project
,
Gitlab
::
GlRepository
::
PROJECT
)
subject
.
enqueue
(
project
,
Gitlab
::
GlRepository
::
WIKI
)
subject
.
enqueue
(
project
,
Gitlab
::
GlRepository
::
DESIGN
)
subject
.
enqueue
(
personal_snippet
,
Gitlab
::
GlRepository
::
SNIPPET
)
subject
.
enqueue
(
project_snippet
,
Gitlab
::
GlRepository
::
SNIPPET
)
subject
.
wait
collect_commit_shas
=
->
(
repo
)
{
repo
.
commits
(
'master'
,
limit:
10
).
map
(
&
:sha
)
}
expect
(
collect_commit_shas
.
call
(
project
.
repository
)).
to
eq
([
'393a7d860a5a4c3cc736d7eb00604e3472bb95ec'
])
expect
(
collect_commit_shas
.
call
(
project
.
wiki
.
repository
)).
to
eq
([
'c74b9948d0088d703ee1fafeddd9ed9add2901ea'
])
expect
(
collect_commit_shas
.
call
(
project
.
design_repository
)).
to
eq
([
'c3cd4d7bd73a51a0f22045c3a4c871c435dc959d'
])
expect
(
collect_commit_shas
.
call
(
personal_snippet
.
repository
)).
to
eq
([
'3b3c067a3bc1d1b695b51e2be30c0f8cf698a06e'
])
expect
(
collect_commit_shas
.
call
(
project_snippet
.
repository
)).
to
eq
([
'6e44ba56a4748be361a841e759c20e421a1651a1'
])
end
it
'cleans existing repositories'
,
:aggregate_failures
do
expect_next_instance_of
(
DesignManagement
::
Repository
)
do
|
repository
|
expect
(
repository
).
to
receive
(
:remove
)
end
# 4 times = project repo + wiki repo + project_snippet repo + personal_snippet repo
expect
(
Repository
).
to
receive
(
:new
).
exactly
(
4
).
times
.
and_wrap_original
do
|
method
,
*
original_args
|
full_path
,
container
,
kwargs
=
original_args
repository
=
method
.
call
(
full_path
,
container
,
**
kwargs
)
expect
(
repository
).
to
receive
(
:remove
)
repository
end
subject
.
start
(
:restore
)
subject
.
enqueue
(
project
,
Gitlab
::
GlRepository
::
PROJECT
)
subject
.
enqueue
(
project
,
Gitlab
::
GlRepository
::
WIKI
)
subject
.
enqueue
(
project
,
Gitlab
::
GlRepository
::
DESIGN
)
subject
.
enqueue
(
personal_snippet
,
Gitlab
::
GlRepository
::
SNIPPET
)
subject
.
enqueue
(
project_snippet
,
Gitlab
::
GlRepository
::
SNIPPET
)
subject
.
wait
end
context
'failure'
do
before
do
allow_next_instance_of
(
Repository
)
do
|
repository
|
allow
(
repository
).
to
receive
(
:create_repository
)
{
raise
'Fail in tests'
}
allow
(
repository
).
to
receive
(
:create_from_bundle
)
{
raise
'Fail in tests'
}
end
end
it
'logs an appropriate message'
,
:aggregate_failures
do
subject
.
start
(
:restore
)
subject
.
enqueue
(
project
,
Gitlab
::
GlRepository
::
PROJECT
)
subject
.
wait
expect
(
progress
).
to
have_received
(
:puts
).
with
(
"[Failed] restoring
#{
project
.
full_path
}
(
#{
project
.
disk_path
}
)"
)
expect
(
progress
).
to
have_received
(
:puts
).
with
(
"Error Fail in tests"
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment