Skip to content

Ercan Ermis

notes for everyone

Menu
  • Cloud
    • Amazon Web Services
    • Google Cloud Platform
  • Linux
  • DevOps
  • Docker
  • Uncategorized
  • Contact Me
Menu

Take your GitLab backup everyday if it works in Docker

Posted on September 16, 2020April 24, 2021 by Ercan

I’m using GitLab in docker (because I love containerization) and I’m really okay with that because I can move the GitLab environment everywhere if I need and I can feel more elastic when I’m using docker.

GitLab backups are really so important because you are keeping all of the source code and maybe wiki maybe more than all of the source code and backup is the first thing if you have a service running at a critical level.

Make sure about your docker run command


I run my GitLab in docker with these command set:

[[email protected] ~]$ docker run --detach \
  --hostname gitlab.ercanermis.com \
  --publish 443:443 --publish 80:80 --publish 22:22 \
  --name gitlab \
  --restart always \
  --volume /srv/gitlab/config:/etc/gitlab \
  --volume /srv/gitlab/logs:/var/log/gitlab \
  --volume /srv/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce:latest

First of all, we need to get to know what’s the docker container name of the GitLab. In my setup, I’m using GitLab Community Edition and I gave the name as a “gitlab” for the docker. If you don’t know your gitlab docker’s name, there is an easy way to learn what it is.

[[email protected] ~]$ docker ps -a | grep gitlab-ce

The last column shows the docker container name. Here is the output:

9c787206fbda gitlab/gitlab-ce:latest "/assets/wrapper" 8 hours ago Up 8 hours (healthy) 0.0.0.0:22->22/tcp, 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp gitlab

Take a backup and know the backup path

Actually GitLab backup is really easy. Here is the command for the trigger backup mechanism of GitLab.

docker exec gitlab gitlab-rake gitlab:backup:create DIRECTORY=gitlab

Trigger command isn’t enough because you should take a backup of gitlab.rb and gitlab-secrets.json files are located in /srv/gitlab/config/ path. I prefer to copy (with cp command) these files to /srv/gitlab/data/backups/ path because gitlab-rake is exporting to the same directory.

My GitLab Docker Backup backup bash script looks like this:

#!/bin/bash
#Author: Ercan Ermis - https://ercanermis.com

docker exec gitlab gitlab-rake gitlab:backup:create DIRECTORY=gitlab
cp /srv/gitlab/config/gitlab.rb /srv/gitlab/data/backups/$(date +%F_%H-%M)_gitlab.rb
cp /srv/gitlab/config/gitlab-secrets.json /srv/gitlab/data/backups/$(date +%F_%H-%M)_gitlab-secrets.json

Which files do you have after run backup bash?

gitlab is generating the backup file name like1600262658_2020_09_16_13.3.6_gitlab_backup.tar It means epochtime_year_month_day_gitlabVersion_gitlab_backup.tar That’s the reason why I use the $date function when copying gitlab.rb and gitlab-secrets.json to the /srv/gitlab/data/backups/ folder.

I’m using aws S3 service to keeping my backups securely and redundant and when the backup is completed and ready in /srv/gitlab/data/backups/ folder, I’m syncing backed up files to s3 with aws s3 sync /srv/gitlab/data/backups/ s3://ercanermis-backup/gitlab/ command and deleting the backup file on the server.

You can also use your own solution to keep your backup redundant and securely like SMB, sFTP or another block storage solution from another provider.

Final: Let’s Automate Backup

Here is the final bash for automating GitLab Docker Backup located in /opt/gitlab-backup.sh

#!/bin/bash
#Author: Ercan Ermis - https://ercanermis.com

docker exec gitlab gitlab-rake gitlab:backup:create DIRECTORY=gitlab
cp /srv/gitlab/config/gitlab.rb /srv/gitlab/data/backups/$(date +%F_%H-%M)_gitlab.rb
cp /srv/gitlab/config/gitlab-secrets.json /srv/gitlab/data/backups/$(date +%F_%H-%M)_gitlab-secrets.json
aws s3 sync /srv/gitlab/data/backups/ s3://ercanermis-backup/gitlab/ && rm -rf /srv/gitlab/data/backups/*

After create your .sh file, you can use your crontab for trigger run your own /opt/gitlab-backup.sh

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • SSL CA Problem on CentOS7 Docker and Solution
  • What do I have?
  • I’m officially AWS Community Builder!
  • Deploy HA nginx to AWS ECS with Geolocation Routing via Terraform
  • Deploy nginx docker to AWS ECS with Terraform Automation
  • How to Install Node Exporter on Linux Server
  • FortiClient Problem on M1 MacBookPro Problem Solution
  • Connect your AWS to GCP with Terraform via IPSec Site-to-Site VPN
  • Google Cloud Platform Automation with Terraform Easily
  • How to secure your Amazon Web Services account
  • Install UGREEN USB Ethernet Adapter on macOS
  • Redirect 301 HTTPS on App Engine with nginx on Google Cloud Platform
  • Set two different Target Groups on AWS Load Balancer with Terraform
  • Extend your ec2 Linux disk without reboot on Amazon Web Services
  • Create a New Grant User on AWS RDS (MariaDB)
  • Amazon S3 CORS Settings with CloudFront on Amazon Web Services
  • Take your GitLab backup everyday if it works in Docker
  • Find large files in CentOS, ubuntu and MacOS easily
  • Fix “Error: rpmdb open failed” on CentOS or Amazon Linux 2
  • Error: No space left on the device when starting/stopping services only
  • Juniper SRX110H-VA VDSL2 Configuration Step by Step
  • Enable Logrotation for Docker Containers
  • Download specific file extension via wget easily on terminal
  • Find the exact size of certain files in Linux via terminal
  • Disable SELinux on CentOS 7 or CentOS 8
  • Hello Blog!

Tag Cloud

amazon linux 2 amazon web services automation aws aws community builder bug centos ci/cd cloud community connection container curl devops docker ec2 ecs fargate file size forticlient fortigate gcp gitlab google cloud platform ipsec isp juniper linux m1 macbookpro macos multi region network pipeline reliability route table security terraform turknet ubuntu vdsl2 vpn vpn problem vpn tunnel wget yum

Archive

  • March 2022 (1)
  • July 2021 (1)
  • May 2021 (6)
  • April 2021 (5)
  • February 2021 (1)
  • January 2021 (1)
  • September 2020 (2)
  • July 2020 (1)
  • April 2020 (1)
  • March 2020 (1)
  • February 2020 (1)
  • November 2019 (5)
©2022 Ercan Ermis | Built using WordPress and Responsive Blogily theme by Superb