备份smgpSend_Log脚本

来源:http://www.weiruoyu.cn/?p=372


 
 
  1. vi smgpSend_Log_tar.sh

 
 
  1. #!/bin/sh

  2. dirname="$(date +%Y%m%d)"

  3. a1=/usr/local/smgpSend/smgpSend_Log/smgp_scanThread

  4. a2=scan_Info.txt.*

  5. a3=scan_Error.txt.*

  6. b1=/usr/local/smgpSend/smgpSend_Log/sendThread

  7. b2=sendThread_QueueError.txt.*

  8. b3=sendThread_sendTimeOut.txt.*

  9. b4=sendThread.txt.*

  10. c1=/usr/local/copydata/smgpSend_Log/

  11. c2=/usr/local/copydata/smgpSend_Log/smgp_scanThread_$dirname

  12. c5=/usr/local/copydata/smgpSend_Log/sendThread_$dirname

  13. c3=/var/log/filecopy/smgpSend_Log/

  14. c4=/var/log/filecopy/smgpSend_Log/smgp_scanThread_$dirname

  15. c6=/var/log/filecopy/smgpSend_Log/sendThread_$dirname

  16. d1=smgp_scanThread_$dirname

  17. d2=sendThread_$dirname

  18. #创建

  19. mkdir -p $c2

  20. mkdir -p $c5

  21. mkdir -p $c3

  22. #移动

  23. cd $a1

  24. mv $a2 $a3 $c2

  25. cd $b1

  26. mv $b2 $b3 $b4 $c5

  27. #压缩

  28. cd $c1

  29. tar -zcvf $d1.tar.gz $d1 >> $c4

  30. tar -zcvf $d2.tar.gz $d2 >> $c6

  31. #删除

  32. echo "rm start" >> $c4

  33. echo "rm start" >> $c6

  34. rm -rvf $d1 >> $c4

  35. rm -rvf $d2 >> $c6

==================上面是最新的,下面适用于保留几天日志文件================================

最近写了一个备份脚本,把上个月的日志脚本备份,难点在于获取上月的日期,并进行字符串拼接

vi smgpSend_Log_tar.sh

 
 
  1. #!/bin/sh

  2. #截取上个月的日期

  3. my_year=`date |awk '{print $1 $2}'|cut -f 1 -d '年'`

  4. my_mouth=`date |awk '{print $1 $2}'|cut -f 2 -d '年'|cut -f 1 -d '月'`

  5. #拼接字符串

  6. yes_mouth=$(($my_mouth-1))

  7. #year_mounth=$my_year-$my_mouth

  8. year_mounth=$my_year-0$yes_mouth

  9. #全区变量

  10. d=/usr/local/copydata/smgpSend_Log/

  11. d5=/var/log/filecopy/smgpSend_Log/

  12. mkdir -p $d5

  13. a0="sendThread"

  14. a1="sendThread.txt."

  15. a2="sendThread_QueueError.txt."

  16. a3="sendThread_sendTimeOut.txt."

  17. b0=$a0"_"$year_mounth

  18. b1=$a1$year_mounth"-*"

  19. b2=$a2$year_mounth"-*"

  20. b3=$a3$year_mounth"-*"

  21. b7=$a0"_"$year_mounth".log"

  22. d1=$d$b0

  23. d3=$d5$b7

  24. a4="scan_Info.txt."

  25. a5="scan_Error.txt."

  26. a6="smgp_scanThread"

  27. b4=$a4$year_mounth"-*"

  28. b5=$a5$year_mounth"-*"

  29. b6=$a6"_"$year_mounth

  30. b8=$a6"_"$year_mounth".log"

  31. d2=$d$b6

  32. d4=$d5$b8

  33. cd /usr/local/smgpSend/smgpSend_Log/sendThread

  34. mkdir -p $d1

  35. mv $b1 $d1

  36. mv $b2 $d1

  37. mv $b3 $d1

  38. cd /usr/local/smgpSend/smgpSend_Log/smgp_scanThread

  39. mkdir -p $d2

  40. mv $b4 $d2

  41. mv $b5 $d2

  42. cd $d

  43. tar -zcvf $b0.tar.gz $b0 >> $d3

  44. tar -zcvf $b6.tar.gz $b6 >> $d4

  45. rm -rv $b0 >> $d3

  46. rm -rv $b6 >> $d4

  47. date >> $d3

  48. date >> $d4

添加每月5号执行

 
 
  1. [root@localhost bin]# crontab -e

添加

 
 
  1. 15 1 5 * * /backup/bin/smgpSend_Log_tar.sh


你可能感兴趣的:(备份,脚本)