summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2014-07-02 09:57:32 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-07-02 13:45:22 +0000
commitc661f1349f44120b3cfcfc718ebb44b72f299cb8 (patch)
tree0e0e1092ba5a0037c2f6caa4ad0ced02390f0e22
parent616922c6125a1954ef51aac47cfce55186138699 (diff)
downloaddefinitions-c661f1349f44120b3cfcfc718ebb44b72f299cb8.tar.gz
Add remote backup and restoration scripts.
- Scripts written by Lars Wirzenius. - Reviewed by Michael Drake. These scripts are to be copied to the system on which the backups are made. They are stored here to keep the related logic in one source location.
-rw-r--r--gitlab-server/usr/share/gitlab-install/gitlab-remote-backup.sh22
-rw-r--r--gitlab-server/usr/share/gitlab-install/gitlab-remote-restore.sh57
2 files changed, 79 insertions, 0 deletions
diff --git a/gitlab-server/usr/share/gitlab-install/gitlab-remote-backup.sh b/gitlab-server/usr/share/gitlab-install/gitlab-remote-backup.sh
new file mode 100644
index 00000000..85618811
--- /dev/null
+++ b/gitlab-server/usr/share/gitlab-install/gitlab-remote-backup.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+#
+# Copy relevant files of a Baserock Gitlab instance out of the instance.
+#
+# Usage: backup.sh ADDR
+# where ADDR is the address (domain name, IP address) of the instance.
+# The files are copied to the current directory.
+
+set -eux
+
+ADDR="$1"
+
+backup()
+{
+ rsync -ahHS --delete "root@$ADDR:$1" "$2"
+}
+
+mkdir -p dumps repositories uploads
+backup /home/postgres/dumps/. dumps/.
+backup /home/git/repositories/. repositories/.
+backup /home/git/gitlab/public/uploads/. uploads/.
+
diff --git a/gitlab-server/usr/share/gitlab-install/gitlab-remote-restore.sh b/gitlab-server/usr/share/gitlab-install/gitlab-remote-restore.sh
new file mode 100644
index 00000000..78ff691a
--- /dev/null
+++ b/gitlab-server/usr/share/gitlab-install/gitlab-remote-restore.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+#
+# Restore a Baserock Gitlab system backup to a fresh instance.
+#
+# Usage: restore.sh ADDR
+# where ADDR is the address (domain name, IP address) of the instance.
+#
+# What this does is a) stop services b) copy files over c) reset the Postgres
+# databases.
+
+set -eux
+
+ADDR="$1"
+
+restore()
+{
+ rsync -ahHS --delete "$2" "root@$ADDR:$1"
+}
+
+# Stop services so we don't modify files and databases from underneath
+# them, and also so they don't modify things while restore is happening.
+
+ssh "root@$ADDR" systemctl stop \
+ crond gitlab-backup.service \
+ gitlab-ci-sidekiq.service \
+ gitlab-ci-unicorn.service \
+ gitlab-sidekiq.service \
+ gitlab-unicorn.service \
+ gitlab.target \
+ gitlab-backup.timer \
+ nginx.service \
+ redis.service
+
+# Create the directory where postgres dump files go.
+
+ssh "root@$ADDR" install -d -o postgres -g postgres /home/postgres/dumps
+
+# Restore the various files.
+
+restore /home/postgres/dumps/. dumps/.
+restore /home/git/repositories/. repositories/.
+restore /home/git/gitlab/public/uploads/. uploads/.
+
+# And thier uid/gid
+ssh "root@$ADDR" chown -R git:git /home/git/repositories /home/git/gitlab/public/uploads
+
+# Delete tables and roles from Postgres so that the restore can happen.
+
+ssh "root@$ADDR" sudo -u postgres psql <<EOF
+drop database gitlabhq_production;
+drop database gitlab_ci_production;
+drop role git, gitlab_ci;
+EOF
+
+# Restore the Postgres databases from the latest dump.
+
+ssh "root@$ADDR" sudo -u postgres psql -q -f /home/postgres/dumps/gitlab.pg_dumpall