#!/bin/bash
#!/usr/tcl/bin/expect
sudo docker exec -it gitlab_gitlab_1 /bin/bash -c "/opt/gitlab/bin/gitlab-rake gitlab:backup:create"
sleep 30m
filename=`(ls -l /opt/dockerData/gitlab/data/backups/*.tar | tail -n 1 | awk '{print $9}')`
a=/gitlab/data/backups/$filename
b=/opt/git_backup
ip=1.1.1.1
port=22
passwd=password
/bin/rpm -qa|/bin/grep -q expect
if [ $? -ne 0 ];then
echo "please install expect"
exit
fi
#if [ $# -ne 5 ];then
# echo "must 5 parameter,1:source file,2:object file,3:object ip 4:object port,5:passwd"
# exit
#fi
expect -c "
spawn scp -P $port $a root@$ip:$b
expect {
\"*assword\" {set timeout 300; send \"$passwd\r\";}
\"yes/no\" {send \"yes\r\"; exp_continue;}
}
expect eof"