|
|
| |||||||
| Site & Server Administration Server Yönetimi hakkında, .htaccess, Apache configuration ve log analiz, güvenlik |
| |
|
| | | LinkBack | Seçenekler |
| |||
| Merhaba Arkadaşlar, Bu konu hakkında açılmış bir çok konu gördüm. Bende böyle bir script geliştirmeye karar verdim. Şimdi size script'i tanıtacağım. Kullanımı hakkında bilgi vermeye çalışacağım bu konuda. cPanel en son sürümlerinde x ve x2 teması kaldırılmış. Kullanılmasıda şuanda önerilmiyor. Bu sebeple script x3 temasını kullanan siteler için özeldir. RVskin kullanan siteleri kapsamamaktadır. Özel olarak kullandığınız tema varsa belirtiniz ilgili özelliği scripte ekleriz. Sistemin genel mantığı Curl ile whm ye bağlanma ardından reseller hesabından alt sitelere ulaşmak ve full backup almak şeklindedir. Scriptin düzenli çalışabilmesi için accountlar arasından geçiş izninin bulunması lazımdır. Gelelim Script ve Kullanımına: Öncelikle script'i indiriyoruz. İndirmek İçin Tıklayınız -- İndireceğiniz Dosya İçeriği: reseller-backup.php : Yedekleme fonksiyonu dosya içerisinde bulunur. example.php : Kullanım için örnek bulunmaktadır. backups.log : İşlem sırasında yedeği alınamayan siteleri içerir cookies.txt : cPanel bağlanma işlemi sırasında cookie bilgilerini içerir. Aslında dosya içerisinde yüzeysel olarak example.php de kullanımdan söz ettim.Ancak php ile arası pek iyi olmayan arkadaşlar için burda detay vereceğim. -- Kullanım: Dosyalarımızı çektikten sonra bir php dosyası oluşturuyoruz. Örneğin adı yedekle.php olan bir php dosyası oluşturduk.Yedekle.php nin içeriği kullanım isteğimize göre farklı olacaktır. Burda kafa karıştırıcı olarak backup fonksiyonunda 1 ile belirttiğim yer olabilir. Şayet SSL üzerinden bağlantı istiyorsak (2083/2087) bu değer 1 olacak. Fakat ssl'siz bağlantı istiyorsak bu değer 0 olacaktır(2082/2086). Şayet Homedir dizinine yedek almak istiyorsak aşağıdaki gibi bir kullanım olacaktır. PHP- Kodu: PHP- Kodu: PHP- Kodu: PHP- Kodu: Mesela homedir dizinine yedekleme için aşağıdaki gibi olacak, ftp,passive ftp, scp içinde mantık aynı <?php sonrasına set_time_limit(0); yazılacak PHP- Kodu: Minute 30 Hour 02 Day * Month * Weekday * Command php -f /home/ali/www/public_html/backup/yedekle.php Şeklinde ayarlıyoruz. Curl ile yedekler alınacağı için sunucunun önemi yoktur. Cronjobs olan, php4 ve üstü desteği olan ayrıca curl kütüphanesi bulunan herhangi bir sunucu üzerinden script çalışabilir.Yani yedeklenecek sunucu ile scriptin aynı sunucuda bulunması şart değildir. Güvenlik açısından /home/ali/public_html/backup klasörünü şifrelerseniz daha iyi olur. Ayrıca backups.log ve cookies.txt sayfalarının chmodlarını 0 layınız. Cookies ve backups.log bilgilerinin görülmesini istemeyiz. Ayrıca yedekle.php yi zendlerseniz şifrelerin korunması açısından ekstra önlem alabilirsiniz. Bunun yanında cron ayarını kullanacaksanız gerçekte olmayan bir siteyi temel alarak cron ayarlarını yaparsanız ekstra güvenlik sağlamış olursunuz. Saygılarımla... Kaynak: http://hostingsiteniz.com/genel/cpan...ti-t665.0.html
__________________ Faaliyet Belge : YS ( 1154 ) Hostingsiteniz.NET Konu HS_Abdullah tarafından (22-08-2011 Saat 15:40:41 ) değiştirilmiştir.. |
| |||
| Alıntı:
Yorumunuz için teşekkür ederim. Scriptin güvenlik bakımından problem olabilecek tek yanı içerisinde whm kullanıcı adı ve whm şifrelerinin bulunması. Aşağıdaki şekilde bunun önüne büyük ölçüde geçebiliriz. Yedeğin alındığı yerin herhangi bir önemi bulunmamakta. Mesela: whm ye boylebirsiteyok.yok şeklinde bir site eklersiniz. Sonrasında bu site üzerinde cron ayarını gerçekleştirirsiniz. bunun yanında yedekle.php yi zendleyebilirsiniz.
__________________ Faaliyet Belge : YS ( 1154 ) Hostingsiteniz.NET Konu HS_Abdullah tarafından (22-08-2011 Saat 15:41:49 ) değiştirilmiştir.. |
| |||
| Merhaba, Bu arada geçen sene böyle bir konu daha açılmış hatta sizde mesaj yazmışsınız: http://www.r10.net/cpanel-amp-plesk/...up-script.html |
| |||
| Alıntı:
__________________ Faaliyet Belge : YS ( 1154 ) Hostingsiteniz.NET |
| |||
| Alıntı:
__________________ Faaliyet Belge : YS ( 1154 ) Hostingsiteniz.NET |
| | |||
| Abdullah abi merhaba sizin vermiş olduğunuz scrip ile yedeklerimi alıyordum. Datacenter serverları centos 6 ya geçirince yedek almamaya başladı. Curl versiyonu güncellenmiş ne yapmam lazım yardımcı olursanız çok sevinirim. Teşekkürler Versiyon aşağıdaki gibidir. curl-7.19.7-26.el6_1.2.x86_64 Konu minemos tarafından (08-05-2012 Saat 10:24:47 ) değiştirilmiştir.. |
| | |||
| Merhaba çalışan bir script buldum kendim test ettim çalışıyor. http://forums.cpanel.net/f49/automat...em-149029.html Kod: <?php
/*
dv at josheli.com
3/4/2004
What it does:
It will request cpanel make full backups of all accounts under a reseller.
It uses cURL, optionally over SSL.
How it works:
Reads all accounts (domain, cpanel and username specifically) from the listaccts page in WHM
Uses cUrl over SSL to call the dofullbackup script of cpanel for each account, using the
account's username and the reseller's password
This script doesn't require cron, but could use it.
Cron for Windows:
http://www.kalab.com/freeware/cron/cron.htm
Instructions:
1. Make sure you have the curl extension for PHP available
2. Modify "config" variables below, to suit
3. From the command prompt:
>php bkup_full.php
4. ([Or] Optionally) Set up a cron job to call this script
5. If you're going to have it ftp somewhere, make sure that server is setup correctly
6. Since it could take several minutes to generate the backup and ftp it,
and you can't have this request script just waiting around trying to
figure out if the backup/ftp cycle is complete, it might be beneficial
to have another script check for completion, and delete the generated
backup if there was success.
*/
/*** BEGIN CONFIG ***/
$reseller = 'www.domain.co.uk';//your reseller url
$whmUser = 'whm username';//your web host manager user name
$whmPass = 'whm password';//your web host manager password
$bkUpReseller = true;//backup the reseller account also? (it's not in the listaccts page)
$resellerCpTheme = 'x';//if you want to back up reseller, we need the reseller cpanel theme
/*
Destination for the backup...
$destType = '/';// Home Directory
$destType = 'ftp';// Remote FTP Server
$destType = 'passiveftp'; //Remove FTP Server (Passive mode transfer)
*/
$destType = 'ftp';//^^^
$destServer = 'ftp.domain.co.uk';//only if $destServer = 'ftp' or 'passiveftp'
$destUser = 'ftp usernam';//only if $destServer = 'ftp' or 'passiveftp'
$destPass = 'ftp password';//only if $destServer = 'ftp' or 'passiveftp'
$destEmail = 'email';//optional; cpanel will send an email when generation is complete
$destRdir = '/public_html/backup/'; // not quite use on the format for this yet (still testing, will update once known)
$destPort = 21;
$logType = 'echo';//output a log to 'file' or 'echo' or 'none'(no log)
$logFileName = 'bkup_full_log.txt';//can include a path too; only makes sense if $logType = 'file'
$useSsl = false;//if true, requires SSL on your site, or modify this script to use the shared SSL; this hasn't really been tested
/*
A comma-separated list of domain names to backup;
Leave blank to backup all domains found in reseller WHM
If not blank, ONLY the domains listed will be backed up.
If listed, the domains must be listed EXACTLY like they appear on the
list accounts page in WHM, i.e. usually without 'www.'
$domains = 'example1.com,example2.net';
*/
$domains = '';
/*** END CONFIG ***/
/*** BEGIN MAIN ***/
set_time_limit(0);
$time_start = getMicroTime();
if (!extension_loaded('curl')) {
dl('php_curl.' .PHP_SHLIB_SUFFIX) or die("Could not load curl extension");
}
if($useSsl) {
$protocol = 'https://';
$cpPort = '2083';
$whmPort = '2087';
writeLog("Using SSL.\n");
}
else {
$protocol = 'http://';
$cpPort = '2082';
$whmPort = '2086';
writeLog("Not using SSL.\n");
}
$domains = trim($domains);
if(!empty($domains)){
$chkDoms = true;
$domains = explode(',',$domains);
foreach($domains as $d){
$domains[] = trim($d);
}
}
else {
$chkDoms = false;
$domains = array();
}
//$postFields = urlencode("dest=$destType&server=$destServer&user=$destPass&pass=$destPass&email=$destEmail");
$postFields = '';
$postArray = array();
$postArray['dest'] = $destType;
$postArray['server'] = $destServer;
$postArray['user'] = $destUser;
$postArray['pass'] = $destPass;
$postArray['email'] = $destEmail;
$postArray['rdir'] = $destRdir;
$postArray['port'] = $destPort;
$thingy = '';
foreach ($postArray as $k=>$v)
{
$thingy.= "$k=".utf8_encode($v).'&';
}
$postFields = substr($thingy,0,-1);
//get the WHM 'list accounts' page
writeLog("Retrieving WHM accounts page...\n");
$acctsPage = getByCurl("$protocol$reseller:$whmPort/scripts/fetchcsv",$whmUser,$whmPass);
//var_dump($acctsPage);
$accounts = array();
$accounts = explode("\n", trim($acctsPage));
//var_dump($accounts);
$account_records = array();
foreach ($accounts as $row) {
$account_records[] = explode(',', $row);
}
writeLog("Parsing accounts...\n");
//var_dump($account_records);
//die('here');
foreach($account_records as $match) {
$accDom = '';
$accUser = '';
$accTheme = '';
$r = '';
$fullUrl = '';
//$accDom = strip_tags(trim($match[1]));//domain - replaced with below
$accDom = strip_tags(trim($match[0]));//domain
if($chkDoms)
if(!in_array($accDom,$domains)) continue;
//$accUser = strip_tags(trim($match[3]));//username - replaced with below
$accUser = strip_tags(trim($match[2]));//username
//$accTheme = strip_tags(trim($match[14]));//cpanel theme - replaced with below
$accTheme = strip_tags(trim($match[9]));//cpanel theme
$fullUrl = "$protocol$accDom:$cpPort/frontend/$accTheme/backup/dofullbackup.html";
writeLog("Requesting backup of $accDom...\n");
$r =& getByCurl($fullUrl,$accUser,$whmPass,array('CURLOPT_POST'=>$postFields));
if($r === false){
writeLog("Backup request of $accDom caused an unknown error.\n");
}
else {
writeLog("Backup request of $accDom complete.\n");
}
//writeLog("\n\n--$accDom--\n\n$r\n\n------\n\n");
}
if($bkUpReseller){
$fullUrl = "$protocol$reseller:$cpPort/frontend/$resellerCpTheme/backup/dofullbackup.html";
writeLog("Requesting backup of $reseller...\n");
$r =& getByCurl($fullUrl,$accUser,$whmPass,array('CURLOPT_POST'=>$postFields));
}
$time_end = getMicroTime();
$time = $time_end - $time_start;
writeLog("Elapsed time: ".round($time,2)." seconds.\n");
/*** BEGIN FUNCTIONS ***/
function getByCurl($url, $user = '', $pass = '',$extra = '') {
global $useSsl;
$ch = curl_init();
//tells curl to save result in a variable instead of outputing to page
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
curl_setopt ($ch, CURLOPT_COOKIEJAR, './cookie.txt');
//curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,1); //need safe_mode turning off for this bit
if(!empty($extra) && is_array($extra)){
foreach($extra as $opt=>$val){
switch($opt){
case 'CURLOPT_REFERER':
curl_setopt($ch,CURLOPT_REFERER,$val);
break;
case 'CURLOPT_POST':
case 'CURLOPT_POSTFIELDS':
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$val);
break;
}
}
}
if($useSsl){
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
}
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function writeLog($entry) {
global $logType,$logFileName;
$method = strtolower($logType);
$entry = date('r').' - '.$entry;
if($method == 'file') {
$fp = fopen($logFileName,'ab');
fwrite($fp, $entry);
fclose($fp);
} elseif($method == 'echo'){
echo nl2br($entry);//browser
flush();
}
return;
}
function getMicroTime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
?> |
![]() |
| Bookmarks |
| Seçenekler | |
| |