PHP Kullanarak MySQL Yedeği Almak
Bu PHP betiği ile MySQL veritabanının yedeğini alıp isterseniz sunucuda saklayabilir, isterseniz email adresinize gönderilmesini sağlayabilirsiniz. Ayrıca eski yedek dosyalarının silinmesini sağlayabileceğiniz gibi, yedek oluşturulduğunda size bilgilendirme maili gönderilmesini de ayarlayabilirsiniz.
Bu dosyayi halen kullanmaktayim ve bir sorun cikarmiyor. Sizin sunucunuz PHPyi safe_mode da calistiriyorsa passthru fonksiyonunu calistirmanizi engelleyebilir. Bu fonksiyon yerine baska fonksiyonlar kullanilabilir ancak muhtemelen onlar da engellenmis olacaktir. Dolayisiyla kendinize yedek almak icin baska yontem arayin.
Bu dosyayi cron jobs veya scheduled tasks kullanarak belli zaman araliklarinda calistirabileceginiz gibi manuel olarak da calistirabilirsiniz.
SendMail fonksiyonunu ben yazmadim ama asil yazan kisiyi de bulamadim. Bilen varsa bana haber verebilir.
Dosyayı indirmek için tıklayın. / Click here to download.
-
/*
-
___=== MySQL Otomatik Yedek ===___
-
Yazan: turker (turker.biz@gmail.com)
-
Bağımlılıklar: yok
-
#----------------------------
-
-
___=== MySQL Auto Backup ===___
-
Author: turker (turker.biz@gmail.com)
-
Requirements: none
-
*/
-
-
# settings
-
$siteName='mysite';
-
-
$dbName='db'; // database name
-
$dbUser='db_user'; // database username
-
$dbPass='db_pass'; // database password
-
-
$backupDirectory='/home/httpd/vhosts/mysite/public_html/backups';
-
$backupDownloadURL='http://www.mysite.com/backups/'.$backupFileName;
-
-
$deleteOldBackupFiles='yes'; // yes|no
-
$deleteBackupFile='no'; // yes|no
-
$sendInfoMail='yes'; // yes|no
-
$sendBackupFileToMail='yes'; // yes|no
-
-
$mailFrom='backup@mysite.com';
-
$mailFromName=$siteName.' AutoBackup';
-
$mailTo='mybackups@gmail.com';
-
$mailToName='John Doe';
-
$mailSubject=$siteName.' Backup';
-
# /settings
-
-
-
/* ############################################################################################## */
-
/* NE YAPTIGINIZI BILMIYORSANIZ BURADAN SONRASINA DOKUNMAYIN BENCE */
-
/* DONT CHANGE ANYTHING BELOW IF YOU DONT KNOW WHAT YOU ARE DOING */
-
/* ############################################################################################## */
-
-
# create mysql backup
-
# /create mysql backup
-
-
-
# send information mail
-
if ($sendInfoMail=='yes') {
-
$Html.="Backup file path: $backupDirectory/$backupFileName<br>\n";
-
$Html.="Backup file URL: $backupDownloadURL<br>\n";
-
SendMail($mailFrom,$mailFromName,$mailTo,$mailToName,$mailSubject,$Text,$Html,'false');
-
}
-
# /send information mail
-
-
# send backup file to e-mail
-
if ($sendBackupFileToMail=='yes') {
-
if ($deleteBackupFile=='no') {
-
$Html.="Backup file path: $backupDirectory/$backupFileName<br>\n";
-
$Html.="Backup file URL: $backupDownloadURL<br>\n";
-
}
-
$ATTM=array($backupDirectory/$backupFileName); // more files can be added: $ATTM=array("/home/myself/test/go.jpg", "/home/myself/test/SomeDoc.pdf");
-
SendMail($mailFrom,$mailFromName,$mailTo,$mailToName,$mailSubject,$Text,$Html,$ATTM);
-
}
-
# /send backup file to e-mail
-
-
-
# delete old backup files
-
if ($deleteOldBackupFiles=='yes') {
-
if(!$link) {
-
}
-
else {
-
}
-
}
-
}
-
# /delete old backup files
-
-
-
# delete backup file
-
if ($deleteBackupFile=='yes') {
-
if(!$delete) {
-
}
-
}
-
# /delete backup file
-
-
-
/*
-
This might be some useful stuff to send out emails in either text
-
or html or multipart version, and attach one or more files or even
-
none to it. Inspired by Kieran's msg above, I thought it might be
-
useful to have a complete function for doing this, so it can be used
-
wherever it's needed. Anyway I am not too sure how this script will
-
behave under Windows.
-
-
{br} represent the HTML-tag for line break and should be replaced,
-
but I did not know how to not get the original tag parsed here.
-
-
function SendMail($From, $FromName, $To, $ToName, $Subject, $Text, $Html, $AttmFiles)
-
$From ... sender mail address like "my@address.com"
-
$FromName ... sender name like "My Name"
-
$To ... recipient mail address like "your@address.com"
-
$ToName ... recipients name like "Your Name"
-
$Subject ... subject of the mail like "This is my first testmail"
-
$Text ... text version of the mail
-
$Html ... html version of the mail
-
$AttmFiles ... array containing the filenames to attach like array("file1","file2")
-
*/
-
-
function SendMail($From,$FromName,$To,$ToName,$Subject,$Text,$Html,$AttmFiles){
-
$OB="----=_OuterBoundary_000";
-
$IB="----=_InnerBoundery_001";
-
$Text=$Text?$Text:"Sorry, but you need an html mailer to read this mail.";
-
-
$headers ="MIME-Version: 1.0\r\n";
-
$headers.="From: ".$FromName." <".$From.">\n";
-
$headers.="To: ".$ToName." <".$To.">\n";
-
$headers.="Reply-To: ".$FromName." <".$From.">\n";
-
$headers.="X-Priority: 1\n";
-
$headers.="X-MSMail-Priority: High\n";
-
$headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n";
-
-
//Messages start with text/html alternatives in OB
-
$Msg ="This is a multi-part message in MIME format.\n";
-
$Msg.="\n--".$OB."\n";
-
$Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n";
-
-
//plaintext section
-
$Msg.="\n--".$IB."\n";
-
$Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
-
$Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
-
// plaintext goes here
-
$Msg.=$Text."\n\n";
-
-
// html section
-
$Msg.="\n--".$IB."\n";
-
$Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
-
$Msg.="Content-Transfer-Encoding: base64\n\n";
-
// html goes here
-
-
// end of IB
-
$Msg.="\n--".$IB."--\n";
-
-
// attachments
-
if($AttmFiles){
-
foreach($AttmFiles as $AttmFile){
-
$Msg.= "\n--".$OB."\n";
-
$Msg.="Content-Type: application/octetstream;\n\tname=\"".$FileName."\"\n";
-
$Msg.="Content-Transfer-Encoding: base64\n";
-
$Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n";
-
-
//file goes here
-
$Msg.=$FileContent;
-
$Msg.="\n\n";
-
}
-
}
-
-
//message ends
-
$Msg.="\n--".$OB."--\n";
-
//syslog(LOG_INFO,"Mail: Message sent to $ToName <$To>");
-
}
Yazdır
| 1,143 Görüntülenme | Kategori: PHP, Veritabanları & SQL |
Geri İzleme
Etiketler: mysql, mysql otomatik yedek, PHP, yedek, fonksiyon, backupBenzer Yazılar
Yorum Yap
XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

8 Ocak 2008 |

