Ferreteria/v0.6/clade/Sys/Data/Engine/Oper/MyMar/Maria/@removed
|
Removed Code
|
2025-02-11
Pretty sure this is obsolete stuff that is now handled elsewhere by other means:
#
/**
* TODO:
* 2024-12-09 If $fs points to a file, then just restore that file.
*/
public function DoImport(string $fs,BkupModeEnum $eMode=NULL) : ActionIface {
$oScrn = self::Screen();
if (is_dir($fs)) {
$doAllowAll = FALSE; // TODO: make this an option
if ($doAllowAll) {
echo $oScrn->GreenIt('Restoring')." all files found in [$sPath].".CRLF;
} else {
echo $oScrn->InfoIt('Note').": No schema specified; schema-data files found in [$sPath] are:".CRLF;
}
$oFolder = new FolderClass($sPath);
$arExts = $oFolder->IndexByExtension();
$sExtReq = is_null($eMode) ? NULL : ('.'.$eMode->FileExt());
foreach ($arExts as $sExt => $arFiles) {
$nF = count($arFiles);
$sS = ($nF == 1) ? '' : 's';
$sWhat = "$nF '$sExt' data file$sS";
if (is_null($sExtReq) || ($sExt == $sExtReq)) {
// This format is allowed.
if ($doAllowAll) {
echo "Restoring $sWhat...".CRLF;
} else {
echo " - Found $sWhat:".CRLF;
}
foreach ($arFiles as $sBase => $oNode) { // $sBase is presumed to be the schema name
if (is_a($oNode,FileIface::class)) {
#$fsData = $oNode->FullSpecFor($sBase.$sExt);
$fsData = $oNode->FullSpec();
#echo " - $fsData :".CRLF;
if ($doAllowAll) {
$this->DoUtilRestore($fsData,$sBase);
} else {
$ftBase = $oScrn->GreenIt($sBase);
echo " -- $ftBase".CRLF;
}
} else {
echo $oScrn->YellowIt('Warning').": found unexpected folder [$fsData] in list.".CRLF;
}
}
} else {
echo "Ignoring $sWhat.".CRLF;
}
}
} elseif (is_file($fs)) {
$ftPath = $oScrn->GreenIt($sPath);
self::GotToHere();
echo $oScrn->InfoIt('Restoring')." $ftPath".CRLF;
$this->DoUtilRestore($sPath,$sBase);
} else {
$ftPath = $oScrn->BlueIt($sPath);
echo $oScrn->ErrorIt('Input Error').": path '$ftPath' not found.".CRLF;
}
}
2025-01-01
I'm taking all the file-mangling stuff out of the Engine classes; that should be handled externally.
This was commented out earlier:
#
public function DoExport(string $fs) {
$eMode = $this->DataFormat();
switch($eMode) {
case BkupModeEnum::USE_JSON:
echo self::CodingPrompt('JSON output mode not written yet.');
break;
case BkupModeEnum::USE_SQL:
$this->DoUtilBackup($fs);
break;
case BkupModeEnum::USE_XML:
echo self::CodingPrompt('XML output mode not written yet.');
break;
}
}
2024-12-25
Removed from @fx/GetSchemaList() on 2024-12-10:
#
// 2024-12-10 moved into SchemaList(), except for screen output
// COMMAND: echo "show schemas;" | mysql <credentials>
$sCreds = $this->CredsForCmd();
$sSQL = '"SHOW SCHEMAS;"';
$sCmd = "echo $sSQL | mysql $sCreds";
$oConnx = $this->Connx(); // get (remote|local) connection object
$oBuff = new MemBufferClass;
#echo "Running data command [$sCmd]...".CRLF;
$oAct = $oConnx->DoCommand($sCmd,$oBuff);
$this->HandleResults($oAct);
echo ($oAct->GetOkay() ? $oScrn->GreenIt('Done.') : ($oScrn->ErrorIt('Error: ').$oAct->GetMessage())).CRLF;
$sList = $oBuff->GetBytes();
$arList = explode("\n",trim($sList)); // we might want to ensure that CRLF, CR, and LF all work as EOL.
#echo 'LIST: '.CRLF.print_r($arList,TRUE);
// "Database" is the standard header for list of databases.
// If we don't see this, then something isn't right.
$sFirst = array_shift($arList);
if ($sFirst != "Database") {
self::GotToHere("Something's not right with the db list. Here's what we got:".CRLF.$sList); die();
}
$oConnx->Shut();
return $arList;
2024-12-14
Commented out earlier (moved to request/actor process):
#
protected function FigureHostFolder(string $sFolder, TpltIface $oTplt) : string {
$oSet = self::Settings();
$fpmData = $oSet->DataFolderMask();
$oConnx = $this->Connx(); // shell (outside) connection details
$sSHost = $oConnx->Creds()->QHost()->GetIt(); // shell-connection host
$osVarMarks = self::Globals()::QVarMarks();
$this->HardAssert($osVarMarks->HasIt(),'The QVarMarks() global needs to be set in the configuration.');
$oVarMarks = $osVarMarks->GetIt();
$oTplt = new $scTplt($oVarMarks,$fpmData);
$oTplt->Data()->SetAll(['db.slug'=>$this->ObjectSlug(),'db.host'=>$sSHost]);
$ofsRel = $oTplt->Render();
$fsRel = $ofsRel->Rendered()->GetIt();
$fsData = $sFolder.$oSet::FILE_PATH_SEP.$fsRel;
#echo "FSDATA=[$fsData] SFOLDER=[$sFolder] FSREL=[$fsRel]".CRLF;
return $fsData;
}
// TODO 2024-12-09: This could probably just reuse a lot of functionality from FigureHostFolder().
protected function FigureHostFileSpec(TpltIface $oTplt, string $sFolder, string $sSchema=NULL) : string {
$oSet = self::Settings();
$oConnx = $this->Connx(); // shell (outside) connection details
$sSHost = $oConnx->Creds()->QHost()->GetIt(); // shell-connection host
$osVarMarks = self::Globals()::QVarMarks();
$this->HardAssert($osVarMarks->HasIt(),'The QVarMarks() global needs to be set in the configuration.');
$oVarMarks = $osVarMarks->GetIt();
// Figure filespec for backup data
// - relative filespec, from template:
$scTplt = self::Classes()->CommonTemplate();
// relative filespec mask
$fsmrData = $oSet->DataFileSpecMask(); // mask for relative filespec
$oTplt = new $scTplt($oVarMarks,$fsmrData);
$oTplt->Data()->SetAll(['db.slug'=>$this->ObjectSlug(),'db.host'=>$sSHost,'db.schema'=>$sSchema]);
$ofsRel = $oTplt->Render();
$fsRel = $ofsRel->Rendered()->GetIt(); // actual relative filespec
// absolute filespec
$fsData = $sFolder.$oSet::FILE_PATH_SEP.$fsRel;
return $fsData;
}
2024-12-03
If we specify a port, then it has to be correct -- but the remote server may have different defaults, so let's allow the config to default to those.
#
// ++ CONFIG ++ //
protected function DefaultPort() : int { return 3306; }
This code from DoUtilBackup() has been consolidated into CredsForCmd() and/or modified to use that:
#
$oCreds = $this->Creds();
#echo $oConnx->ReflectThis()->Report();
$oConnx->Open();
// get DB creds and compose the command to run remotely:
$sDUser = $oCreds->QUser()->GetIt();
$sDPass = $oCreds->QPass()->GetIt();
$sDHost = $oCreds->QHost()->GetIt();
$nDPort = $oCreds->QPort()->GetItNz($this->DefaultPort()); // should this be included in the mysqldump command?
#$nTPort = $oTunn->QPort()->GetIt();
// ...
$sCmd = "mysqldump --port=$nDPort --host=$sDHost --user=$sDUser --password=$sDPass $sDBSpec";
I suddenly realized that DoAdminRequest() should just pass $this to the Request-object and have it make the appropriate Iface call. This means that DoAdminRequest() can be a single line of code in the base class.
#
public function DoAdminRequest(AdminReqIface $oReq) {
if (is_a($oReq,BackupRqIface::class)) {
// this is currently the only admin-request type, but that may change
$this->DoExport($oReq->Mode(),$oReq->LocalPath());
} elseif (is_a($oReq,ListSchemasRqIface::class)) {
}
}
This leads to the further thought that maybe what I should do is initialize the Request with the DB object and then just call the Request to do the action -- but I *think* part of the purpose of a Request is that it can be created before we have the db object. We know what we want to do, but we don't have the target yet. `AskEngine()` is the final connector which makes it possible to Do The Thing.
Also, these were commented out awhile ago -- possibly the same day they were written:
#
// ++ SETUP ++ //
public function __construct(string $sSlug, private CredsIface $oCreds, private ConnxIface $oConnx) {
$oCreds->QPort()->SetDefault(3306);
parent::__construct($sSlug,$oCreds,$oConnx);
}
// -- SETUP -- //
// ...
// ++ SETTINGS ++ //
private $eBkMode = NULL;
protected function BackupMode(BkupModeEnum $eMode) { return $this->eBkMode; }
public function UseSQLforBackup() { $this->eBkMode = BkupModeEnum::SQL; }
public function UseJSONforBackup() { $this->eBkMode = BkupModeEnum::JSON; }
// -- SETTINGS -- //
The constructor was from before I repackaged the connection info into Creds objects ([WF]IO\Connx\Aux\xCreds).
2024-11-27
This was partly working, but the local mysqldump never seemed able to connect to the remote through the tunnel.
For now, I'm switching to running the mysqldump command on the remote, which is a lot simpler to set up.
I may end up needing this code later, to make actual data-connections possible, but for now it's in the way.
#
/**
* PROCESS: We need to create an ssh tunnel so we can run the dump command locally
* while still attaching to a possibly-remote db engine.
* HISTORY:
* 2024-11-23 For now, this backs up all DBs. TODO: allow specifying a list
* 2024-11-24 We *could* open a tunnel for this, but tentatively it's simpler
* to pipe a command through:
* ssh user@remote_host "mysqldump -u username -p database_name" > local_backup_file.sql
*/
protected function DoUtilBackup(string $sPath) {
$oScrn = self::Screen();
$oConnx = $this->Connx();
$oCreds = $this->Creds();
#echo $oConnx->ReflectThis()->Report();
// get the shell-connection creds:
$sSHost = $oConnx->Creds()->QHost()->GetIt();
echo "Opening tunnel to $sSHost...".CRLF;
$oTunn = $oConnx->NewTunnel($oCreds);
$oAct = $oTunn->Open();
echo ($oAct->GetOkay() ? $oScrn->GreenIt('Opened.') : ($oScrn->ErrorIt('Error: ').$oAct->GetMessage())).CRLF;
// get DB creds and compose the command to run remotely:
$sDUser = $oCreds->QUser()->GetIt();
$sDPass = $oCreds->QPass()->GetIt();
$sDHost = $oCreds->QHost()->GetIt();
$nDPort = $oCreds->QPort()->GetItNz($this->DefaultPort()); // should this be included in the mysqldump command?
$nTPort = $oTunn->QPort()->GetIt();
$sDBSpec = '--all-databases'; // TODO 2024-11-24: allow specification of DB list in app command
$sCmd = "mysqldump --port=$nTPort --host=$sDHost --user=$sDUser --password=$sDPass $sDBSpec";
#$sCmd = 'ls -al';
$oBuff = new BufferClass;
echo "Starting local dump command [$sCmd]...".CRLF;
$oConnx->DoRemoteCommand($sCmd,$oBuff);
echo CRLF.'Response length '.$oBuff->Length().' bytes'.CRLF;
}