" . $localPath . "{$database['sql_file']}"); if (file_exists($sqlFileFullPath)) { $output = '* Generated file => ' . $sqlFileFullPath . '
'; try { $output .= '* Compressing file : '; exec("gzip " . $localPath . "{$database['sql_file']}"); $output .= 'OK
'; } catch (Exception $e) { $output .= 'KO -> Error : ' . $e->getMessage() . '
'; $output .= 'Error code : ' . $e->getCode() . '
'; $output .= $e->getFile(); } } $output .= '* Upload to :' . $remoteDir . '/' . basename($dataFile) . '
'; $connection = ssh2_connect($server, $port); if(ssh2_auth_password($connection, $username, $password)){ if(ssh2_scp_send($connection, $localGZFile, $remoteGZFile)){ $success = true; } else { $output .= "[KO] Error while uploading file to $server" . '
'; } } else { $output .= "[KO] Error while connecting to $server" . '
'; } $output .= (unlink($localGZFile)) ? '[OK] Tmp file deleted' : '[KO] Error while removing tmp file'; $output .= '
'; // result if (!$success) { mail($email, 'Error DB Backup', $output, $mailHeaders); } else { mail($email, 'DB Backup success', $output, $mailHeaders); } ?>