Tuesday 22 March 2016

Gitlab Server Community Edition (CE) Backup and restore



Backup Steps for Gitlab Omnibus installations:

A backup creates an archive file that contains the database, all repositories and all attachments. The filename will be [TIMESTAMP]_gitlab_backup.tar and default backup/restore directory is var/opt/gitlab/backups. This timestamp can be used to restore an specific backup.  You can only restore a backup to exactly the same version of GitLab Server. You need to keep a separate copy of /etc/gitlab/gitlab-secrets.json . This file contains the database encryption key used for two-factor authentication.

Use the below syntax to create backup of Gitlab Server CE:

[root@linuxcnf ~]#gitlab-rake gitlab:backup:create
Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
Compressing database ... [DONE]
done
Dumping repositories ...
 * Test-repository1_BaseVersion ... [DONE]
 * Test-repository2_BaseVersion.wiki ...  [DONE]
 * Test-repository4.wiki ...  [SKIPPED]
 * testuser1 ... [SKIPPED]
 * testuser1.wiki ...  [SKIPPED]
done
Dumping uploads ...
done
Dumping builds ...
done
Creating backup archive: 1457963178_gitlab_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
done
done
done
Deleting old backups ... skipping
[root@linuxcnf ~]#


Backup Restore steps for Gitlab CE Omnibus installations
First make sure your backup tar file is in /var/opt/gitlab/backups 
Next, restore the backup by running the restore command. You need to specify the timestamp of the backup that you are restoring.

Stop below mention process which are connected to the database:

[root@linuxcnf ~]#gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@linuxcnf ~]#gitlab-ctl stop sidekiq
ok: down: sidekiq: 1s, normally up

This command will overwrite the contents of your GitLab database and restore the backup data:

[root@linuxcnf ~]#gitlab-rake gitlab:backup:restore BACKUP=1457963178
……………….
GRANT
[DONE]
done
Restoring repositories ...
 * Test-repository1 ... [DONE]
 * Test-repository2 ... [DONE]
 * Test-repository3 ... [DONE]
 * Test-repository4 ... [DONE]
* testuser1 ... [DONE]
Put GitLab hooks in repositories dirs [DONE]
done
Restoring uploads ...
done
Restoring builds ...
done
This will rebuild an authorized_keys file.
You will lose any data stored in authorized_keys file.
Do you want to continue (yes/no)? yes
.
Deleting tmp directories ... done
done
done
done
done
[root@linuxcnf ~]#

When restoration finish run the below command to start gitlab server:

[root@linuxcnf ~]#gitlab-ctl start

Check GitLab Data restoration status:

[root@linuxcnf ~]#gitlab-rake gitlab:check SANITIZE=true


Configure cron to make daily backups

For omnibus installations
To schedule a cron job that backsup your repositories automatically as scheduled time.

Add the following line in to cron to schedule the backup for everyday at 11 PM:

[root@linuxcnf ~]#crontab -e
0 23 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1

No comments:

Post a Comment