[packages/gitlab-ce] setup db backup and db upgrade on package upgrade

glen glen at pld-linux.org
Thu May 26 23:13:09 CEST 2016


commit a6fcdc58235bb9e87f72f03e025bcd1027e2f533
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Thu May 26 23:47:51 2016 +0300

    setup db backup and db upgrade on package upgrade

 gitlab-ce.spec | 12 ++++++++++++
 gitlab-ctl.sh  | 54 ++++++++++++++++++++++++++++++++----------------------
 2 files changed, 44 insertions(+), 22 deletions(-)
---
diff --git a/gitlab-ce.spec b/gitlab-ce.spec
index 8fa06dd..5d6cf4f 100644
--- a/gitlab-ce.spec
+++ b/gitlab-ce.spec
@@ -202,6 +202,12 @@ install -p %{SOURCE11} $RPM_BUILD_ROOT%{_sbindir}/gitlab-ctl
 %clean
 rm -rf "$RPM_BUILD_ROOT"
 
+%pre
+if [ "$2" = "2" ]; then
+	# Looks like an RPM upgrade
+	gitlab-ctl preinst
+fi
+
 %post
 /sbin/chkconfig --add gitlab-sidekiq
 /sbin/chkconfig --add gitlab-unicorn
@@ -228,6 +234,12 @@ else
 	systemctl -q try-start gitlab-sidekiq || :
 fi
 
+%posttrans
+if [ "$1" = "0" ]; then
+	# Looks like an RPM upgrade
+	gitlab-ctl posttrans
+fi
+
 %preun
 if [ "$1" = "0" ]; then
 	%service -q gitlab-sidekiq stop
diff --git a/gitlab-ctl.sh b/gitlab-ctl.sh
index 2b35353..3307770 100755
--- a/gitlab-ctl.sh
+++ b/gitlab-ctl.sh
@@ -11,10 +11,30 @@ die() {
 	exit 1
 }
 
+# Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
+upgrade() {
+	gitlab-rake db:migrate "$@"
+}
+
+# GitLab | Create a backup of the GitLab system
+backup() {
+	gitlab-rake gitlab:backup:create "$@"
+}
+
+# http://docs.gitlab.com/ce/administration/restart_gitlab.html#installations-from-source
+restart() {
+	:
+}
+
 # Run backup before package upgrade
 # https://gitlab.com/gitlab-org/omnibus-gitlab/blob/8.8.1+ce.0/config/templates/package-scripts/preinst.erb#L10
-backup_before_upgrade() {
-	if ! gitlab-rake gitlab:backup:create SKIP=repositories,uploads,builds,artifacts,lfs,registry; then
+preinst() {
+	if [ -f $auto_migrations_skip_file ]; then
+		echo >&2 "Found $auto_migrations_skip_file, skipping auto backup..."
+		return
+	fi
+
+	if ! backup SKIP=repositories,uploads,builds,artifacts,lfs,registry; then
 		cat >&2 <<-EOF
 
 		Backup failed! If you want to skip this backup, run the following command and try again:
@@ -27,19 +47,9 @@ backup_before_upgrade() {
 }
 
 # Run migrations after a package upgrade
+# https://gitlab.com/gitlab-org/omnibus-gitlab/blob/8.8.1+ce.0/config/templates/package-scripts/posttrans.erb
 # https://gitlab.com/gitlab-org/omnibus-gitlab/blob/8.8.1+ce.0/files/gitlab-ctl-commands/upgrade.rb
-upgrade() {
-	gitlab-rake db:migrate
-}
-
-# Run migrations after a package upgrade
-pkg_upgrade() {
-	if [ -f $auto_migrations_skip_file ]; then
-		echo >&2 "Found $auto_migrations_skip_file, exiting..."
-		return
-	fi
-
-	backup_before_upgrade
+posttrans() {
 	upgrade
 
 	cat >&2 <<-EOF
@@ -48,17 +58,17 @@ pkg_upgrade() {
 		If you need to roll back to the previous version you can
 		use the database backup made during the upgrade (scroll up for the filename).
 	EOF
-
-}
-
-# http://docs.gitlab.com/ce/administration/restart_gitlab.html#installations-from-source
-restart() {
-	:
 }
 
 case "$1" in
-pkg-upgrade)
-	pkg_upgrade
+preinst)
+	preinst
+	;;
+posttrans)
+	posttrans
+	;;
+backup)
+	backup "$@"
 	;;
 upgrade)
 	upgrade
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/gitlab-ce.git/commitdiff/82ad69d4c447cfa7a8bd37ff7e96bd72268d4163



More information about the pld-cvs-commit mailing list