cron job is not executed

0

I have a cron job that calls a url, this url is a folder that contains an index.php file. This PHP file runs every 12 hours and saves the databases of my server in .sql files inside a folder, but by the cron job it is not doing this, but if I call this url directly in the browser, the PHP file is called and the backup is done. Here is the PHP code I used:

ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);

$mysqli = new mysqli("localhost", "root", "senha");
$mysqli->set_charset("utf8");

$query = "SHOW DATABASES";
$result = $mysqli->query($query);
while ($r = $result->fetch_assoc()) {
    $DATABASE = $r['Database'];

    $pasta = date("d-m-Y-H");
    $nome_arquivo = $DATABASE.'.sql';

    $DBUSER="root";
    $DBPASSWD="senha";
    $DATABASE=$DATABASE;
    @mkdir($pasta, 0700);
    $cmd = "mysqldump -u $DBUSER --password=$DBPASSWD $DATABASE > $pasta/$nome_arquivo";

    exec($cmd);
}

This is the cron task: curl -s -o / dev / null link

    
asked by anonymous 05.07.2017 / 03:11

1 answer

1

I solved the problem by creating a shell script. Inside the Shell Script file I configured the BD copy routine and executed the script file by the cron job.

The code used to make the connection and save the .sql remains the same, what changes is the way the file is executed.

    
23.07.2017 / 17:00