• 09-12-2008, 21:06:16
    #1
       <?php 
    // Ayarlar 
    $saatfarki = 0; 
    $tarihsaat = date("d-m-Y H:i:s",(time()+3600*$saatfarki)); 
    $tarih=date("dmY",(time()+3600*$saatfarki)); 
    $site="site"; //site adı 
    $cpanel_user="site.net"; //site user name (cpanel kullanıcı adı) 
    $dizin="/home/httpd/vhosts/$cpanel_user/private"; // yedek alınacak dizinin adı 
    $yedek_dosya='backup-'.$tarih.'sql.gz'; // yedek dosyasının adı 
    $dosya_sil='evet'; // yedek oluşturulduktan sonra eski yedek dosyaları silinsin mi? 
    $yedek_sil='hayır'; // oluşturulan yedek dosyası silinsin mi? 
    $email_gonder='evet'; // yedek alındığında e-mail gönderilsin mi? 
    $dosya_gonder='evet'; // yedek, emaile gönderilsin mi? 
    $dbuser='user_user'; // veritabanı kullanıcı adı 
    $dbpass='user_pass'; // veritabanı kullanıcı şifresi 
    $dbname='user_db'; // veritabanı adı 
    $dosya_adres="$dizin/$yedek_dosya"; 
    
    // E-Mail Ayarları 
    $gonderme_tarihi=$tarihsaat; 
    $kime='user@user.com'; 
    $kime_isim='USER'; 
    $kimden='dbbackup@user.net'; 
    $kimden_isim='DBUSER'; 
    $baslik=$site.' -Veritabanı Yedeği-'.$gonderme_tarihi; 
    
    
    // Veritabanı yedeğini al 
    $x=passthru("mysqldump -u$dbuser -p$dbpass $dbname | gzip > $dizin/$yedek_dosya"); 
    $y=passthru("chmod 755 $dizin/$yedek_dosya"); 
    if (!$x || !$y) { echo "Veritabanı yedeği alınamıyor. -$x , $y-";die(); } 
    
    // yedeğin alındığını bildiren email gönder 
    if ($email_gonder=='evet') { 
        $headers="MIME-Version: 1.0\n"; 
        $headers.="Content-type: text/html; charset=iso-8859-9\n"; 
        $headers.="X-Mailer: PHP\n"; 
        $headers.="X-Sender: <PHP>\n"; 
        $headers.="From: <$kimden>\n"; 
        $headers.="Return-Path: <$kimden>\n"; 
        $mesaj=$gonderme_tarihi.' tarhinde alınan '.$site.' MySQL veritabanı yedeği '.$dizin.' dizini içindeki '.$yedek_dosya.' dosyasıdır.'; 
        mail($kime,$baslik,$mesaj,$headers); 
    } 
    
    // eski yedek dosyalarını sil 
    if ($dosya_sil=='evet') { 
        chdir($dizin); 
        $link=@opendir($dizin); 
        if(!$link){ 
            echo 'Belirtilen isimde bir klasör bulunamadı veya belirtilen yol yanlış!';die(); 
        } 
        else { 
            while($dosya=readdir($link)){ 
                if ($dosya!='.' && $dosya!='..' && $dosya!=$yedek_dosya && is_file($dosya)){ 
                     unlink($dosya); 
                 } 
            } 
            closedir($link); 
        } 
    } 
    
    // yedek dosyasını e-maile gönder 
    if ($dosya_gonder=='evet') { 
    $TEXT=""; 
    $HTML='<b>'.$gonderme_tarihi.'</b> tarhinde alınan<b> '.$site.'</b> MySQL veritabanı yedeği<br><b> '.$dizin.'</b> dizini içindeki <b>'.$yedek_dosya.' </b>dosyasıdır.'; 
    #$ATTM=array("/home/myself/test/go.jpg", "/home/myself/test/SomeDoc.pdf"); 
    $ATTM=array($dosya_adres); 
    SendMail( "$kimden","$kimden_isim", "$kime","$kime_isim",$baslik,$TEXT,$HTML,$ATTM); 
    
    
    //echo $HTML; 
    } 
    
    // yedek dosyasını sil 
    if ($yedek_sil=='evet') { 
        chdir($dizin); 
        $link=@opendir($dizin); 
        if(!$link){ echo 'Belirtilen isimde bir klasör bulunamadı veya belirtilen yol yanlış!';die(); } 
        else { unlink($yedek_dosya); } 
        closedir($link); 
    } 
    
    
    
    /* 
    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"; 
    $Html=$Html?$Html:preg_replace("/\n/","{br}",$Text) 
      or die("neither text nor html part present."); 
    $Text=$Text?$Text:"Sorry, but you need an html mailer to read this mail."; 
    $From or die("sender address missing"); 
    $To or die("recipient address missing"); 
         
    $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.="X-Mailer: My PHP Mailer\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 
    $Msg.=chunk_split(base64_encode($Html))."\n\n"; 
    
    // end of IB 
    $Msg.="\n--".$IB."--\n"; 
    
    // attachments 
    if($AttmFiles){ 
      foreach($AttmFiles as $AttmFile){ 
       $patharray = explode ("/", $AttmFile); 
       $FileName=$patharray[count($patharray)-1]; 
       $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 
       $fd=fopen ($AttmFile, "r"); 
       $FileContent=fread($fd,filesize($AttmFile)); 
       fclose ($fd); 
       $FileContent=chunk_split(base64_encode($FileContent)); 
       $Msg.=$FileContent; 
       $Msg.="\n\n"; 
      } 
    } 
         
    //message ends 
    $Msg.="\n--".$OB."--\n"; 
    mail($To,$Subject,$Msg,$headers);      
    //syslog(LOG_INFO,"Mail: Message sent to $ToName <$To>"); 
    } 
    ?>
    Alıntıdır
  • 10-12-2008, 12:11:38
    #2
    Eposta Aktivasyonu Gerekmekte
    Veritabanını yedekleme

    yedek.php diye bir dosyanın içine kopyalayın. admin paneli ile bağlantısını yapın. admin olmayanların bu sayfaya ulaşmasını engelleyin.

    <?
    $sql_host = "localhost";
    $sql_db = "";
    $sql_user = "";
    $sql_pass = "";

    function sql_connect(){
    global $conn_id,$sql_host,$sql_user,$sql_pass,$sql_db;
    $conn_id=mysql_connect($sql_host,$sql_user,$sql_pa ss);
    if(!$conn_id){echo"mysql bağlantı hatası"; exit;}
    $conn_db=mysql_select_db($sql_db);
    if(!$conn_db){echo"mysql veritabanı bağlantı hatası"; exit;}
    }
    sql_connect();

    $tarih = date('Y-m-d');
    $saat = date("H:i");
    $dosya_adi="veritabani";
    $ad="$dosya_adi"."+"."$tarih"."+"."$saat".".sql";
    header("Content-disposition: attachment; filename=$ad");
    header("Content-Type: text/plain; charset=UTF-8");
    @mysql_query("SET NAMES 'latin5'");
    $tablolar=mysql_list_tables($sql_db);
    $tablosayisi=mysql_num_rows($tablolar);
    for ($a=0;$a<$tablosayisi;$a++)
    {
    $row=mysql_fetch_row($tablolar);
    $tablename=$row[0];
    @mysql_query("SET NAMES 'latin5'");
    $crtable=mysql_query("show create table $tablename");
    $tmpres = mysql_fetch_row($crtable);
    echo "\n\n";
    echo $tmpres[1].";";
    echo "\n\n";
    @mysql_query("SET NAMES 'latin5'");
    $alanlar=mysql_query("select * from `$tablename`");
    $alansayisi=mysql_num_fields($alanlar);
    $nr=mysql_num_rows($alanlar);
    for ($c=0;$c<$nr;$c++)
    {
    echo "INSERT INTO `$tablename` VALUES (";
    $row=mysql_fetch_row($alanlar);
    for ($d=0;$d<$alansayisi;$d++)
    {
    $data=strval($row[$d]);
    echo "'".addslashes($data)."'";
    if ($d<($alansayisi-1))
    {
    echo ", ";
    }
    }
    echo ");\n";
    }
    }

    ?>