#!/bin/sh
work_dir=$(cd `dirname $0`;pwd)
#work_dir=/root
backup_dir="ea_poc"
#获取开始时间
NOW=$(date "+%Y%m%d%H%M%S")

usage(){
  echo "sh devops_bak.sh"
}

backup(){
    backup_ts=`date +%Y%m%d`
    echo [$(date +%Y-%m-%d#%H:%M:%S)]-------------BEGIN------------
    [ ! -d $BACKUP/$NOW ] && mkdir -p $BACKUP/$NOW
    tar -czvf $work_dir/${backup_dir}_${backup_ts}.tgz ${backup_dir}
    echo [$(date +%Y-%m-%d#%H:%M:%S)]------------COMPLETE----------

    echo [$(date +%Y-%m-%d#%H:%M:%S)]----------删除历史备份--------
    rm -f $work_dir/${backup_dir}_$(date -d -60day +%Y%m%d).tgz
    echo [$(date +%Y-%m-%d#%H:%M:%S)]----------删除成功------------
}

if [ $# -eq 0 ];then
    backup
else
    case "$1" in
        "backup")
            backup
        ;;
        *)
            usage
        ;;
    esac
fi
