@george1421 I promised you to stay in the loop about this topic. First the bad news: Our full stack developer just doesn’t have the time to support me with this. So what did I do? On my own 🤪 I guess if @Sebastian-Roth sees this code he’s puking or cringing how bad the code is But I’m a firsttime php coder, so please have mercy with me
So at first I created a new table with the information needed to connect to the other hosts. After that a simple PHP file with a form, that querys all of my available images and locations:
<html>
<form method="post" action="transmitter.php" id="transmitting">
<?php
$link = mysqli_connect("127.0.0.1", "secret", "damnsecret", "fog"); //connect Database
//Check if Connection was successful and print error if not
if (!$link) {
echo "Fehler: konnte nicht mit MySQL verbinden." . PHP_EOL;
echo "Debug-Fehlernummer: " . mysqli_connect_errno() . PHP_EOL;
echo "Debug-Fehlermeldung: " . mysqli_connect_error() . PHP_EOL;
exit;
}
//Gather all Images and create Dropdown Menu for User.
if($result2 = $link->query("SELECT `imageID`,`imageName`,`imageDesc`,`imagePath`,`imageProtect`,`imageMagnetUri`,`imageDateTime`,`imageCreateBy`,`imageBuilding`,`imageSize`,`imageTypeID`,`imagePartitionTypeID`,`imageOSID`,`imageFormat`,`imageLastDeploy`,`imageCompress`,`imageEnabled`,`imageReplicate`,`imageServerSize` FROM `images`")){
echo "Transferiere Image ";
echo "<select id=image name=image class='form-control' style='width:300px;'>";
while ($row = $result2->fetch_assoc()) {
echo "<option value=$row[imageID]>$row[imageName]</option>";
}
echo "</select>";
}else{
echo $link->error;
}
//Gather all installed Nodes that User can select
if($result3 = $link->query("SELECT `ID`, `NodeName`, `IPAddress`, `Localmount`, `dbuser`, `dbpw`, `bwlimit` FROM `externalNode`")){
echo " zum Node ";
echo "<select id=destination name=destination class='form-control' style='width:300px;'>";
while ($row = $result3->fetch_assoc()) {
echo "<option value=$row[ID]>$row[NodeName]</option>";
}
echo "</select>";
}else{
echo $link->error;
}
mysqli_close($link);
?>
<input id="Senden" type="submit" name="senden" value="Senden"></html>
Then I made every storagenode available and mounted it via NFS into seperate folders into /mnt. After sending the form following php script got called:
<?php
$link = mysqli_connect("127.0.0.1", "secretsauce", "damnsecretsauce", "fog"); //connect Database
//Check if Connection was successful and print error if not
if (!$link) {
echo "Fehler: konnte nicht mit MySQL verbinden." . PHP_EOL;
echo "Debug-Fehlernummer: " . mysqli_connect_errno() . PHP_EOL;
echo "Debug-Fehlermeldung: " . mysqli_connect_error() . PHP_EOL;
exit;
}
//getting all POST informations into useable variables
$gotimage = $_POST["image"];
$gotdestination = $_POST["destination"];
//Query main table to retrieve all informations about the image that has to be transfered
if($result = $link->query("SELECT `imageID`,`imageName`,`imageDesc`,`imagePath`,`imageProtect`,`imageMagnetUri`,`imageDateTime`,`imageCreateBy`,`imageBuilding`,`imageSize`,`imageTypeID`,`imagePartitionTypeID`,`imageOSID`,`imageFormat`,`imageLastDeploy`,`imageCompress`,`imageEnabled`,`imageReplicate`,`imageServerSize` FROM `images` WHERE `imageID`=$gotimage")){
$resultexp = $result->fetch_array();
}else{
echo $link->error;
}
//Query Second Table to retrieve needed information for destination host
if($result2 = $link->query("SELECT `ID`, `NodeName`, `IPAddress`, `Localmount`, `dbuser`, `dbpw`, `bwlimit` FROM `externalNode`")){
$resultexp2 = $result2->fetch_array();
}else{
echo $link->error;
}
//making needed information useable
$imageID=$resultexp['imageID'];
$imagepath=$resultexp['imagePath'];
echo 'Transferiere Image ' . $resultexp['imageName'] . ' ans Ziel ' . $resultexp2['NodeName'];
//Query Storagegroup table to get information on which storage the image is located
if($result3 = $link->query("SELECT `igaStorageGroupID` FROM `imageGroupAssoc` WHERE `igaImageID`=$imageID AND `igaPrimary`='1'")){
$resultexp3 = $result3->fetch_array();
}else{
echo $link->error;
}
$storageID=$resultexp3['igaStorageGroupID'];
//set storagepath to needed variable
if ($storageID==1) {
$storagepath="/mnt/localnode/";
}
elseif ($storageID==2){
$storagepath="/mnt/nvme/";
}
else {echo "gibt nen Fehler, StorageID nicht gefunden.";
exit;
}
$destpath=$resultexp2['Localmount'];
echo "<p>";
//exec shell command to transfer image via rsync to destination and send mail notification after completion
echo shell_exec("/usr/bin/screen -d -m /var/lib/transfer/transfer.sh " . $storagepath . " " . $imagepath . " " . $destpath . " 2>&1");
//make destination variables useable
$destdbaddress=$resultexp2['IPAddress'];
$destdbuser=$resultexp2['dbuser'];
$destdbpw=$resultexp2['dbpw'];
//connect to destination Database
$link2 = mysqli_connect($destdbaddress, $destdbuser, $destdbpw, "fog_dev");
//Check if Connection was successful and print error if not
if (!$link2) {
echo "Fehler: konnte nicht mit MySQL verbinden." . PHP_EOL;
echo "Debug-Fehlernummer: " . mysqli_connect_errno() . PHP_EOL;
echo "Debug-Fehlermeldung: " . mysqli_connect_error() . PHP_EOL;
exit;
}
The reason I didn’t use the Replicationserve on FOG is, that I just want a simple Browserinput und when I click “send” just send it. On the other replicationservice I would log into the server and enable the service. Therefore I decided ot use rsync and let php call a little bashscript that copies is and send a mail when it’s done. The current status anyway can be looked up via SSH and screen resume command:
#!/bin/sh
#start rsync with given variables
/usr/bin/rsync -a -P $1$2 $3$2
#sendmail after image got transferred
subject="Imagetransfer $2 abgeschlossen"
/usr/sbin/sendmail mailadress@lol.de <<EOF
subject:$subject
Viel Erfolg!
EOF
echo "Sync abgeschlossen"
And what I’m now struggeling is, how to put the data into the destination database . At the moment I’m not even sure how to get the data. I already made the SQL statement: and even put in every SQL Result into a single variable
$vresultexpimageID=$resultexp['imageID'];
$vresultexpimageName=$resultexp['imageName'];
$vresultexpimageDesc=$resultexp['imageDesc'];
$vresultexpimagePath=$resultexp['imagePath'];
$vresultexpimageProtect=$resultexp['imageProtect'];
$vresultexpimageMagnetUri=$resultexp['imageMagnetUri'];
$vresultexpimageDateTime=$resultexp['imageDateTime'];
$vresultexpimageCreateBy=$resultexp['imageCreateBy'];
$vresultexpimageBuilding=$resultexp['imageBuilding'];
$vresultexpimageSize=$resultexp['imageSize'];
$vresultexpimageTypeID=$resultexp['imageTypeID'];
$vresultexpimagePartitionTypeID=$resultexp['imagePartitionTypeID'];
$vresultexpimageOSID=$resultexp['imageOSID'];
$vresultexpimageFormat=$resultexp['imageFormat'];
$vresultexpimageLastDeploy=$resultexp['imageLastDeploy'];
$vresultexpimageCompress=$resultexp['imageCompress'];
$vresultexpimageEnabled=$resultexp['imageEnabled'];
$vresultexpimageReplicate=$resultexp['imageReplicate'];
$vresultexpimageServerSize=$resultexp['imageServerSize'];
//echo shell_exec("/var/lib/transfer/dbupdate.sh $destdbaddress $destdbuser $destdbpw $imageID";
?>
But even then, the transmition to the destination database isn’t sucessfull. My next approach was to do it into a second batchfile, that querys the main database, export it INTO a File and then import it into the destination database, without success at the moment.
But after 12 hours straight PHP coding I need a little break I never coded php, and I can imagine I forget a lot of things, for example escaping. But after the progress I had already yesterday I though I could finish today, but it looks like no.
If I’m successul I’m answering again. But I can imagine that the approach I did isn’t quite helpful for the FOG Project