GitLab remote backup of Linux Shell scripts
Note: Gitlab is a Git service program with a Web GUI and a series of management tools. For details, refer to Google it.
This article is a companion article in "Atlassian confluence remote backup method for Linux Shell scripts. Its Description and principles are the same as those in the previous article. The core principles are core dump, scp, ssh, and find + rm, but they are also different.
1. Gitlab provides a better backup method, which is just a simple command and supports remote backup (remote storage and cloud storage). For example, Gitlab can be stored on aws s3.
2. This script runs on the Gitlab server and is not on the slave server.
The script is as follows:
#! /Bin/bash
# This shell script will execute on A Server
# SHELL =/bin/bash
# PATH =/sbin:/bin:/usr/sbin:/usr/bin
# MAILTO = root
# HOME =/
# For details see man 4 crontabs
# Example of job definition:
#. ---------------- Minute (0-59)
# |. ----------- Hour (0-23)
# |. ---------- Day of month (1-31)
# |. ------- Month (1-12) OR jan, feb, mar, apr...
# |. ---- Day of week (0-6) (Sunday = 0 or 7) OR sun, mon, tue, wed, thu, fri, sat
# |
# ***** User-name command to be executed
# M h dom mon dow command
# Execute on 11: 59 per Sunday
#59 11 ***/0 $0>/tmp/gitlab_backup _ $ (date-d "yesterday" + "% Y % m % d % H % M % S "). log
# Execute on 23:59 per day
#59 23 *** $0>/tmp/gitlab_backup _ $ (date-d "yesterday" + "% Y % m % d % H % M % S"). log
# Xxx. xxx
# | Ssh tunnel |
# Xxx. xxx <==========> xxx. xxx
# |
# ---------- + ----------------------------- + -------
# |
# + ----- ++ ------ +
# | A | B |
# + ----------- ++ ------------- +
# Gitlab server backups clinet
#
# A and B passed ssh Authentication
# A --> B: ssh lan_ip
# A --> B: ssh wan_ip
# B --> A: ssh lan_ip
# B --> A: ssh wan_ip
# A --> A: ssh lan_ip
# A --> A: ssh wan_ip
# B --> B: ssh lan_ip
# B --> B: ssh wan_ip
# Run as root, of course.
[$ UID-eq 0] | (echo "Must be root to run this script." & exit 1)
Save_days = 5
[$? -Eq 1] & exit 1
Gitlab_internal_backup_directory =/data/var/opt/gitlab/backups
# If you have both wan ip and lan ip, you can fill it with all, if you have one ip, you can fill it just with lan ip
Backup_server_ipaddress_public = xxx. xxx
Backup_server_ipaddress_private = xxx. xxx
# Select lan ip first for transmission speed
Backup_server_hostname =$ {backup_server_ipaddress_private:-$ backup_server_ipaddress_public}
Backup_server_ssh_username = root
# Backup_server_ssh_port =$ (awk '/Port/{print $2}'/etc/ssh/sshd_config)
Backup_server_ssh_port =$ (netstat-anop | awk '/sshd/&/LISTEN/{print $4}' | awk-F': ''{print $2 }')
Backup_server_ssh_hostname = $ backup_server_hostname
Backup_path =/data/gitlab_backup_directory
Backup_path_time_uniq =$ (date-d "yesterday" + "% Y % m % d ")
[-D $ backup_path/$ backup_path_time_uniq] | mkdir-p $ backup_path/$ backup_path_time_uniq
# Sudo-u gitlab_ci-H bundle exec rake backup: create RAILS_ENV = production
Echo "GitLab is executing backup operation, please hold on! "
/Data/opt/gitlab/bin/gitlab-rake gitlab: backup: create> $ backup_path/$ backup_path_time_uniq/$ (date-d "yesterday" + "% Y % m % d "). log 2> & 1
[$? -Ne 0] & echo "Local backup failed! "& Exit 1; echo" Local backup successfully! "
Backuped_tar_file = 'awk'/gitlab_backup.tar/{print $4} '$ backup_path/backup_path_time_uniq/$ (date-d "yesterday" + "% Y % m % d"). Log'
[-F $ gitlab_internal_backup_directory/$ backuped_tar_file] & echo "Find backuped tar file successfully! "
Ssh $ backup_server_ssh_username @ $ backup_server_ssh_hostname [-d $ backup_path/$ backup_path_time_uniq] | mkdir-p $ backup_path/$ backup_path_time_uniq
[$? -Ne 0] & echo "Remote backup directory creation failed! "& Exit 1; echo" Remote backup directory creation successfully! "
Scp-P $ port $ gitlab_internal_backup_directory/$ backuped_tar_file $ backup_server_ssh_username @ $ backup_server_ssh_hostname: $ backup_path/$ backup_path_time_uniq
[$? -Ne 0] & echo "Remote backup transmission failed! "& Exit 1; echo" Remote backup transmission successfully! "
Find $ gitlab_internal_backup_directory-mtime + $ save_days-exec rm-rf {}\;
[$? -Ne 0] & echo "Local expired backup remove skipped! "; Echo" Local expired backup remove successfully! "
Find $ backup_path-mtime + $ save_days-exec rm-rf {}\;
[$? -Ne 0] & echo "Local expired tempdir remove skipped! "; Echo" Local expired tempdir remove successfully! "
Ssh $ backup_server_ssh_username @ $ backup_server_ssh_hostname find $ backup_path-mtime + $ save_days-exec rm-rf {}\;
[$? -Ne 0] & echo "Remote expired backup remove skipped! "; Echo" Remote expired backup remove successfully! "
Refer:
Refer:
GitLab.org/GitLab Community Edition/Backup restore https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/raketasks/backup_restore.md
GitLab.org/GitLab CI/Backup restore https://gitlab.com/gitlab-org/gitlab-ci/blob/master/doc/raketasks/backup_restore.md
Tag: Gitlab backup script, Gitlab backup method, how to back up Gitlab, remote backup Gitlab, remote backup script
-- End --
For more GitLab tutorials, see the following:
Install GitLab on Ubuntu 12.04
GitLab 5.3 upgrade considerations
Deploy GitLab on CentOS (self-managed Git project repository)
Install GitLab 6.0.2 on RHEL6/CentOS6/ScientificLinux6
CentOS 6.5 GitLab installation tutorial and Related Problems
GitLab details: click here
GitLab: click here
This article permanently updates the link address: