查看: 1619|回復: 3

[已解決] Tenny come~

[複製鏈接]
發表於 2009-1-31 20:30:25 | 顯示全部樓層 |閱讀模式
[隱藏]

馬上註冊,結交更多好友,享用更多功能,讓你輕鬆玩轉社區。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
  1. <?php
  2. // 設定資料庫變數
  3. $dbhost = 'localhost'; //  MySQL伺服器位置 (資料庫放同主機則不需更動)
  4. $dbuser = 'your_username'; // MySQL資料庫使用者名稱
  5. $dbpass = 'yourpass'; // MySQL資料庫登入密碼
  6. $dbname = 'database_name'; // 資料庫名稱

  7. // 選擇性設定

  8. $use_gzip = "yes";  // 是否需要gzip壓縮 (建議壓縮)
  9. $remove_sql_file = "yes"; // 壓縮後是否刪除原本的sql檔, 建議刪除
  10. $remove_gzip_file = "no"; // 是否需要刪除gzip檔案, 建議不刪除 (除非空間很大, 否則建議刪除)

  11. // 設定路徑

  12. $savepath = "/www/htdocs/dbsender"; // 檔案放置目錄完整路徑, 最後不加斜線 (cpanel通常使用者主目錄在/home/使用者帳號)

  13. $send_email = "yes";  // 是否用e-mail傳檔, 若是請填下列兩行
  14. $to      = "you@yourdomain.com";  // 收信人
  15. $from    = "r00t@yourdomain.com"; // 寄信人 (可填不用的信箱, 幫助信件自動分類)

  16. $senddate = date("j F Y");

  17. $subject = "MySQL Database Backup - $senddate"; // 信件標題 ($senddate是加入日期)
  18. $message = "Your MySQL database has been backed up and is attached to this email"; // 信件內容

  19. $use_ftp = "yes"; // 是否上傳至FTP伺服器, 若是請填下列四行
  20. $ftp_server = "localhost"; // FTP位置 (例如ftp.server.com)
  21. $ftp_user_name = "ftp_username"; // FTP帳號
  22. $ftp_user_pass = "ftp_password"; // FTP密碼
  23. $ftp_path = "/"; // 上傳至FTP的路徑






  24. // 以下的部份不用更改

  25.         $date = date("mdy-hia");
  26.         $filename = "$savepath/$dbname-$date.sql";        
  27.         passthru("mysqldump --opt -h$dbhost -u$dbuser -p$dbpass $dbname >$filename");
  28.         
  29.         if($use_gzip=="yes"){
  30.                 $zipline = "tar -czf ".$dbname."-".$date."_sql.tar.gz $dbname-$date.sql";
  31.                 shell_exec($zipline);
  32.         }
  33.         if($remove_sql_file=="yes"){
  34.                 exec("rm -r -f $filename");
  35.         }
  36.         
  37.         if($use_gzip=="yes"){
  38.                 $filename2 = "$savepath/".$dbname."-".$date."_sql.tar.gz";
  39.         } else {
  40.                 $filename2 = "$savepath/$dbname-$date.sql";
  41.         }
  42.         
  43.         
  44.         if($send_email == "yes" ){
  45.                 $fileatt_type = filetype($filename2);
  46.                 $fileatt_name = "".$dbname."-".$date."_sql.tar.gz";
  47.                
  48.                 $headers = "From: $from";
  49.                
  50.                 // Read the file to be attached ('rb' = read binary)
  51.                 $file = fopen($filename2,'rb');
  52.                 $data = fread($file,filesize($filename2));
  53.                 fclose($file);
  54.         
  55.                 // Generate a boundary string
  56.                 $semi_rand = md5(time());
  57.                 $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  58.         
  59.                 // Add the headers for a file attachment
  60.                 $headers .= "\nMIME-Version: 1.0\n" ."Content-Type: multipart/mixed;\n" ." boundary="{$mime_boundary}"";
  61.         
  62.                 // Add a multipart boundary above the plain message
  63.                 $message = "This is a multi-part message in MIME format.\n\n" ."--{$mime_boundary}\n" ."Content-Type: text/plain; charset="iso-8859-1"\n" ."Content-Transfer-Encoding: 7bit\n\n" .
  64.                 $message . "\n\n";
  65.         
  66.                 // Base64 encode the file data
  67.                 $data = chunk_split(base64_encode($data));
  68.         
  69.                 // Add file attachment to the message
  70.                 $message .= "--{$mime_boundary}\n" ."Content-Type: {$fileatt_type};\n" ." name="{$fileatt_name}"\n" ."Content-Disposition: attachment;\n" ." filename="{$fileatt_name}"\n" ."Content-Transfer-Encoding: base64\n\n" .
  71.                 $data . "\n\n" ."--{$mime_boundary}--\n";
  72.         
  73.                 // Send the message
  74.                 $ok = @mail($to, $subject, $message, $headers);
  75.                 if ($ok) {
  76.                         echo "<h4><center>Database backup created and sent! File name $filename2</center></h4>";
  77.                 } else {
  78.                         echo "<h4><center>Mail could not be sent. Sorry!</center></h4>";
  79.                 }
  80.         }
  81.         
  82.         if($use_ftp == "yes"){
  83.                 $ftpconnect = "ncftpput -u $ftp_user_name -p $ftp_user_pass -d debsender_ftplog.log -e dbsender_ftplog2.log -a -E -V $ftp_server $ftp_path $filename2";
  84.                 shell_exec($ftpconnect);
  85.                 echo "<h4><center>$filename2 Was created and uploaded to your FTP server!</center></h4>";
  86.         
  87.         }
  88.         
  89.         if($remove_gzip_file=="yes"){
  90.                 exec("rm -r -f $filename2");
  91.         }

  92. ?>
複製代碼
呢個係資料庫自動備份php

點點備一次????
係咪run 一次 就備一次?
發表於 2009-1-31 21:53:11 | 顯示全部樓層
1# +_.偉仔


建議使用directadmin或phpmyadmin 備份, 再用 bigdump 還原.
回復

使用道具 舉報

發表於 2009-5-1 20:53:39 | 顯示全部樓層
唔係好明bo
回復

使用道具 舉報

發表於 2010-11-9 18:38:03 | 顯示全部樓層
將個檔copy一次咪得囉
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|排行榜|幫助|希望國度

GMT+8, 2024-5-5 21:16 , Processed in 0.063207 second(s), 14 queries .

Theme Design By Tenny (希望國度)| Version: 10.0

Powered by Discuz! X3.4 © 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表