Gitlab remote backup of Linux shell scripts

Source: Internet
Author: User
Tags atlassian confluence

Note: Gitlab is a git service program that has a Web graphical interface and a range of management tools, specifically detailed to Google it.

This can be said to be the last "Linux shell script Atlassian Confluence Remote backup method" of the sister article. Its description and principle are the same as the previous one, and its core principles are cores dump, SCP, SSH and FIND+RM, but there are also different.

The 1.Gitlab itself provides a good backup method, just as simple as a command, and it also supports remote backup (Remote Storage and cloud storage), such as it can be stored on AWS S3.

2. This script runs on the Gitlab server, not on the standby, and the previous script is running on the standby machine.

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) # &NBSP;|&NBSP;&NBSP;|&NBSP;&NBSP:---------- day of month  (1 - 31) # |  &NBSP;|&NBSP;&NBSP;|&NBSP;&NBSP:------- month  (1 - 12)  OR jan,feb,mar,apr  # |  |  |  | &nbsp.---- 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.xxx.xxx                 xxx.xxx.xxx.xxx#            |         ssh tunnel           |#    xxx.xxx.xxx.xxx   <==========>  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  1gitlab_internal_backup_directory=/data/var/opt/gitlab/backups# if you have both  wan ip and lan ip, you&Nbsp;can fill it with all, if you have one ip, you can  fill it just with lan ipbackup_server_ipaddress_public=xxx.xxx.xxx.xxxbackup_ Server_ipaddress_private=xxx.xxx.xxx.xxx# select lan ip first for transmission  speedbackup_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_hostnamebackup_path=/data/gitlab_backup_directorybackup_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=productionecho  "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 [email protected] $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 [email protected] $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& nbsp;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   [email protected] $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!  "

Reference:
Gitlab.org/gitlab Community edition/backup Restore Https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/raketas Ks/backup_restore.md
Gitlab.org/gitlab ci/backup Restore Https://gitlab.com/gitlab-org/gitlab-ci/blob/master/doc/raketasks/backup_rest Ore.md

Tag:gitlab backup script, Gitlab backup method, how to back up Gitlab, remote backup gitlab, remote backup script

--end--

This article is from "Communication, My Favorites" blog, please make sure to keep this source http://dgd2010.blog.51cto.com/1539422/1686043

Gitlab remote backup of Linux shell scripts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.