I codiert dies die FTP-Backups zu handhaben, nicht sicher, ob es Ihren spezifischen Bedürfnissen passt tho:
class Backup
{
public $ftp = null;
public $files = array();
public function FTP($host, $user = null, $pass = null, $port = 21, $path = '/')
{
if ((extension_loaded('ftp') === true) && (extension_loaded('zip') === true))
{
$this->ftp = ftp_connect($host, $port, 5);
if (is_resource($this->ftp) === true)
{
if (ftp_login($this->ftp, $user, $pass) === true)
{
$zip = new ZipArchive();
if (is_object($zip) === true)
{
ftp_pasv($this->ftp, true);
if ($zip->open(sprintf('./%s_%s.zip', $host, date('YmdHis', time())), ZIPARCHIVE::CREATE) === true)
{
$this->FTP_Map($path);
while (($file = array_shift($this->files)) !== null)
{
if (preg_match('~/$~', $file) > 0)
{
$zip->addEmptyDir(preg_replace('~^[\\/]+~', '', $file));
}
else
{
$stream = tempnam(sys_get_temp_dir(), __CLASS__);
if (is_file($stream) === true)
{
if (ftp_get($this->ftp, $stream, $file, FTP_BINARY, 0) === true)
{
$zip->addFromString(preg_replace('~^[\\/]+~', '', $file), file_get_contents($stream));
}
unlink($stream);
}
}
}
}
$zip->close();
}
}
ftp_close($this->ftp);
}
}
return false;
}
public function FTP_Map($path = '/')
{
if (is_resource($this->ftp) === true)
{
$files = ftp_nlist($this->ftp, ltrim($path, '/'));
if (is_array($files) === true)
{
foreach ($files as $file)
{
if (@ftp_chdir($this->ftp, $file) !== true)
{
$this->files[] = sprintf('/%s/%s', trim($path, '\\/'), trim($file, '\\/'));
}
else if (ftp_cdup($this->ftp) === true)
{
if (array_push($this->files, sprintf('/%s/%s/', trim($path, '\\/'), trim($file, '\\/'))) > 0)
{
$this->FTP_Map(sprintf('/%s/%s/', trim($path, '\\/'), trim($file, '\\/')));
}
}
}
return true;
}
}
return false;
}
}
Verbrauch:
$Backup = new Backup();
$Backup->FTP('demo.wftpserver.com', 'demo-user', 'demo-user', 21, '/text/');
Für MySQL-Backups, würde SELECT INTO OUTFILE
es tun?
Warum überhaupt PHP? 'rsync' erfüllt alle Ihre" Muss "-Anforderungen. Wie planen Sie, Zip-Dateien und inkrementelle Backups zu verwenden? – meagar
Ich stimme @meagar zu, php scheint eine schlechte Wahl für so etwas zu sein. Auch das lokale Speichern von Sicherungen hilft nicht, wenn der Computer vollständig ausfällt. –
@meagar dies ist für eine gegenseitige Backup-Lösung zwischen zwei freigegebenen Web-Hosts, so dass nur PHP (na ja, und vielleicht Perl) eine Option ist. @Chris by "local" Ich meine lokal auf dem Server läuft das Backup-Skript, nicht der entfernte Server, der gesichert wird –