....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 66.235.200.170  /  Your IP : 13.59.46.202
Web Server : Apache
System : Linux gator4410.hostgator.com 5.14.0-162.23.1.9991722448259.nf.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 31 18:11:45 UTC 2024 x86_64
User : bmgxafte ( 1214)
PHP Version : 8.2.28
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /scripts/backups_create_metadata
#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/backups_create_metadata         Copyright 2022 cPanel, L.L.C.
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

################################################################################

package scripts::backups_create_metadata;

use strict;
use warnings;

use Cpanel::Backup::Config         ();
use Cpanel::Backup::Metadata       ();
use Cpanel::Backup::StreamFileList ();
use Cpanel::Config::LoadCpConf     ();
use Cpanel::ConfigFiles            ();
use Cpanel::FileUtils::Path        ();
use Cpanel::IONice                 ();
use Cpanel::Logger                 ();
use Cpanel::OSSys                  ();
use Cpanel::OSSys::Capabilities    ();
use Cpanel::SafeRun::Simple        ();

use Getopt::Long ();
use File::Glob   ();
use File::Spec   ();

use Try::Tiny;

################################################################################

our $all;
our $backup;
our $user;
our $vacuum;
our $schedule_rebuild;
our $fix_corrupt;

our $logger;

sub _help {
    my ($msg) = @_;

    print qq{$msg

Usage:

--all - Create metadata for all backups in the configured directory.

e.g. $0 --all
This creates metadata for all backups and users.
If metadata exists, it will delete it and create new metadata.
You cannot combine --all with other options.

--vacuum - Defragment the database and release unused space, runs in the background

e.g. $0 --vacuum
This defragments the database and release unused space.
You cannot combine --vacuum with other options.

--backup=monthly/YYYY-MM-DD - Create metadata for all users in the backup directory that you specify.

e.g. $0 --backup=monthly/2017-03-01
This creates metadata for all users in this backup directory.
You can combine this option with the --user option.
e.g. $0 --backup=monthly/2017-03-01 --user=alvin
This creates metadata for this user in this backup directory.

--user=user - Create metadata only for this user.

e.g. $0 --user=alvin
This creates metadata only for this user.
You can combine this option with the --backup=monthly/YYYY-MM-DD option.
e.g. $0 --backup=monthly/2017-03-01 --user=alvin
This creates metadata for this user in this backup directory.

--schedule_rebuild - Rebuild all metadata in the background.

e.g. $0 --schedule_rebuild
This rebuilds all metadata. The script returns to the command line immediately and
continues to rebuild the metadata in a background task.
You can combine this option with the --fix_corrupt option.
e.g. $0 --schedule_rebuild --fix_corrupt
This scans all user metadata and rebuilds corrupt metadata. The script returns to
the command line immediately and continues to rebuild the metadata in a background
task.

--fix_corrupt - Scans all user metadata to identify and rebuild corrupt metadata.
e.g. $0 --fix_corrupt
This scans all user metadata and rebuilds corrupt metadata.
You can combine this option with the --schedule_rebuild option.
e.g. $0 --schedule_rebuild --fix_corrupt
This scans all user metadata and rebuilds corrupt metadata. The script returns to
the command line immediately and continues to rebuild the metadata in a background
task.
};

    exit 0;
}

sub _invalid_parms {
    _help("invalid parameters");
    die "Invalid Command Line Parameters\n";
}

sub _output {
    my ($line) = @_;

    print $line . "\n";

    return;
}

sub clean_old_metadata_files {
    my ($dir) = @_;

    opendir( my $accounts_dir, "$dir/accounts/" );
    foreach my $file ( readdir($accounts_dir) ) {
        if ( ( $file =~ m/\-\=\-meta/ || $file eq '.sql_dump.gz' ) && -f "$dir/accounts/$file" ) {
            print "Removing old metadata file $dir/accounts/$file\n";
            unlink("$dir/accounts/$file");
        }
    }
    closedir($accounts_dir);

    # Clean old version of single sqlitedb
    unlink '/var/cpanel/backups/metadata.sqlite';

    return;
}

