HEX
Server: Apache
System: Linux vpshost11508.publiccloud.com.br 5.15.179-grsec-vpshost-10.lc.el8.x86_64 #1 SMP Mon Apr 7 12:04:45 -03 2025 x86_64
User: wicomm2 (10002)
PHP: 8.3.0
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: /home/storage/5/78/dd/wicomm2/public_html/clientes/backup/inspirafarm/prod.php
<?php
require 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

// CONFIGS DO BANCO
$host = 'inspirafarm.vpshost11508.mysql.dbaas.com.br';
$usuario = 'inspirafarm'; // ou outro usuário
$senha = 'Wicomm@2025';
$banco = 'inspirafarm';

// CONECTAR AO BANCO
$conn = new mysqli($host, $usuario, $senha, $banco);
if ($conn->connect_error) {
    die("Falha na conexão: " . $conn->connect_error);
}

$data = date("d-m-Y__H-i-s");
$arquivo = "backup_{$banco}_{$data}.sql";
$caminho = __DIR__ . "/$arquivo";

// ABRE ARQUIVO PARA ESCREVER
$fp = fopen($caminho, 'w');

// CABEÇALHO
fwrite($fp, "-- Backup gerado em: $data\n");
fwrite($fp, "-- Banco: $banco\n\n");

// BUSCA TODAS AS TABELAS
$tables = [];
$res = $conn->query("SHOW TABLES");
while ($row = $res->fetch_array()) {
    $tables[] = $row[0];
}

// EXPORTA CADA TABELA
foreach ($tables as $table) {
    // Estrutura
    $res = $conn->query("SHOW CREATE TABLE `$table`");
    $row = $res->fetch_assoc();
    fwrite($fp, "-- Estrutura da tabela `$table`\n");
    fwrite($fp, "DROP TABLE IF EXISTS `$table`;\n");
    fwrite($fp, $row['Create Table'] . ";\n\n");

    // Dados
    $res = $conn->query("SELECT * FROM `$table`");
    if ($res->num_rows > 0) {
        fwrite($fp, "-- Dados da tabela `$table`\n");
        while ($row = $res->fetch_assoc()) {
            $vals = array_map(function($v) use ($conn) {
                return isset($v) ? "'" . $conn->real_escape_string($v) . "'" : "NULL";
            }, array_values($row));
            fwrite($fp, "INSERT INTO `$table` VALUES (" . implode(",", $vals) . ");\n");
        }
        fwrite($fp, "\n");
    }
}

fclose($fp);
$conn->close();

// ENVIA POR E-MAIL COM PHPMailer
$mail = new PHPMailer(true);

try {
    // SMTP CONFIG
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com'; 
    $mail->SMTPAuth = true;
    $mail->Username = 'guiadeculturafarm@gmail.com';          // SEU E-MAIL GMAIL
    $mail->Password = 'grij axfs dgrc kome';            // SENHA DE APLICATIVO GERADA
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port = 587;

    // DESTINO
    $mail->setFrom('guiadeculturafarm@gmail.com', 'Inspira Farm PROD');
    $mail->addAddress('dev@wicomm.com.br', 'Jefferson Cavalcante');

    // CONTEÚDO
    $mail->Subject = "Backup do Banco - {$banco} - $data";
    $mail->Body    = "Segue em anexo o backup do banco de dados gerado em $data.";
    $mail->addAttachment($caminho);

    $mail->send();
    echo "Backup enviado com sucesso.";
} catch (Exception $e) {
    echo "Erro ao enviar o e-mail: {$mail->ErrorInfo}";
}

// REMOVE O BACKUP LOCAL
unlink($caminho);
?>