日期:2014-05-16  浏览次数:20780 次

unix上应用程序数据文件及日志备份脚本
#!/usr/bin/bash

##############################
#定期备份通讯、业务、数据处理进程的数据及日志
#作者:xxx
#创建时间:2013/7/4
#Ex: >chown a+x {/afc/timingDelDataLog.sh,/afc/timingDelDataLog.py}
#    >export EDITOR=vi
#	   >crontab -e
#	    30 0 * * * /afc/timingDelDataLog.sh&
#    >svcadm disable cron
#    >svcadm enable cron
##############################

cd /afc/
./timingDelDataLog.py >>/afc/log/timingDelDataLog.log
#!/usr/bin/python
#author:weihua.liu
#date:2013/07/03

#from datetime import *
import os,tarfile,bz2,shutil,time,datetime

arch_dir = '/afc/arch/'
cs_dataDir = '/afc/data/biiergsccs/'
bs_dataDir = '/afc/data/biiergscbs/'
ds_dataDir = '/afc/data/biiergscds/'
ds_logDir = '/afc/log/biiergscds/'
bs_logDir = '/afc/log/biiergscbs/'
tarEndStr='.tar.bz2'

#delete data file from saveDataCycle days before
saveDataCycle=30

def tarBackFile(tarFileName,compressDir):
	archive = tarfile.open(tarFileName,'w:bz2')
	archive.debug=1
	archive.add(compressDir)
	archive.close()

def backup_cs(archDate):
	for file in os.listdir(cs_dataDir+'RCV'):
		if archDate == file:
			t_tarFileName=archDate+'-rcv'+tarEndStr
			tarBackFile(t_tarFileName,cs_dataDir+'RCV/'+archDate)
			os.rename(t_tarFileName,arch_dir+'biiergsccs/'+t_tarFileName)
			shutil.rmtree(cs_dataDir+'RCV/'+archDate)

	for file in os.listdir(cs_dataDir+'SNDS'):
		if archDate == file:
			t_tarFileName=archDate+'-snds'+tarEndStr
			tarBackFile(t_tarFileName,cs_dataDir+'SNDS/'+archDate)
			os.rename(t_tarFileName,arch_dir+'biiergsccs/'+t_tarFileName)
			shutil.rmtree(cs_dataDir+'SNDS/'+archDate)

	for file in os.listdir(cs_dataDir+'SNDF'):
		if archDate == file:
			t_tarFileName=archDate+'-sndf'+tarEndStr
			tarBackFile(t_tarFileName,cs_dataDir+'SNDF/'+archDate)
			os.rename(t_tarFileName,arch_dir+'biiergsccs/'+t_tarFileName)
			shutil.rmtree(cs_dataDir+'SNDF/'+archDate)

def backup_ds(archDate):
	for file in os.listdir(ds_dataDir+'NORMAL'):
		if archDate == file:
			t_tarFileName=archDate+'-normal'+tarEndStr
			tarBackFile(t_tarFileName,ds_dataDir+'NORMAL/'+archDate)
			os.rename(t_tarFileName,arch_dir+'biiergscds/'+t_tarFileName)
			shutil.rmtree(ds_dataDir+'NORMAL/'+archDate)

	for file in os.listdir(ds_dataDir+'REPACK'):
		if archDate == file:
			t_tarFileName=archDate+'-repack'+tarEndStr
			tarBackFile(t_tarFileName,ds_dataDir+'REPACK/'+archDate)
			os.rename(t_tarFileName,arch_dir+'biiergscds/'+t_tarFileName)
			shutil.rmtree(ds_dataDir+'REPACK/'+archDate)

	for file in os.listdir(ds_dataDir+'REPEAT'):
		if archDate == file:
			t_tarFileName=archDate+'-repeat'+tarEndStr
			tarBackFile(t_tarFileName,ds_dataDir+'REPEAT/'+archDate)
			os.rename(t_tarFileName,arch_dir+'biiergscds/'+t_tarFileName)
			shutil.rmtree(ds_dataDir+'REPEAT/'+archDate)

	for file in os.listdir(ds_dataDir+'ERROR'):
		if archDate == file:
			t_tarFileName=archDate+'-error'+tarEndStr
			tarBackFile(t_tarFileName,ds_dataDir+'ERROR/'+archDate)
			os.rename(t_tarFileName,arch_dir+'biiergscds/'+t_tarFileName)
			shutil.rmtree(ds_dataDir+'ERROR/'+archDate)

	t_tarLogFileName=archDate+'-dslog'+tarEndStr
	t