zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    上传和下载附件功能
    C#小常识,持续更新..
    动态添加HTML表单控件,无(runat="server")
    Excel技巧 持续更新..
    JS函数集锦 持续更新..
    JS 函数 检验输入是否为数字类型,正整数
    存储过程 游标 事例
    Sql 查询语句中的类型转换
    shell 计数脚本
    centos 获取文件的创建时间
  • 原文地址:https://www.cnblogs.com/silenceli/p/3507086.html
Copyright © 2011-2022 走看看