This topic is locked

Youtube - Backup To Wasabi Cloud Provider Part 2

7/13/2025 12:56:09 PM
PHPRunner Tips and Tricks
C
Chris Whitehead author

I've just watched the video in the title which is great, came a little bit too late for me( I know this was released previously by Sergy which I never watched) and I only watched it as I'd recently done something similar using googledrive, I should have watched Sergy's original then I'd have known about the getCloudProvider function in PHPRunner.

I did do a couple of things differently. Instead of the mysqldump.exe I used https://github.com/ifsnop/mysqldump-php from Diego Torres, using this means I didn't have to worry about where path to the exe or if the user was locked out due to permissions.

I also extended the connection manager class so could steal the main connection credentials, I'm not sure if this works in v11, maybe a slightly different function, I did the backup in v10.91. Hope this helps someone.

// extend the class to hijack connection manager and get the protected variables
class backup extends ConnectionManager
{

public $backup_path = 'backups/';
public $db_data;
public $filename;

public function __construct() {

$this->newline = "
";
}

// get the connection credention and return them
public function getConnectionData() {
// read in the connection data
$this->_setConnectionsData();

// take the first connection returned in the array, this might be different on your setup
$db_key = array_key_first( $this->_connectionsData );
$data = $this->_connectionsData[$db_key];

// pop them into an object for use later on
$this->db_data = array(
'db_host' => $data['connInfo'][0],
'db_user' => $data['connInfo'][1],
'db_pass' => $data['connInfo'][2],
'db_name' => $data['connInfo'][4],
);
}

// dump the database
public function createDatabaseBackup() {

$this->getConnectionData();// set the connection credentials so they can be used to connect to the DB for the mysqldump class

$filepath = $this->backup_path . 'backup_' . date('Ymd_His') . '.sql';// set the filename

$dump = new Mysqldump('mysql:host='.$this->db_data['db_host'].';dbname='.$this->db_data['db_name'], $this->db_data['db_user'], $this->db_data['db_pass'] );// create the dump

// did it work or was it a fail
if ( $dump->start( $filepath ) ) {
$message = "Error Creating Sql Dump : ";
$this->outputMessage( $message,'danger' );
return null;// was a fail, send the sad value
} else {
$message = 'SQL Dump Completed.';
$this->outputMessage( $message );
return $filepath;// return the filename so it can be used to upload to google drive
}
}
}