Application Data Files and log backup scripts on unix

Source: Internet
Author: User

Application Data Files and log backup scripts on unix #! /Usr/bin/bash ############################### regular Backup Communication data and logs of business and data processing processes # Author: xxx # Creation Time: 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/'tarendstrpolic'.tar.bz2' # delete data file from saveDataCycle days beforesaveDataCycle = 30 Def tarBackFile (tarFileName, compressDir): archive = tarfile. open (tarFileName, 'W: bz2 ') archive. debug = 1archive. add (compressDir) archive. close () def backup_cs (archDate): for file in OS. listdir (cs_dataDir + 'rcv '): if archDate = file: t_tarFileName = archDate +'-RCV '+ tarEndStrtarBackFile (t_tarFileName, cs_dataDir + 'rcv/' + archDate) OS. rename (t_tarFileName, arch_dir + 'biiergsccs/'+ t_tarFileName) shutil. rmtree (cs_dataDi R + 'rcv/'+ archDate) for file in OS. listdir (cs_dataDir + 'snds '): if archDate = file: t_tarFileName = archDate +'-SNDS '+ tarEndStrtarBackFile (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 '+ tarEndStrtarBackFile (t_tarFi LeName, 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' + tarEndStrtarBackFile (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 + 'repackage'): if archDate = file: t_tarFileName = archDate + '-repackage' + tarEndStrtarBackFile (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' + tarE NdStrtarBackFile (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' + tarEndStrtarBackFile (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' + tarEndStrt_compressLogFiles = ''for file in OS. listdir (ds_logDir): if file. count (archDate)> 0: t_compressLogFiles = t_compressLogFiles + ds_logDir + file + ''if t_compressLogFiles! = '': OS. system ('tar cvf' + t_tarLogFileName + ''+ t_compressLogFiles) OS. rename (t_tarLogFileName, arch_dir + 'biiergscds/'+ t_tarLogFileName) for file in OS. listdir (ds_logDir): if file. count (archDate)> 0: OS. remove (ds_logDir + file) def backup_bs (archDate1, archDate2): for file in OS. listdir (bs_dataDir): if file. count (archDate1)> 0: t_tarFileName = archDate2 + '-tmp-' + file + tarEndStrtarBackFile (t_tarFileName, bs_dataDir + File) OS. rename (t_tarFileName, arch_dir + 'biiergscbs/'+ t_tarFileName) shutil. rmtree (bs_dataDir + file) t_tarFileName = archDate2 + '-a_ SC' + tarEndStrt_compressFiles = ''for file in OS. listdir (bs_dataDir + 'A _ SC '): if file. count (archDate2)> 0: t_compressFiles = t_compressFiles + bs_dataDir + 'A _ SC/'+ file + ''if t_compressFiles! = '': OS. system ('tar cvf' + t_tarFileName + ''+ t_compressFiles) OS. rename (t_tarFileName, arch_dir + 'biiergscbs/'+ t_tarFileName) for file in OS. listdir (bs_dataDir + 'A _ SC '): if file. count (archDate2)> 0: OS. remove (bs_dataDir + 'A _ SC/'+ file) t_tarLogFileName = archDate2 +'-bslog' + tarEndStrt_compressLogFiles = ''for file in OS. listdir (bs_logDir): if file. count (archDate2)> 0: t_compressLogFiles = t_compressLogFiles + bs_logDi R + file + ''if t_compressLogFiles! = '': OS. system ('tar cvf' + t_tarLogFileName + ''+ t_compressLogFiles) OS. rename (t_tarLogFileName, arch_dir + 'biiergscbs/'+ t_tarLogFileName) for file in OS. listdir (bs_logDir): if file. count (archDate2)> 0: OS. remove (bs_logDir + file) def getDateStr (formatStr): archDateTime = datetime. datetime. now ()-datetime. timedelta (days = saveDataCycle) archDate = archDateTime. date () return archDate. strftime (formatStr) if _ name _ = '_ main _': dateStr = getDateStr ('% Y % m % D') backup_cs (dateStr) backup_ds (dateStr) # spilt Ex: 2013_6_20dateStrNew = dateStr [0: 4] + '_' + dateStr [4: 6]. lstrip ('0') + '_' + dateStr [6:8]. lstrip ('0') backup_bs (dateStrNew, dateStr)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.