mò Tã¸Ec@sŒdZdkZdkZdkZdkZdklZdklZy dk Z Wnje j o^ei i dƒoei i dƒn(ei i dƒoei i dƒndk Z nXdkZ dklZd klZd klZd ed „Zd efd„ƒYZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zdeedd„Z!e"djo eƒndS(sRSimple script for repairing damaged FileStorage files. Usage: %s [-f] [-v level] [-p] [-P seconds] input output Recover data from a FileStorage data file, skipping over damaged data. Any damaged data will be lost. This could lead to useless output if critical data is lost. Options: -f Overwrite output file even if it exists. -v level Set the verbosity level: 0 -- show progress indicator (default) 1 -- show transaction times and sizes 2 -- show transaction times and sizes, and show object (record) ids, versions, and sizes -p Copy partial transactions. If a data record in the middle of a transaction is bad, the data up to the bad data are packed. The output record is marked as packed. If this option is not used, transactions with any bad data are skipped. -P t Pack data to t seconds in the past. Note that if the "-p" option is used, then t should be 0. Important: The ZODB package must be importable. You may need to adjust PYTHONPATH accordingly. N(sunpack(sloadstZODBt.sFileStorage.pys..(su64(sRecordIterator(s TimeStamptcCsP|oti|dIJn|otittidIJntidƒdS(Ns ii(tmesstsyststderrtshow_docstringt__doc__targvtexit(RR((t-/data/zmath/zope/lib/python/ZODB/fsrecover.pytdieZs t ErrorFoundcBstZRS(N(t__name__t __module__(((R R ascGst||ƒ‚dS(N(R Rtargs(RR((R terrordsc Cs–|i|ƒ|idƒ}t|ƒdjo t‚ntd|ƒ\} }} }} }t|ƒ}||d|jotd|ƒn|d|| |jotd||ƒn|o0| |jo#tdt| ƒt|ƒ|ƒn| djot||||ƒt‚n| djotd | |ƒn|}||}| d joU|i|ƒ|idƒ}||jotd |ƒn|d}|d| fSn|d|| |}|i|ƒ} |i| ƒ} |o-yt|i|ƒƒ}Wqh}qXnh}t| | | | |||||ƒ }|}|i|ƒ|idƒ}||jotd |ƒn|d7}||| fS( Nis >8s8scHHHisbad transaction length at %ss%invalid transaction length, %s, at %ss$time-stamp reducation %s < %s, at %stcs upsinvalid status, %r, at %stus%inconsistent transaction length at %ss/redundant transaction length check failed at %s(tftseektpostreadthtlentEOFErrortunpackttidtstltstatustultdlteltu64ttlt file_sizeRtltidttruncatetoutpttposttendtNonetusert descriptiontloadstetRecordIteratortresult(RRR#R&R$R R/R(R"RRRR+R*R-RRRR'((R tread_txn_headergsX  ! #            cCs|d}x5|d|atiitƒo|d7}q Pq Wttdƒ}t||||ƒ|i |ƒ|i ƒdS(s0Copy data from pos to end of f to a .trNNN file.iis.tr%dtwbN(tiR&t_trnametostpathtexiststopenttrtcopyRR#RRtclose(RRR#R&R2R8((R R%¢s cCslxe|o]|idƒ}|pPnt|ƒ|jo|| }n|i|ƒ|t|ƒ8}qWdS(Ni (tntsrcRtbufRtdsttwrite(R<R>R;R=((R R9µs cCsÝxÖ|i|ƒ|idƒ}|pdSnd}x|id|ƒ}|djo|t|ƒ7}Pn|d}|t|ƒdjo||7}Pnt |||d!ƒ}||jo||dSq7q7WqWdS(s÷Return a potential transaction location following pos in f. This routine scans forward from pos looking for the last data record in a transaction. A period '.' always occurs at the end of a pickle, and an 8-byte transaction length follows the last pickle. If a period is followed by a plausible 8-byte transaction length, assume that we have found the end of a transaction. The caller should try to verify that the returned location is actually a transaction header. ii iRiN( RRRRtdatatstfindtlRR!R"(RRR"RCRAR@((R tscan¿s*      cCs0|dodGn |ddGtiiƒdS(NiRi (R2Rtstdouttflush(R2((R t iprogressás  cCs%xt|ƒD]}t|ƒq WdS(N(trangetpR2RG(RIR2((R tprogressès c CsCy#titiddƒ\} }Wn.tij o}tt|ƒdt ƒnXt |ƒdjotddt ƒn|\}}t }}d}d} x†| D]~\}}|djot|ƒ}q¤|djo t }q¤|d jo t }q¤|d jotiƒt|ƒ} q¤q¤Wt|||||| ƒdS( Nisfv:pP:Ris!two positional arguments requiredis-vs-ps-fs-P(tgetoptRRtoptsRRtmsgR tstrtTrueRtinpR&tFalsetforcetpartialtverboseR)tpacktopttvtintttimetfloattrecover( RWRRRTRPRSR&RMRVRRLRU((R tmainìs*#         icCsdG|GdG|GHtii|ƒo| otd|ƒnt|dƒ}|i dƒt i i jotdƒn|i ddƒ|iƒ} t i i |d d ƒ}d}d }d}d}d }d}xÇ|o¿y%t||| ||ƒ\}}} Wntj oPn{ttfj o ‚n`tj oS}d G|GH|pt"|ƒnt#||ƒ}|d jo d G|GHqÒqÒnX| }|djo|||}|}qÒn|}|i} |djot$| ƒ}ntt$| ƒ}||jo:|od||fGHnd}|i&|ƒ}| } n!|}|pd|GHd }n|i'|| |i(ƒ|o/dG|G|G|d joHnt)i*i+ƒnd} y¢x›|D]“} |d joK| i.djo d}nt0| i.ƒ}dt1| i2ƒ|| i3fGHn|i4| i2| i| i.| i3| i5|ƒ| d 7} q·WWnÉttfj o ‚nætj o¢}|o>| o7d|_7|i8|ƒ|i9|ƒ|o dGHqÏn|i:|ƒdG|GH|pt"|ƒnt#||ƒ}|d jo d G|GHqRn9X|i8|ƒ|i9|ƒ|odGHt)i*i+ƒn|p;|d| }x*||jo|d }t<|ƒqjWqÒqÒW| ||i=}d|GH|o d|GHn|dj o&dGHdk@lA} |i?|| ƒn|iBƒdS(Nt Recoveringtintos %s existstrbisinput is not a file storageiitcreateilserror reading txn header:slooking for valid txn header atsTime stamps out of order %s, %ssTime stamps back in order %stbegintbps %7d %s %sRIRSserror copying transaction:tfinishls! %s bytes removed during recoverys0%s bytes of undone transaction data were skippeds Packing ...(s referencesf(CRPR&R4R5R6RRR R7RRRt FileStoragetpacked_versionRttellR#tofsR)t_tstoktprog1tundoneRR$R0tnposttxnRRtKeyboardInterruptt SystemExitt ExceptionterrRTRJRDt TimeStampttt laterThant tpc_beginRRRERFtnrectrR@RCRR!toidtversiontrestoretdata_txnRSt_statusttpc_votet tpc_finisht tpc_aborttprogRGt_postbadRUtZODB.serializet referencesfR:(RPR&RTRSRRRURjRmRR#RwR„RRvR$RhR€RiRqRRCRgR‚RkRlRs((R R[sÒ %               "$               t__main__(#RRR4RKRYtstructRtcPickleR,Rt ImportErrorR5R6tappendtZODB.FileStoraget ZODB.utilsR!R.tpersistent.TimeStampRrRQR RpR RR0R%R9RDRGRJR\R)R[R (RDR!RGR[R0R.RKR\R%RrRYR RRRJR9RR RR,R4((R t?5s>             ;  "   €