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