linux shell 交互 git 批量备份

2019-08-20 10:47:32 浏览数 (2)

shell 交互 git 批量备份

安装expect

yum install expect

编写免输入脚本

代码语言:javascript复制
#!/usr/bin/expect
set timeout 10
set git_host [lindex $argv 0]
spawn  git clone  $git_host
expect "Username*"
send "mynamen"
expect "Password*"
send "mypasswordn"
expect "100%"
expect eof

批量脚本

代码语言:javascript复制
#!/bin/bash
cd /data/git && mkdir `date   %Y%m%d`  && cd `date   %Y%m%d`
if [ $? != 0 ];then
exit 1
fi
expect /data/git/gitpull.exp  https://git.1.git
expect /data/git/gitpull.exp https://git.2.git
expect /data/git/gitpull.exp https://git.3.git
......

定时备份

代码语言:javascript复制
0 3 * * * /data/git/git_clone.sh >  `date  %Y%m%d`.log 2>&1 &

结果

代码语言:javascript复制
4.6G    20190819
2.0M    20190819.log
28K    git_clone.sh
4.0K    gitpull.exp

定时删除

代码语言:javascript复制
0 5 * * * find /data/git/`date  %Y%m%d --date="-8 day"` |xargs rm > /dev/null 2>&1 &
0 6 * * * find /data/git/`date  %Y%m%d --date="-8 day"` |xargs rmdir > /dev/null 2>&1 &

0 人点赞