sub create_master_meta {
    my ($dir) = @_;

    my $meta_master = $dir . "/accounts/.master.meta";
    if ( !-e $meta_master ) {
        my $ref = Cpanel::Backup::Metadata::introspect_old_backup($dir);
        if ( defined( $ref->{'backup'}->{'backup_type'} ) && $ref->{'backup'}->{'backup_type'} ne 'ERROR' ) {
            Cpanel::Backup::Metadata::create_meta_master_with_users_from_introspect( $dir, $ref );
        }
        else {
            return 0;    # ignore if the directory cannot be determined
        }
    }

    return 1;
}

# Set our "nice" level

sub apply_nice_level_to_process {
    my ($logger) = @_;
    my $cpconf_ref;
    ( %{$cpconf_ref} ) = Cpanel::Config::LoadCpConf::loadcpconf();

    Cpanel::OSSys::nice(18);    # needs to be one higher for cpuwatch
    my $CAPABILITIES = Cpanel::OSSys::Capabilities->load;
    if ( $CAPABILITIES->capable_of('ionice') ) {
        if ( Cpanel::IONice::ionice( 'best-effort', exists $cpconf_ref->{'ionice_cpbackup'} ? $cpconf_ref->{'ionice_cpbackup'} : 6 ) ) {
            $logger->info( "Setting I/O priority to reduce system load: " . Cpanel::IONice::get_ionice() );
        }
    }
    return;
}

sub _run_vacuum {
    require Cpanel::Daemonizer::Tiny;

    Cpanel::Daemonizer::Tiny::run_as_daemon(
        sub {
            require Cpanel::Logger;
            my $logger = Cpanel::Logger->new();
            sleep 15;
            Cpanel::Backup::Metadata::vacuum_metadata($logger);
        },
        ""
    );

    return;
}

sub _get_raw_backup_dirs {
    my ($backup_master_dir) = @_;

    # get all backup dirs under the main backup
    my %backup_dirs_hash;

    foreach my $dir (
        File::Glob::bsd_glob( $backup_master_dir . "/2*/accounts" ),
        File::Glob::bsd_glob( $backup_master_dir . "/monthly/2*/accounts" ),
        File::Glob::bsd_glob( $backup_master_dir . "/weekly/2*/accounts" ),
        File::Glob::bsd_glob( $backup_master_dir . "/incremental/accounts" )
    ) {
        next if ( !-d $dir );
        my ( $xdir, $accounts ) = Cpanel::FileUtils::Path::dir_and_file_from_path($dir);
        $backup_dirs_hash{$xdir} = 1;
    }

    return %backup_dirs_hash;
}

sub _get_all_backup_dirs {
    my ( $backup_master_dir, %backup_dirs_hash ) = @_;

    # sort this in a smart manner so it plays out like it would have had
    # bin/backup done it.

    my @order;
    foreach my $dir ( sort keys %backup_dirs_hash ) {
        my $introspect_ref;
        try {
            $introspect_ref = Cpanel::Backup::Metadata::introspect_old_backup($dir);
        };
        next if !$introspect_ref;                                        # if it dies this is not a valid backup dir, so just move on
        next if !exists $introspect_ref->{'backup'}->{'backup_id'};
        next if $introspect_ref->{'backup'}->{'backup_id'} eq 'ERROR';

        my @users = keys %{ $introspect_ref->{'users'} };
        next if !@users;
        my $user = $users[0];

        my $category_ref = Cpanel::Backup::StreamFileList::categorize_backup( $backup_master_dir, $dir, $user );

        my $sort_path = $category_ref->{'backupID'};
        if ( $sort_path =~ m{^(monthly|weekly)/(.*)$} ) {
            $sort_path = $2 . '/' . $1;
        }
        else {
            $sort_path .= '/a';    # for sorting consistency a is before (m)onthly
        }

        $category_ref->{'sort_path'} = $sort_path;
        push( @order, $category_ref );
    }

    my @dirs = map { $_->{'path'} } sort { $a->{'sort_path'} cmp $b->{'sort_path'} } @order;

    return @dirs;
}

