PDA

View Full Version : سوال: گرفتن backup از دیتابیس



soroush.r70
پنج شنبه 09 شهریور 1391, 13:53 عصر
من یه اسکریپت گیر اوردم می خوام ازش استفاده کنم می خواستم بدونم این اسکریپت وقتی توی فایل php بذارم و در داخل هاستم قرار بدم این اسکریپت خودش به صورت اتوماتیک backup می گیره و ارسال می کنه و ارسال اتوماتیک هر چند وقت یک باره...؟


<?php
$datestamp = date("Y-m-d"); // Current date to append to filename of backup file in format of YYYY-MM-DD

/* CONFIGURE THE FOLLOWING SEVEN VARIABLES TO MATCH YOUR SETUP */
$dbuser = ""; // Database username
$dbpwd = ""; // Database password
$dbname = ""; // Database name. Use --all-databases if you have more than one
$filename= "backup-$datestamp.sql.gz"; // The name (and optionally path) of the dump file
$to = "you@remotesite.com"; // Email address to send dump file to
$from = "you@yourhost.com"; // Email address message will show as coming from.
$subject = "MySQL backup file"; // Subject of email

$command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename";
$result = passthru($command);

$attachmentname = array_pop(explode("/", $filename)); // If a path was included, strip it out for the attachment name

$message = "Compressed database backup file $attachmentname attached.";
$mime_boundary = "< <<:" . md5(time());
$data = chunk_split(base64_encode(implode("", file($filename))));

$headers = "From: $from\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/mixed;\r\n";
$headers .= " boundary=\"".$mime_boundary."\"\r\n";

$content = "This is a multi-part message in MIME format.\r\n\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$content.= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$content.= $message."\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Disposition: attachment;\r\n";
$content.= "Content-Type: Application/Octet-Stream; name=\"$attachmentname\"\r\n";
$content.= "Content-Transfer-Encoding: base64\r\n\r\n";
$content.= $data."\r\n";
$content.= "--" . $mime_boundary . "\r\n";

mail($to, $subject, $content, $headers);

unlink($filename); //delete the backup file from the server
?>

Unique
پنج شنبه 09 شهریور 1391, 14:23 عصر
جرا امتحانش نمیکنین ؟
البته داره ایمیل میکنه که برای database های بزرگ زیاد جالب نیست !
mysqldump بهترین ابزار برای backup هست و اگه شما امکان اجرای command را توی هاستتون داشته باشین مشکلی نخواهد بود !

soroush.r70
پنج شنبه 09 شهریور 1391, 17:47 عصر
خوب هر چند وقت یک بار بک آپ گیری اتوماتیک انجام می ده و ارسال می کنه...؟

Unique
جمعه 10 شهریور 1391, 00:11 صبح
یک اسکریپته و باید مثلا با cron jobs هر زمانی نیاز دارین اجراش کنید ! روزانه ! هفتگی یا ماهانه ! خودش نمیتونه خودش را اجرا کنه !

soroush.r70
شنبه 11 شهریور 1391, 10:05 صبح
در موقع استفاده از اسکریپت بالا خطاهای زیر رخ می ده و بک آپ به ایمیلم ارسال می شه ولی فایلی دانلود نمی شه دلیلش چیه...؟


Warning: passthru() has been disabled for security reasons in /home/realdesi/domains/realdesign.ir/public_html/1/soroushif/backup.php on line 14

Warning: file(backup-2012-09-01.sql.gz) [function.file]: failed to open stream: No such file or directory in /home/realdesi/domains/realdesign.ir/public_html/1/soroushif/backup.php on line 20

Warning: implode() [function.implode]: Invalid arguments passed in /home/realdesi/domains/realdesign.ir/public_html/1/soroushif/backup.php on line 20

Warning: unlink(backup-2012-09-01.sql.gz) [function.unlink]: No such file or directory in /home/realdesi/domains/realdesign.ir/public_html/1/soroushif/backup.php on line 41

Unique
شنبه 11 شهریور 1391, 15:50 عصر
همه warning ها به اولی بر میگرده ! همونطور که حدس میزدم شما دارین از هاست shared استفاده میکنید و passthru که دستوری شبیه به exec هست را محدود کرده اند ! برای این اسکریپت هاست مجازی یا اختصاصی نیاز دارین !