gitlab备份检查小脚本

直接上脚本

#!/bin/sh
source /etc/profile

# 定义邮件发送列表
maillist=(
  zisefeizhu@qq.com
)


# 清理缓存
clean_cache(){
 echo 1 > /proc/sys/vm/drop_caches
}

# 发送邮件函数
send_mail(){
  for mail in ${maillist[*]}; do
    echo -e "`date +%Y:%m:%d` backups success,
backups big $1,
host surplus resources $2,
memory  surplus $3 " | mail -s "${Title}" $mail
    # 尝试:每天在执行完毕备份后,清除缓存
    clean_cache
  done
}

# 定义需要检测的备份信息的时间
baklist=(
  `ls -lt /backups/16* | awk 'NR==1{print $7}'`
)

# 检测是否进行备份
for domain in ${baklist[*]};do
  echo "当前的时间: " `date`
  time=`date +%d`
  echo $domain
  backups=`ls -lth /backups/16* | awk 'NR==1{print $5}'`
  hoststorage=`df -h | grep  -w /dev/vda1 | awk '{print $5}'`

  echo y | cp /etc/gitlab/gitlab-secrets.json /etc/gitlab/gitlab.rb /backups/
  #内存使用情况
  memory=`free -h | awk 'NR==2{print $4}'`

  if [ $domain -lt 10 ]; then
     domai=0$domain
  else
     domai=$domain
  fi

  if [ $domai -eq $time ]; then
    Title="gitlab bak success"
    send_mail $backups $hoststorage  $memory
  else
    Title="gitlab bak failed"
    send_mail $backups $hoststorage  $memory
  fi
done
过手如登山,一步一重天
原文地址:https://www.cnblogs.com/zisefeizhu/p/14755984.html