zoukankan      html  css  js  c++  java
  • gitlab自动备份脚本auto_backup_to_remote

    #!/bin/bash
    
    # gitlab 服务器备份路径
    LocalBackDir=/var/opt/gitlab/backups
    
    # 远程备份服务器 gitlab备份文件存放路径
    RemoteBackDir=/root/gitlab_backup
    
    # 远程备份服务器 登录账户
    RemoteUser=root
    
    # 远程备份服务器 IP地址
    RemoteIP=(备份服务器B的地址,请你自行修改)
    
    #当前系统日期
    DATE=`date +"%Y-%m-%d"`
    
    #Log存放路径
    LogFile=$LocalBackDir/log/$DATE.log
    
    # 查找 gitlab本地备份目录下 时间为60分钟之内的,并且后缀为.tar的gitlab备份文件
    BACKUPFILE_SEND_TO_REMOTE=$(find $LocalBackDir -type f -mmin -60  -name '*.tar*')
    
    #新建日志文件
    touch $LogFile
    
    #追加日志到日志文件
    echo "Gitlab auto backup to remote server, start at  $(date +"%Y-%m-%d %H:%M:%S")" >>  $LogFile
    echo "---------------------------------------------------------------------------" >> $LogFile
    
    # 输出日志,打印出每次scp的文件名
    echo "---------------------The file to scp to remote server is: $BACKUPFILE_SEND_TO_REMOTE-------------------------------" >> $LogFile
    
    
    #备份到远程服务器
    scp $BACKUPFILE_SEND_TO_REMOTE $RemoteUser@$RemoteIP:$RemoteBackDir
    
    #追加日志到日志文件
    echo "---------------------------------------------------------------------------" >> $LogFile
    

    脚本

    #!/bin/bash
    #gitlab bakup_directory
    LocalBackDir=/var/opt/gitlab/backups
    #remote bakup_directory
    RemoteBackDir=/root/gitlab_backup
    #remote USER
    RemoteUser=root
    #remote IP
    RemoteIP=192.168.4.64
    #date
    DATE=`date +"%Y-%m-%d"`
    #log directory
    LogFile=$LocalBackDir/log/$DATE.log
    #Find the gitlab backup file with the suffix of .tar in the gitlab local backup directory for 60 minutes.
    BACKUPFILE_SEND_TO_REMOTE=$(find $LocalBackDir -type f -mmin -60  -name '*.tar*')
    #New log file
    touch $LogFile
    #Append log to log file
    echo "Gitlab auto backup to remote server, start at  $(date +"%Y-%m-%d %H:%M:%S")" >>  $LogFile
    echo "---------------------------------------------------------------------------" >> $LogFile
    #Output log, print out the file name of each scp
    echo "---------------------The file to scp to remote server is: $BACKUPFILE_SEND_TO_REMOTE-------------------------------" >> $LogFile
    #backup to remote server
    scp $BACKUPFILE_SEND_TO_REMOTE $RemoteUser@$RemoteIP:$RemoteBackDir
    #Append log to log file
    echo "---------------------------------------------------------------------------" >> $LogFile
    
  • 相关阅读:
    ExecuteScalar requires the command to have a transaction when the connection assigned to the command is in a pending
    如何从vss中分离程序
    String or binary data would be truncated
    the pop3 service failed to retrieve authentication type and cannot continue
    The POP3 service failed to start because
    IIS Error he system cannot find the file specified _找不到页面
    pku2575Jolly Jumpers
    pku2940Wine Trading in Gergovia
    pku3219二项式系数
    pku1029false coin
  • 原文地址:https://www.cnblogs.com/Doc-Yu/p/12085025.html
Copyright © 2011-2022 走看看