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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
a540ab42
Commit
a540ab42
authored
Nov 05, 2013
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Bourne shell from backup code
parent
f9b66aec
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
14 deletions
+18
-14
lib/backup/database.rb
lib/backup/database.rb
+5
-5
lib/backup/manager.rb
lib/backup/manager.rb
+4
-4
lib/backup/repository.rb
lib/backup/repository.rb
+9
-5
No files found.
lib/backup/database.rb
View file @
a540ab42
...
@@ -13,20 +13,20 @@ module Backup
...
@@ -13,20 +13,20 @@ module Backup
def
dump
def
dump
case
config
[
"adapter"
]
case
config
[
"adapter"
]
when
/^mysql/
then
when
/^mysql/
then
system
(
"mysqldump
#{
mysql_args
}
#{
config
[
'database'
]
}
>
#{
db_file_name
}
"
)
system
(
'mysqldump'
,
*
mysql_args
,
config
[
'database'
],
out:
db_file_name
)
when
"postgresql"
then
when
"postgresql"
then
pg_env
pg_env
system
(
"pg_dump
#{
config
[
'database'
]
}
>
#{
db_file_name
}
"
)
system
(
'pg_dump'
,
config
[
'database'
],
out:
db_file_name
)
end
end
end
end
def
restore
def
restore
case
config
[
"adapter"
]
case
config
[
"adapter"
]
when
/^mysql/
then
when
/^mysql/
then
system
(
"mysql
#{
mysql_args
}
#{
config
[
'database'
]
}
<
#{
db_file_name
}
"
)
system
(
'mysql'
,
*
mysql_args
,
config
[
'database'
],
in:
db_file_name
)
when
"postgresql"
then
when
"postgresql"
then
pg_env
pg_env
system
(
"psql
#{
config
[
'database'
]
}
-f
#{
db_file_name
}
"
)
system
(
'psql'
,
config
[
'database'
],
'-f'
,
db_file_name
)
end
end
end
end
...
@@ -45,7 +45,7 @@ module Backup
...
@@ -45,7 +45,7 @@ module Backup
'encoding'
=>
'--default-character-set'
,
'encoding'
=>
'--default-character-set'
,
'password'
=>
'--password'
'password'
=>
'--password'
}
}
args
.
map
{
|
opt
,
arg
|
"
#{
arg
}
=
'
#{
config
[
opt
]
}
'"
if
config
[
opt
]
}.
compact
.
join
(
' '
)
args
.
map
{
|
opt
,
arg
|
"
#{
arg
}
=
#{
config
[
opt
]
}
"
if
config
[
opt
]
}.
compact
end
end
def
pg_env
def
pg_env
...
...
lib/backup/manager.rb
View file @
a540ab42
...
@@ -16,7 +16,7 @@ module Backup
...
@@ -16,7 +16,7 @@ module Backup
# create archive
# create archive
print
"Creating backup archive:
#{
s
[
:backup_created_at
].
to_i
}
_gitlab_backup.tar ... "
print
"Creating backup archive:
#{
s
[
:backup_created_at
].
to_i
}
_gitlab_backup.tar ... "
if
Kernel
.
system
(
"tar -cf
#{
s
[
:backup_created_at
].
to_i
}
_gitlab_backup.tar repositories/ db/ uploads/ backup_information.yml"
)
if
Kernel
.
system
(
*
%W(tar -cf
#{
s
[
:backup_created_at
].
to_i
}
_gitlab_backup.tar repositories/ db/ uploads/ backup_information.yml)
)
puts
"done"
.
green
puts
"done"
.
green
else
else
puts
"failed"
.
red
puts
"failed"
.
red
...
@@ -25,7 +25,7 @@ module Backup
...
@@ -25,7 +25,7 @@ module Backup
def
cleanup
def
cleanup
print
"Deleting tmp directories ... "
print
"Deleting tmp directories ... "
if
Kernel
.
system
(
"rm -rf repositories/ db/ uploads/ backup_information.yml"
)
if
Kernel
.
system
(
*
%W(rm -rf repositories/ db/ uploads/ backup_information.yml)
)
puts
"done"
.
green
puts
"done"
.
green
else
else
puts
"failed"
.
red
puts
"failed"
.
red
...
@@ -44,7 +44,7 @@ module Backup
...
@@ -44,7 +44,7 @@ module Backup
file_list
.
map!
{
|
f
|
$1
.
to_i
if
f
=~
/(\d+)_gitlab_backup.tar/
}
file_list
.
map!
{
|
f
|
$1
.
to_i
if
f
=~
/(\d+)_gitlab_backup.tar/
}
file_list
.
sort
.
each
do
|
timestamp
|
file_list
.
sort
.
each
do
|
timestamp
|
if
Time
.
at
(
timestamp
)
<
(
Time
.
now
-
keep_time
)
if
Time
.
at
(
timestamp
)
<
(
Time
.
now
-
keep_time
)
if
system
(
"rm
#{
timestamp
}
_gitlab_backup.tar"
)
if
Kernel
.
system
(
*
%W(rm
#{
timestamp
}
_gitlab_backup.tar)
)
removed
+=
1
removed
+=
1
end
end
end
end
...
@@ -75,7 +75,7 @@ module Backup
...
@@ -75,7 +75,7 @@ module Backup
end
end
print
"Unpacking backup ... "
print
"Unpacking backup ... "
unless
Kernel
.
system
(
"tar -xf
#{
tar_file
}
"
)
unless
Kernel
.
system
(
*
%W(tar -xf
#{
tar_file
}
)
)
puts
"failed"
.
red
puts
"failed"
.
red
exit
1
exit
1
else
else
...
...
lib/backup/repository.rb
View file @
a540ab42
...
@@ -18,7 +18,7 @@ module Backup
...
@@ -18,7 +18,7 @@ module Backup
# Create namespace dir if missing
# Create namespace dir if missing
FileUtils
.
mkdir_p
(
File
.
join
(
backup_repos_path
,
project
.
namespace
.
path
))
if
project
.
namespace
FileUtils
.
mkdir_p
(
File
.
join
(
backup_repos_path
,
project
.
namespace
.
path
))
if
project
.
namespace
if
system
(
"cd
#{
path_to_repo
(
project
)
}
> /dev/null 2>&1 && git bundle create
#{
path_to_bundle
(
project
)
}
--all > /dev/null 2>&1"
)
if
system
(
*
%W(git --git-dir=
#{
path_to_repo
(
project
)
}
bundle create
#{
path_to_bundle
(
project
)
}
--all)
,
silent
)
puts
"[DONE]"
.
green
puts
"[DONE]"
.
green
else
else
puts
"[FAILED]"
.
red
puts
"[FAILED]"
.
red
...
@@ -30,7 +30,7 @@ module Backup
...
@@ -30,7 +30,7 @@ module Backup
print
" *
#{
wiki
.
path_with_namespace
}
... "
print
" *
#{
wiki
.
path_with_namespace
}
... "
if
wiki
.
empty?
if
wiki
.
empty?
puts
" [SKIPPED]"
.
cyan
puts
" [SKIPPED]"
.
cyan
elsif
system
(
"cd
#{
path_to_repo
(
wiki
)
}
> /dev/null 2>&1 && git bundle create
#{
path_to_bundle
(
wiki
)
}
--all > /dev/null 2>&1"
)
elsif
system
(
*
%W(git --git-dir=
#{
path_to_repo
(
wiki
)
}
bundle create
#{
path_to_bundle
(
wiki
)
}
--all)
,
silent
)
puts
" [DONE]"
.
green
puts
" [DONE]"
.
green
else
else
puts
" [FAILED]"
.
red
puts
" [FAILED]"
.
red
...
@@ -53,7 +53,7 @@ module Backup
...
@@ -53,7 +53,7 @@ module Backup
project
.
namespace
.
ensure_dir_exist
if
project
.
namespace
project
.
namespace
.
ensure_dir_exist
if
project
.
namespace
if
system
(
"git clone --bare
#{
path_to_bundle
(
project
)
}
#{
path_to_repo
(
project
)
}
> /dev/null 2>&1"
)
if
system
(
*
%W(git clone --bare
#{
path_to_bundle
(
project
)
}
#{
path_to_repo
(
project
)
}
)
,
silent
)
puts
"[DONE]"
.
green
puts
"[DONE]"
.
green
else
else
puts
"[FAILED]"
.
red
puts
"[FAILED]"
.
red
...
@@ -63,7 +63,7 @@ module Backup
...
@@ -63,7 +63,7 @@ module Backup
if
File
.
exists?
(
path_to_bundle
(
wiki
))
if
File
.
exists?
(
path_to_bundle
(
wiki
))
print
" *
#{
wiki
.
path_with_namespace
}
... "
print
" *
#{
wiki
.
path_with_namespace
}
... "
if
system
(
"git clone --bare
#{
path_to_bundle
(
wiki
)
}
#{
path_to_repo
(
wiki
)
}
> /dev/null 2>&1"
)
if
system
(
*
%W(git clone --bare
#{
path_to_bundle
(
wiki
)
}
#{
path_to_repo
(
wiki
)
}
)
,
silent
)
puts
" [DONE]"
.
green
puts
" [DONE]"
.
green
else
else
puts
" [FAILED]"
.
red
puts
" [FAILED]"
.
red
...
@@ -73,7 +73,7 @@ module Backup
...
@@ -73,7 +73,7 @@ module Backup
print
'Put GitLab hooks in repositories dirs'
.
yellow
print
'Put GitLab hooks in repositories dirs'
.
yellow
gitlab_shell_user_home
=
File
.
expand_path
(
"~
#{
Gitlab
.
config
.
gitlab_shell
.
ssh_user
}
"
)
gitlab_shell_user_home
=
File
.
expand_path
(
"~
#{
Gitlab
.
config
.
gitlab_shell
.
ssh_user
}
"
)
if
system
(
"
#{
gitlab_shell_user_home
}
/gitlab-shell/support/rewrite-hooks.sh
#{
Gitlab
.
config
.
gitlab_shell
.
repos_path
}
"
)
if
system
(
"
#{
gitlab_shell_user_home
}
/gitlab-shell/support/rewrite-hooks.sh
"
,
Gitlab
.
config
.
gitlab_shell
.
repos_path
)
puts
" [DONE]"
.
green
puts
" [DONE]"
.
green
else
else
puts
" [FAILED]"
.
red
puts
" [FAILED]"
.
red
...
@@ -103,5 +103,9 @@ module Backup
...
@@ -103,5 +103,9 @@ module Backup
FileUtils
.
rm_rf
(
backup_repos_path
)
FileUtils
.
rm_rf
(
backup_repos_path
)
FileUtils
.
mkdir_p
(
backup_repos_path
)
FileUtils
.
mkdir_p
(
backup_repos_path
)
end
end
def
silent
{
err:
'/dev/null'
,
out:
'/dev/null'
}
end
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