sub fix_corrupt_metadata {
    my ( $backup_master_dir, @users ) = @_;

    # delete the users db's
    foreach my $user (@users) {
        my $user_db_path = Cpanel::Backup::Metadata::get_metadata_filename( $user, 0 );
        unlink $user_db_path if -f $user_db_path;
    }

    my @dirs = _get_all_backup_dirs( $backup_master_dir, _get_raw_backup_dirs($backup_master_dir) );
    foreach my $user (@users) {
        print "Fixing corrupt backup metadata for $user\n";
        foreach my $dir (@dirs) {
            Cpanel::Backup::Metadata::create_metadata_for_backup_user( $dir, $user, $logger );
        }
    }

    return;
}

sub script {    ##no critic qw(ProhibitExcessComplexity)
    my (@args) = @_;

    $ENV{'LANG'} = 'en_US.UTF-8';

    local $| = 1;
    $logger //= Cpanel::Logger->new( { 'alternate_logfile' => '/dev/stdout' } );

    apply_nice_level_to_process($logger);

    my $opts = Getopt::Long::GetOptionsFromArray(
        \@args,
        'all'              => \$all,
        'backup=s'         => \$backup,
        'user=s'           => \$user,
        'vacuum'           => \$vacuum,
        'schedule_rebuild' => \$schedule_rebuild,
        'fix_corrupt'      => \$fix_corrupt,
    ) or _invalid_parms();

    _help("You must provide at least one option to execute the script.") if ( !$all && !$backup && !$vacuum && !$schedule_rebuild && !$user && !$fix_corrupt );

    _help("You cannot combine --all with other options.") if ( $all && ( $backup || $user || $vacuum || $schedule_rebuild || $fix_corrupt ) );

    _help("You cannot combine --vacuum with other options.") if ( $vacuum && ( $all || $backup || $user || $schedule_rebuild || $fix_corrupt ) );

    _help("You can only combine this option with the --user option.")   if ( $backup && ( $all || $schedule_rebuild || $fix_corrupt || $vacuum ) );
    _help("You can only combine this option with the --backup option.") if ( $user   && ( $all || $schedule_rebuild || $fix_corrupt || $vacuum ) );

    _help("You can only combine this option with the --fix_corrupt option.")      if ( $schedule_rebuild && ( $all || $backup || $user || $vacuum ) );
    _help("You can only combine this option with the --schedule_rebuild option.") if ( $fix_corrupt      && ( $all || $backup || $user || $vacuum ) );

    my $conf              = Cpanel::Backup::Config::load();
    my $backup_master_dir = $conf->{'BACKUPDIR'};

    # if --user is on the command line by itself, leverage the --all code to
    # process all the backups but for this user only.

    if ( $user && !$backup ) {
        $all = $backup_master_dir;
    }

    # if disabled do not do anything, unless it is all then allow the
    # cleanup operation to happen, but then fail

    Cpanel::Backup::Metadata::metadata_disabled_check(1) if ( !$all );

    #We use this two places, may as well just get it now
    my @users;

    if ($user) {
        push( @users, $user );
    }
    else {
        @users = Cpanel::Backup::Metadata::get_all_users();
    }

    if ($all) {
        $all = $backup_master_dir;

        foreach my $this_user (@users) {
            my $db = Cpanel::Backup::Metadata::get_metadata_filename($this_user);
            unlink $db if -f $db;
        }

        my %backup_dirs_hash = _get_raw_backup_dirs($backup_master_dir);

        # clean old metadata
        foreach my $dir ( sort keys %backup_dirs_hash ) {
            try {
                clean_old_metadata_files($dir);

                # delete existing master meta, as it may be of an older type
                my $meta_master = $dir . "/accounts/.master.meta";
                unlink $meta_master if -e $meta_master;
            }
            catch {
                $logger->warn("Failed to clean old metadata for $dir :$_:");
            };
        }

        # allow the clean up to take place regardless of disabled or not
        # but then fail if metadata is disabled
        Cpanel::Backup::Metadata::metadata_disabled_check(1);

        my @dirs = _get_all_backup_dirs( $backup_master_dir, %backup_dirs_hash );
        foreach my $dir (@dirs) {
            print "Processing directory “$dir”\n";
            my $ret;

            try {
                $ret = create_master_meta($dir);
            }
            catch {
                $logger->warn("Failed to create metadata for $dir :$_:");
            };

            next if !$ret;    # ignore if the directory cannot be determined

            try {
                if ($user) {
                    Cpanel::Backup::Metadata::create_metadata_for_backup_user( $dir, $user, $logger );
                }
                else {
                    Cpanel::Backup::Metadata::create_metadata_for_backup( $dir, $logger );
                }
            }
            catch {
                $logger->warn("Failed to create metadata for $dir : $! ($_)");
            };
        }

        _run_vacuum();
    }
    elsif ($backup) {
        $backup = $backup_master_dir . "/$backup";

        my $backup_ref = Cpanel::Backup::StreamFileList::categorize_backup( $backup_master_dir, $backup, "dontcare" );
        if ( $backup_ref->{'backupID'} eq "ERROR" ) {
            _help("backup parameter is not a valid backup");
        }

        if ($user) {
            $backup_ref = Cpanel::Backup::StreamFileList::categorize_backup( $backup_master_dir, $backup, $user );
            if ( $backup_ref->{'type'} eq 'unknown' ) {
                _help("user parameter is not a valid backup");
            }

            try {
                if ( !create_master_meta($backup) ) {
                    die "Cannot create backup";    # is caught and warned
                }
                my $master_meta = Cpanel::Backup::Metadata::load_master_meta($backup);
                foreach my $user_ref ( values %{ $master_meta->{'users'} } ) {

                    next if ( $user_ref->{'user'} ne $user );
                    $logger->info("Processing Backup $backup for User $user");
                    Cpanel::Backup::Metadata::create_metadata_for_backup_user( $backup, $user_ref->{'user'}, $logger );
                    last;
                }
            }
            catch {
                $logger->warn("Failed to create metadata for $backup");
            }
        }
        else {
            try {
                if ( !create_master_meta($backup) ) {
                    die "Cannot create backup";    # is caught and warned
                }

                $logger->info("Processing Backup $backup");
                Cpanel::Backup::Metadata::create_metadata_for_backup( $backup, $logger );
            }
            catch {
                $logger->warn("Failed to create metadata for $backup");
            }
        }

        _run_vacuum();
        $logger->info("Processing is complete.");
    }
    elsif ($vacuum) {
        _run_vacuum();
    }
    elsif ($schedule_rebuild) {
        if ($fix_corrupt) {
            print "Fixing corrupted backup metadata in the background\n";
        }
        else {
            print "Creating all backup metadata in the background\n";
        }

        # remove old metadata, and regen with new schema
        require Cpanel::Daemonizer::Tiny;

        Cpanel::Daemonizer::Tiny::run_as_daemon(
            sub {
                # Don't lose output from the script when it detaches from here and goes off on it's own
                open( STDERR, '>>', $Cpanel::ConfigFiles::CPANEL_ROOT . '/logs/error_log' ) or warn "Could not open cPanel Error Log: $!";
                open( STDOUT, '>>', $Cpanel::ConfigFiles::CPANEL_ROOT . '/logs/error_log' ) or warn "Could not open cPanel Error Log: $!";

                if ($fix_corrupt) {
                    Cpanel::SafeRun::Simple::saferun( '/usr/local/cpanel/scripts/backups_create_metadata', '--fix_corrupt' );
                }
                else {
                    Cpanel::SafeRun::Simple::saferun( '/usr/local/cpanel/scripts/backups_create_metadata', '--all' );
                }
            },
            ""
        );
    }
    elsif ($fix_corrupt) {
        my ( $dbs_valid, $broken_users_ar ) = Cpanel::Backup::Metadata::is_database_valid( \@users );
        if ($dbs_valid) {
            print "No user metadata is corrupt\n";
        }
        else {
            try {
                fix_corrupt_metadata( $backup_master_dir, keys %{$broken_users_ar} );
            }
            catch {
                print "Error fixing corrupt backup metadata: $_\n";
            };
        }
    }

    return 1;
}

exit( script(@ARGV) ? 0 : 1 ) unless caller();

Youez - 2016 - github.com/yon3zu
LinuXploit