#!/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