################################################################################################################################################################################################################################################################################# ################################################ data files By the day increment backup script # Function: Press Mtime to put the previous day's file COPY / LINK backup directory, do not delete the original file # execution frequency: per day execution (crontab) ############### ######################################################################################################################################################################################################################################################################################################## Function ############# Date = YYYMMDD #USAGE: Command Date Days getprevdate () {str = $ 1 days = $ 2 yy = `Echo $ STR | CUT -C 1-4` mm = `Echo $ Str | Cut-C 5-6` DD =` Echo $ STR | CUT-C 7-8` SAV_DD = $ DAYS Days = `EXPR $ DAYS - $ DD` While [$ days -ge 0] do mm = `EXPR $ mm - 1` [$ mm -eq 0] && mm = 12 && yy =` expr $ yy - 1` AAA = `CAL $ mm $ yy` bbb =` Echo $ AAA | awk '{print $ NF} '`days =` EXPR $ days - $ bbb` DONE DD = `EXPR 0 - $ days` expr $ dd:" ^. $ "> / Dev / null && dd = 0 $ DD EXPR $ mm:" ^ $ "> / dev / null && mm = 0 $ mm Echo $ yy $ mm $ dd} # ====================== main ==== ============== # TodayDate = `Date" % Y% M% D "` # backup data source directory srcpath = "/ bill / data / pppath / bak /" # Backup purpose Directory BakPath = "/ Bill / Backup / CDR / $ {TodayDate} /" log file directory log file directory logPath = "/ bill / backup / logpath / cdr /" # Process log file name logfile = "/ bill / backup / L OGPATH / CDR / $ {TodayDate} .log "
IF [! -D $ BAKPATH]; THEN MKDIR $ BAKPATH; Fi # Generates Time Stamp File, Accurate To BEGINDATE = "` getPrevdate $ {TodayDate} 1`0001 "enddate =" `GetPrevdate $ {TodayDate} 2`0001" #for test # begindate = "200412260001" # enddate = "200412270001" Touch -t "$ {begindate}" / billouch -t "$ {enddate}" / bill / backup / script / endfile
ECHO "****************************************************** *********** "> $ logfile echo" The CDR Backup process is starting at [`date`] >> $ logfile echo" Backup File's Mtime Between [$ Begindate - $ ENDDATE ">> $ logfile echo "srcpath = / bill / data / pppath / bak /" >> $ logfile echo "Bakpath = / Bill / Backup / CDR / $ {TodayDate} /" >> $ logfile echo "Process Log Is Written in $ logfile ">> $ logfile echo" Backup Files List as: ">> $ logfile # In the source directory finds a file that meets the condition and copy it to the backup directory Find $ srcpath / (-newer / bill / backup / script / beginfile -a! -newer / bill / backup / script / endfile /) -Depth -print | xargs cpcdr $ BAKPATH $ logfile;
Echo "Backup CDR Completed AT [` Date`]. ">> $ logfile # Check the processing log to see if there is an error awk 'begin {CNT = 0;} {IF ($ 1 ~ / error /) CNT ;} END {IF CNT == 0) Printf ("backup successed./n"); Else Printf ("there is% d error found.please check it./n",cnt);} '$ logfile >> $ logfile echo" ** *********************************************************** ******* >> $ logfile
Prendate = `getPrevdate $ {TODAYDATE} 31` # Echo $ prendatecd $ logPath # Delete 31 days ago Log file while read file; do if [-f $ file]; the RM -F` Echo $ file | awk '{ix (SubStr ($ 0, 1, 8) <= '$ prendate') Print ($ 0)} '`fidone <> $ Logfile Else Echo "CP $ x $ BAKPATH SUCCESSED." >> $ logfile fidone