Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ GitLab remote backup of Linux Shell Scripting     - Lazarus IDE Start Basics Tutorial (Linux)

- Oracle 11g to create a second instance on Linux (Database)

- Linux, MySQL / MariaDB Galera Cluster Setup Process (Database)

- MySQL thread cache thread_cache_size parameter optimization (Database)

- Oracle 11g maintenance partitions (eight) - Renaming Partitions (Database)

- MySQL completely uninstall and install Configuring Character Sets under Linux (Database)

- How to import JNI resulting .so libraries in Android Studio (Programming)

- Simple to use Linux GPG (Linux)

- 10046 trace only open for a particular SQL statement (Database)

- Internal class broadcasting needs public and static (Programming)

- Linux Telnet access Windows 7 configuration procedure (Linux)

- Nginx Beginner Guide (Server)

- VirtualBox installation enhancements let the mouse move and share CentOS 6.4 (Linux)

- crontab task scheduling Health Check (Linux)

- Java singleton mode (Singleton mode) (Programming)

- How to protect the Apache website under Linux system (Linux)

- The script Linux command (Linux)

- Linux, see picture not resolve the problem (Linux)

- Linux operating system security management skills (Linux)

- To install Samba server on CentOS 6.6 (Server)

 
         
  GitLab remote backup of Linux Shell Scripting
     
  Add Date : 2018-11-21      
         
       
         
  NOTE: Gitlab Git is a service program, there are Web graphical interface and a series of management tools, specific details can Google it.

This one can be said to be "Atlassian confluence remote backup methods Linux Shell Scripting," the companion. Their description and principles are the same and the previous is that the core principles are core dump, scp, ssh and find + rm, but there are also different.

1.Gitlab itself provides a better backup method, only a simple command, and it also supports remote backup (remote storage and cloud storage), for example, it can be stored on the aws s3.

2. This script runs on Gitlab server, not on the backup server, on a script is running on the backup machine.

Script 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.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 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.xxx.xxx
backup_server_ipaddress_private = xxx.xxx.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!"
     
         
       
         
  More:      
 
- To install HDRMerge 0.4.3 under ubuntu (Linux)
- Manually generate AWR reports (Database)
- S5PV210 development board for embedded development environment to build under Ubuntu (Linux)
- KVM virtualization of nested virtualization (Linux)
- HTML5 postMessage cross-domain data exchange (Programming)
- Composition and dynamic memory allocation C program (Programming)
- To install the latest version of Shotwell 0.18 under Ubuntu (Linux)
- 64-bit Oracle Linux recompiled Hadoop-2.2.0 (Server)
- Storm how to assign tasks and load balancing (Programming)
- Why do you need close contact Rust 1.0 (Programming)
- PXE + Kickstart automatically install CentOS 6.5 (Linux)
- CentOS minimal network is unavailable resolved (Linux)
- Forwarding module with Apache reverse proxy server (Server)
- Linux crontab commands and detailed usage examples (Linux)
- Check the Linux server performance with ten or so commands in a minute (Server)
- SELinux security permissions HTTP + PHP service changes (Server)
- Each catalog Detailed Linux (Linux)
- Sublime Text 3 practical functions and shortcut keys used to collect (Linux)
- How to install and configure a VNC server on CentOS 7.0 (Server)
- Introduction to thread pooling and simple implementation (Programming)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.