git备份脚本

#!/bin/bash
BASEDIR=/home/git/gitlab
DESTDIR=/home/silence/backups/gitlab
SRCDIR=$BASEDIR/tmp/backups
LOGFILE=$DESTDIR/gitback.log


#####begin backups#####
ts_format=`date +%Y-%m-%d %H:%M:%S`
timestamp=`date +%s`

test -f $LOGFILE || touch $LOGFILE
echo "" >> $LOGFILE
echo "" >> $LOGFILE
echo "BEGIN BACKUP @ $ts_format" >> $LOGFILE

######backup git#######
cd $BASEDIR && \
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production > /dev/null 2>&1
if [ $? -eq 0 ];then
  echo "backup successfully" >> $LOGFILE
else
  echo "backup failed. Errno: $?" >> $LOGFILE
fi

######clean git diskspace,keep 5days data######
file_counts=`ls $SRCDIR |wc -w`
if [ $file_counts -gt 5 ]; then
  rmlist=`ls -ltr $SRCDIR |grep -v ^total |head -n -5 |awk '{print $9}'`
  for rfile in $rmlist;do
    echo "remove $SRCDIR/$rfile to clean five days ago backupfiles" >> $LOGFILE
    rm $SRCDIR/$rfile
  done 
fi

######clean store dir space ,keep 3days data######

file_counts=`ls $DESTDIR |grep \.tar |wc -w`
if [ $file_counts -gt 2 ]; then
  rmlist=`ls -ltr $DESTDIR |grep \.tar |head -n -2 |awk '{print $9}'`
  for rfile in $rmlist;do
    echo "remove $DESTDIR/$rfile to clean 3 days ago backupfiles" >> $LOGFILE
    rm $DESTDIR/$rfile
  done 
fi

######cp the file #######
targetfile=$SRCDIR/`ls -ltr $SRCDIR | tail -n 1|awk '{print $9}'`
cp -af $targetfile $DESTDIR && echo "copy the file to destination directory successfully!" >> $LOGFILE

exit 0

 

转载于:https://www.cnblogs.com/silenceli/p/3507086.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值