#!/bin/bash

data=$(date "+%Y-%m-%d %H:%M:%S")
ip='192.168.10.14'
password='fan'
gitBak='/var/opt/gitlab/backups/'
delFile=`ls -l -crt  $gitBak/*.tar | awk '{print $9 }' | head -1`
count=`ls -l -crt  $gitBak/*.tar | awk '{print $9 }' | wc -l`

if [ $count -gt 4 ];then
  rm $delFile
  echo "$data -- delete $delFile" >> $gitBak/log.txt
fi
gitlab-rake gitlab:backup:create RAILS_ENV=production CRON=1
if [ $? -ne 0 ];then
  echo "$data -- 脚本执行失败" > $gitBak/log.txt
fi
copyFile=`ls -l -crt  $gitBak/*.tar | awk '{print $9 }' | tail -1`
/usr/bin/expect <<EOF
spawn scp -rp $copyFile root@$ip:/opt
expect {
"(yes/no)?" { send "yes\n"; expect "*assword:" { send "$password\n"}}
"*assword:" { send "$password\n" } 
}
expect eof
EOF

相关文章:

  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2022-12-23
  • 2023-01-25
  • 2022-12-23
猜你喜欢
  • 2022-02-04
  • 2022-12-23
  • 2021-11-29
  • 2021-11-21
  • 2021-06-28
  • 2021-07-13
  • 2022-12-23
相关资源
相似解决方案