Hi,
da ich BASH-Skript nicht mächtig bin, habe ich mir per PHP ein kleines Skript gebaut das mir die mySQL Datenbank sichert und zippen soll, um sie dann per FTP zum download zur Verfügung stellen soll.
Das sieht wiefolgt aus:
Code:
<?php
$log = "**** Datensicherung sqldump.php am " . date('d.m.Y H:i:s') . "\r\n";
$fp = fopen('/root/dblist','r');
while ($data = fscanf($fp, "%s %s %s %s %s %s %s")) {
list ($check, $host, $user, $password, $db, $webpath) = $data;
if( $check == 1 ) {
$log .= "Check: $check, Host: $host, User: $user, Password: $password, DB: $db, Webpath: $webpath \r\n";
if( strrchr($webpath, '/') != '/' ) $webpath = $webpath ."/";
$target = $webpath . $db . '_' . date("Y_m_d") . '.sql';
$command = "/usr/bin/mysqldump ";
$command .= "--user=$user --password=$password -B $db > $target";
// echo $command . "\r\n";
exec ($command,$status, $error);
$log .= "$command, Status: $error \r\n";
exec ("gzip -f $taget", $status);
exec ("chown $user:$user $target.gz", $status, $error);
$dh = opendir($webpath);
$days = 7*24*60*60;
while( ($file = readdir($dh)) != false ) {
if( strncmp($file, $db, strln($db) ) == 0 ) {
if( fileatime($webpath . $file) < time()-$days ) {
$delfile = $webpath . $file;
if( is_file($delfile) ) {
if( @ unlink($delfile) ) {
$log .= "Datei $delfile gelöscht! \\n";
}
}
}
}
}
closedir($dh);
}
}
fclose($fp);
$log .= "\r\n\r\n";
$dh_log = fopen('/root/sqldump.log', 'a+');
fwrite($dh_log, $log);
fclose($dh_log);
?>
Er bringt mir dann immer die schöne Meldung:
sh: /mysqldump: datei oder Verzeichnis nicht gefunden
Was mir hier auffällt:
- Wieso
/mysqldump?
Ich habe extra den Pfad zur Datei angegeben, obwohl diese im Librarypfad steht. Die Datei dblist bekommt er - hab ich geprüft.
Wenn ich den Befehl per Echo ausgeben lasse und manuell eintippe funktioniert der Befehl problemlos.
Das gleiche nutze ich noch auf meinem 2. Server und da funktioniert es ebenfalls Problemlos, d.h. bin jetzt komplett ratlos woran das liegen könnte
PS: Ich rufe das ganze mit php-cgi /root/sqldump.php auf