0
I have a cron task that calls a url, that url is a folder that contains an index.php file. This PHP file runs every 12 hours and saves my server databases into files. sql inside a folder, only by the cron task 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. Follow 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 http://domain/bkpserver
have you tried just running Curl? I mean, without using the browser, just the same line. See if you’re answering anything.
– Daniel
Copy your cmd command and run via bash script if you run correctly do the following to decrease the running time of the script in cron to run every 5 minutes and with the open terminal run "Tail -fn 10 /var/log/cron" wait for cron to run the routine and get the error, then concerte or post here to find out what it is.
– Rafael Salomão
already tried to change the permission to 0777?
– Solange
@Daniel, yes, I’ve only run the mysqldump command and it worked smoothly. Solange, the folder and the file is 777. Rafael Solomon, I tried to execute this command, but said he did not find this file. Thank you all for your help.
– Bernardo Kowacic