Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & MySQL
PHP & MySQL Forum d'entraide sur les fonctions MySQL avec PHP. Avant de poster -> FAQ MySQL, Cours MySQL et Sources MySQL. Pour les questions concernant le moteur MySQL plutôt que les fonctions PHP, merci d'utiliser le forum MySQL.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 07/08/2011, 20h38   #1
Membre habitué
 
Avatar de geforce
 
Femme
Développeur informatique
Inscription : janvier 2010
Messages : 468
Détails du profil
Informations personnelles :
Sexe : Femme

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2010
Messages : 468
Points : 149
Points : 149
Envoyer un message via Skype™ à geforce
Par défaut [cron sous Red-hat] un Backup bdd planifier

Bonjour,

je voudrais faire un script PHP qui sera exécuté via un cron (tous les jours à 00:00 par exemple).

Voilà le script qui devait être exécuté, mais qui ne marche pas (je n'ai pas compris pour quoi) ? J'ai des warnings qui m'indiquent que la fonction "system()" ne s'est pas bien exécutée (jen'ai pas plus de détails)

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
$host = "localhost"; 
$user = "root";
$pass = "******"; // On définit les infos de la base de données
$db = "reporting-rh";
$date = date("d_m_Y"); // On définit le variable $date (ici, son format)
 
$backup = $db."bdd-backup_".$date.".sql.gz";
// Utilise les fonctions système : MySQLdump & GZIP pour générer un backup gzipé
$command = "mysqldump -h $host -u $user -p $pass $db | gzip> $backup";
system($command);
// Démarre la procédure de téléchargement
$taille = filesize($backup);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/gzip");
header("Content-Disposition: attachment; filename=$backup;");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$taille);
@readfile($backup);
// Supprime le fichier temporaire du serveur
unlink($backup);
?>
Pourtant les lignes de commande seules s’exécutent parfaitement !


Sinon, ça m'arrangerait de faire un script shell (un batch), mais je ne sais pas comment le faire. Est-il possible de m'aider un peu ? (C'est peut-être plus simple que le script PHP et plus stable).

Merci d’avance pour votre aide
geforce est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/08/2011, 14h34   #2
Membre habitué
 
Avatar de geforce
 
Femme
Développeur informatique
Inscription : janvier 2010
Messages : 468
Détails du profil
Informations personnelles :
Sexe : Femme

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2010
Messages : 468
Points : 149
Points : 149
Envoyer un message via Skype™ à geforce
les messages d'erreur :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
Warning: filesize() [function.filesize]: stat failed for reporting-rhbdd_backup_08_08_2011.sql.gz in /application/Dashboard/backup_db.php on line 18
 
Warning: Cannot modify header information - headers already sent by (output started at /application/Dashboard/backup_db.php:18) in /application/Dashboard/backup_db.php on line 21
 
Warning: Cannot modify header information - headers already sent by (output started at /application/Dashboard/backup_db.php:18) in /application/Dashboard/backup_db.php on line 22
 
Warning: Cannot modify header information - headers already sent by (output started at /application/Dashboard/backup_db.php:18) in /application/Dashboard/backup_db.php on line 23
 
Warning: Cannot modify header information - headers already sent by (output started at /application/Dashboard/backup_db.php:18) in /application/Dashboard/backup_db.php on line 24
 
Warning: Cannot modify header information - headers already sent by (output started at /application/Dashboard/backup_db.php:18) in /application/Dashboard/backup_db.php on line 25
 
Warning: Cannot modify header information - headers already sent by (output started at /application/Dashboard/backup_db.php:18) in /application/Dashboard/backup_db.php on line 26
 
Warning: Cannot modify header information - headers already sent by (output started at /application/Dashboard/backup_db.php:18) in /application/Dashboard/backup_db.php on line 27
 
Warning: Cannot modify header information - headers already sent by (output started at /application/Dashboard/backup_db.php:18) in /application/Dashboard/backup_db.php on line 28
 
Warning: Cannot modify header information - headers already sent by (output started at /application/Dashboard/backup_db.php:18) in /application/Dashboard/backup_db.php on line 29
 
Warning: unlink(reporting-rhbdd_backup_08_08_2011.sql.gz) [function.unlink]: No such file or directory in /application/Dashboard/backup_db.php on line 33
geforce est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/08/2011, 15h30   #3
Membre actif
 
Homme
Inscription : avril 2011
Messages : 426
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : avril 2011
Messages : 426
Points : 171
Points : 171
Ce que je peux dire c'est que le fichier que tu essaies de supprimer n'existe pas.

Ensuite, les erreurs sur le header, c'est un classique.

Pour la première erreur, je pense que cela vient d'un problème de droit sur le dossier en question. Passe en chmod 777
heretik25 est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 08/08/2011, 16h38   #4
Expert Confirmé
 
Avatar de grunk
 
Homme Olivier
Développeur Web
Inscription : août 2003
Messages : 1 837
Détails du profil
Informations personnelles :
Nom : Homme Olivier
Âge : 27
Localisation : France, Côte d'Or (Bourgogne)

Informations professionnelles :
Activité : Développeur Web
Secteur : Industrie

Informations forums :
Inscription : août 2003
Messages : 1 837
Points : 3 318
Points : 3 318
Citation:
Sinon, ça m'arrangerait de faire un script shell (un batch), mais je ne sais pas comment le faire
Faudrait plus voir du coté des forums linux mais un truc du genre devrait marcher :
Code :
1
2
3
4
5
6
7
8
 
#!/bin/bash
 
cd /chemin/desire/pour/backups/
 
mysqldump -uroot -ppass --opt bdd1 > bdd1.sql
tar jcf bdd1.sql.tar.bz2 bdd1.sql
rm bdd1.sql
grunk est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 09/08/2011, 13h08   #5
Membre habitué
 
Avatar de geforce
 
Femme
Développeur informatique
Inscription : janvier 2010
Messages : 468
Détails du profil
Informations personnelles :
Sexe : Femme

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2010
Messages : 468
Points : 149
Points : 149
Envoyer un message via Skype™ à geforce
j'ai tester de faire sa mais sa marche pas

la commande :
Code :
 22 12 * * * mysqldump -hlocalhost -uroot -pTBbillel21 reporting-rh | gzip > reporting-rh_bdd_backup_09_08_2011.sql.gz

message : bash: 22: command not found

si quelque peut me dirigés ou m'aidé
geforce est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 12h55.


 
 
 
 
Partenaires

Hébergement Web