Linux Uzak Ftp Adresine Yedek Aldırmak [Remote Ftp Backup Script]
24 Temmuz 2014 Yorum 0 1011 Görüntüleme

Linux Uzak Ftp Adresine Yedek Aldırmak [Remote Ftp Backup Script]

blank_computer_screen[1]Linux sunucularda kullandığınız kontrol paneline bağlı olarak.Aldığınız yedekleri zamanlı olarak size ait başka sunucuda olan ftp hesabınıza yükletmeye yarayan php ve bash script destekli yazılımı veriyorum.Yazılım arayüzü oldukca basit.

 

Demo : http://bash.cyberciti.biz/backup/wizard-ftp-script.php

 

<?php
/****************************************************************
 * Copyright (c) 2005-2006 nixCraft <http://www.cyberciti.biz/>
 * This script is licensed under GNU GPL version 2.0 or above
 * You are free to copy, modify, improve - php source code under
 * GNU GPL version 2.0 or above.
 ****************************************************************/

// Make sure form is submitted by user
if(!(isset($_POST['showftpscript']))) {
 // if not display them form
  writeHead("FTP MySQL and Webserver System Backup script",true);
  writeForm();
  writeFoot();
}
else {
 $_POST['dirs'] = stripslashes(trim($_POST['dirs']));
 $_POST['ftpservername'] = stripslashes(trim($_POST['ftpservername']));
 $_POST['ftpuser'] = stripslashes(trim($_POST['ftpuser']));
 $_POST['ftppasswd'] = stripslashes(trim($_POST['ftppasswd']));
 $_POST['ftpbakdir'] = stripslashes(trim($_POST['ftpbakdir']));
 $_POST['mysqlpassword'] = stripslashes(trim($_POST['mysqlpassword']));
 $_POST['mysqluser'] = stripslashes(trim($_POST['mysqluser']));
 $_POST['mysqlhost'] = stripslashes(trim($_POST['mysqlhost']));

$OUT="#!/bin/sh\n";
$OUT .= "# System + MySQL backup script\n";
$OUT .= "# Full backup day - " .$_POST['fullbackupday']. " (rest of the day do incremental backup)\n";
$OUT .= "# Copyright (c) 2005-2006 nixCraft <http://www.cyberciti.biz/fb/>\n";
$OUT .= "# This script is licensed under GNU GPL version 2.0 or above\n";
$OUT .= "# Automatically generated by http://bash.cyberciti.biz/backup/wizard-ftp-script.php\n";
$OUT .= "# ---------------------------------------------------------------------\n";
$OUT .= "\n### System Setup ###\n";
$OUT .= 'DIRS="' .$_POST['dirs']. '"' ."\n";
$OUT .= "BACKUP=/tmp/backup.$$\n";
$OUT .= 'NOW=$(date +"%d-%m-%Y")'."\n";
$OUT .= 'INCFILE="/root/tar-inc-backup.dat"'."\n";
$OUT .= 'DAY=$(date +"%a")'."\n";
$OUT .= 'FULLBACKUP="' .$_POST['fullbackupday']. '"' ."\n"; 

$OUT .="\n### MySQL Setup ###\n";
$OUT .= 'MUSER="' .$_POST['mysqluser']. '"' ."\n";
$OUT .= 'MPASS="' .$_POST['mysqlpassword']. '"' ."\n";
$OUT .= 'MHOST="' .$_POST['mysqlhost']. '"' ."\n";
$OUT .= 'MYSQL="$(which mysql)"'."\n";
$OUT .= 'MYSQLDUMP="$(which mysqldump)"'."\n";;
$OUT .= 'GZIP="$(which gzip)"'."\n"; 

$OUT .="\n### FTP server Setup ###\n";
$OUT .= 'FTPD="' . $_POST['ftpbakdir']. '/incremental"' ."\n";
$OUT .= 'FTPU="' . $_POST['ftpuser']. '"' ."\n";
$OUT .= 'FTPP="' . $_POST['ftppasswd']. '"' ."\n";
$OUT .= 'FTPS="' . $_POST['ftpservername']. '"' ."\n";
$OUT .= 'NCFTP="$(which ncftpput)"'."\n"; 

$OUT .="\n### Other stuff ###\n";
$OUT .= 'EMAILID="'.$_POST['emailid']. '"' ."\n"; 

$OUT .= "\n### Start Backup for file system ###\n";
$OUT .= '[ ! -d $BACKUP ] && mkdir -p $BACKUP || :' ."\n";

$OUT .= "\n### See if we want to make a full backup ###\n";
$OUT .= 'if [ "$DAY" == "$FULLBACKUP" ]; then' ."\n";
$OUT .= '  FTPD="'.$_POST['ftpbakdir'].'/full"' ."\n";
$OUT .= '  FILE="fs-full-$NOW.tar.gz"' ."\n";
$OUT .= '  tar -zcvf $BACKUP/$FILE $DIRS' ."\n";
$OUT .= 'else' ."\n";
$OUT .= '  i=$(date +"%Hh%Mm%Ss")' ."\n";
$OUT .= '  FILE="fs-i-$NOW-$i.tar.gz"' ."\n";
$OUT .= '  tar -g $INCFILE -zcvf $BACKUP/$FILE $DIRS' ."\n";
$OUT .= 'fi' ."\n";

$OUT .= "\n### Start MySQL Backup ###\n";
$OUT .= "# Get all databases name\n";
$OUT .= 'DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse \'show databases\')"' ."\n";
$OUT .= 'for db in $DBS' ."\n";
$OUT .= 'do' ."\n";
$OUT .= ' FILE=$BACKUP/mysql-$db.$NOW-$(date +"%T").gz' ."\n";
$OUT .= ' $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE' ."\n";
$OUT .= 'done' ."\n";

$OUT .= "\n### Dump backup using FTP ###\n#Start FTP backup using ncftp\n";
$OUT .= 'ncftp -u"$FTPU" -p"$FTPP" $FTPS&lt;&lt;EOF' ."\n";
$OUT .= 'mkdir $FTPD' ."\n";
$OUT .= 'mkdir $FTPD/$NOW' ."\n";
$OUT .= 'cd $FTPD/$NOW' ."\n";
$OUT .= 'lcd $BACKUP' ."\n";
$OUT .= 'mput *' ."\n";
$OUT .= 'quit' ."\n";
$OUT .= 'EOF' ."\n";

$OUT .= "\n### Find out if ftp backup failed or not ###\n";
$OUT .= 'if [ "$?" == "0" ]; then' ."\n";
$OUT .= ' rm -f $BACKUP/*' ."\n";
$OUT .= 'else' ."\n";
$OUT .= ' T=/tmp/backup.fail' ."\n";
$OUT .= ' echo "Date: $(date)">$T' ."\n";
$OUT .= ' echo "Hostname: $(hostname)" >>$T' ."\n";
$OUT .= ' echo "Backup failed" >>$T' ."\n";

$OUT .= ' mail  -s "BACKUP FAILED" "$EMAILID" &lt;$T' ."\n";
$OUT .= ' rm -f $T' ."\n";
$OUT .= 'fi' ."\n";

writeHead("Your Shell Script code",false);
echo "<p>Your Shell Script code:</p>\n\n";
echo '<p><textarea readonly rows="20" cols="95" onclick="this.focus();this.select()">'.$OUT."</textarea></p>\n\n";
echo "<p><a href='wizard-ftp-script.php'>&lt;&lt; Back to Script Setup</a>\n";
echo " | <a href='http://bash.cyberciti.biz/'>Shell script home</a> | <a href='http://www.cyberciti.biz/tips/how-to-backup-mysql-databases-web-server-files-to-a-ftp-server-automatically.html'>Back to article</a> </p>\n";
writeFoot();
}

function writeForm() {

echo '
<h3>Use following form to generate backup ftp script <span style="color: rgb(255, 0, 0);">:)</span></h3>

<script>
function checkForm() {
if (document.forms.backupFtpScript.elements[\'lbldirs\'].value.length == 0) {
    alert(\'Please enter a value for the "Backup directory name" field\');
    return false;
}
if (document.forms.backupFtpScript.elements[\'lblftpservername\'].value.length == 0) {
    alert(\'Please enter a value for the "FTP Server Name" field\');
    return false;
}

if (document.forms.backupFtpScript.elements[\'lblftpuser\'].value.length == 0) {
    alert(\'Please enter a value for the "FTP User Name" field\');
    return false;
}

if (document.forms.backupFtpScript.elements[\'lblftppasswd\'].value.length == 0) {
    alert(\'Please enter a value for the "FTP User Password" field\');
    return false;
}

if (document.forms.backupFtpScript.elements[\'lblftpbakdir\'].value.length == 0) {
    alert(\'Please enter a value for the "FTP Backup directory" field\');
    return false;
}

if (document.forms.backupFtpScript.elements[\'lblmysqlpassword\'].value.length == 0) {
    alert(\'Please enter a value for the "MySQL User Password" field\');
    return false;
}

if (document.forms.backupFtpScript.elements[\'lblmysqluser\'].value.length == 0) {
    alert(\'Please enter a value for the "MySQL User Name" field\');
    return false;
}

if (document.forms.backupFtpScript.elements[\'lblmysqlhost\'].value.length == 0) {
    alert(\'Please enter a value for the "MySQL Server Host Name" field\');
    return false;
}

if (document.forms.backupFtpScript.elements[\'lblemailid\'].value.length == 0) {
    alert(\'Please enter a value for the "MySQL Server Host Name" field\');
    return false;
}

  return true;
}
</script>

<div class="nixcraftWizform">
<form action="wizard-ftp-script.php" method="post" onSubmit="return checkForm()" name="backupFtpScript">
<div class="nixcraftWizleft"><label for="lbldirs">Backup directory name(s): </label></div>
<div class="nixcraftWizright"><input type="text" name="dirs" id="lbldirs" size="50" maxlength="300" value="/etc /home"  /> <small>(White/blank space separated directory name)</small></div>

<div class="nixcraftWizleft"><label for="lblftpservername">FTP Server name/ip address: </label></div>
<div class="nixcraftWizright"><input type="text" name="ftpservername" id="lblftpservername" size="30" maxlength="50" value="192.168.1.100" /> <small>(Example: ftp.yourdomain.com)</small></div>

<div class="nixcraftWizleft"><label for="lblftpuser">FTP User Login name: </label></div>
<div class="nixcraftWizright"><input type="text" name="ftpuser" id="lblftpuser" size="30" maxlength="50" value="" /> <small>(Remote FTP Server User Name)</small></div>

<div class="nixcraftWizleft"><label for="lblftppasswd">FTP User Password: </label></div>
<div class="nixcraftWizright"><input type="text" name="ftppasswd" id="lblftppasswd" size="30" maxlength="50" value="" /> <small>(Remote FTP Password)</small></div>

<div class="nixcraftWizleft"><label for="lblftpbakdir">FTP Path: </label></div>
<div class="nixcraftWizright"><input type="text" name="ftpbakdir" id="lblftpbakdir" size="30" maxlength="50" value="/" /> <small>(This path must already exist on your server)</small></div>

<div class="nixcraftWizleft"><label for="lblmysqlhost">MySQL Hostname/IP address Name: </label></div>
<div class="nixcraftWizright"><input type="text" name="mysqlhost" id="lblmysqlhost" size="30" maxlength="50" value="localhost" /> <small>(Default is localhost)</small></div>

<div class="nixcraftWizleft"><label for="lblmysqluser">MySQL User Name: </label></div>
<div class="nixcraftWizright"><input type="text" name="mysqluser" id="lblmysqluser" size="30" maxlength="50" value="root" /> <small>(default is root or admin)</small></div>

<div class="nixcraftWizleft"><label for="lblmysqlpassword">MySQL User Password: </label></div>
<div class="nixcraftWizright"><input type="text" name="mysqlpassword" id="lblmysqlpassword" size="30" maxlength="50" value="" /> <small>(MySQL User Password)</small></div>

<div class="nixcraftWizleft"><label for="lblfullday">Select full backup day: </label></div>
<div class="nixcraftWizright"><select name="fullbackupday">
<option value="Sun">Sunday</option>
<option value="Mon">Monday</option>
<option value="Tue">Tuesday</option>
<option value="Wed">Wednesday</option>
<option value="Thu">Thursday</option>
<option value="Fri">Friday</option>
<option value="Sat">Saturday</option>
</select> <small>(Full backup day)</small>
</div>

<div class="nixcraftWizleft"><label for="lblemailid">Your (admin) Email ID: </label></div>
<div class="nixcraftWizright"><input type="text" name="emailid" id="lblemailid" size="30" maxlength="50" value="you@yourdomain.com" /> <small>(Receive an email when FTP backup fails)</small></div>

<div class="nixcraftWizright"><input type="submit" name="Submit" value="Generate FTP backup script" id="genftpscript" />
<input type="hidden" name="showftpscript" value="process" /></div>
</form>
</div>
';
}

function writeHead($title,$showcss=false){
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> ' .$title. '</title>
<script src="/mint/?js" type="text/javascript"></script>';

if ( $showcss ) writeCss();
echo '</head>
<body>';
}

/////////////////////////
function writeFoot(){
echo "<hr>\n";
echo "<center>&copy; 2005-2006 <a href='http://www.cyberciti.biz/'>nixCraft</a> - View <a href=wizard-ftp-script.php.txt>php source code</a> </center>\n";
echo "</body>\n</html>";
@include_once("/apps/include.genlib.php");
yTraceMe();
}

///////////////////////
function writeCss(){
echo '<style type="text/css" media="screen">
.nixcraftWizform {
	position: static;
	overflow: hidden;
}

.nixcraftWizleft {
	width: 25%;
	text-align: right;
	clear: both;
	float: left;
	display: inline;
	padding: 4px;
	margin: 5px 0;
}

.nixcraftWizright {
	width: 70%;
	text-align: left;
	float: right;
	display: inline;
	padding: 4px;
	margin: 5px 0;
}

.nixcraftWizerror {
	border: 1px solid #ff0000;
}

.nixcraftWizsubmit {
}

</style>
';
}

?>

Yazılımın güzel yanı yedek yüklendikten sonra size uyarı maili atabilmesi ayrıca crontab ekleyerek istediğiniz günlerde yedek aldırma özelliği mevcut.

Önceki IOS 7-8 Ücretli İçerikleri Bedava İndirmek [Ipad,Iphone,Ipod]
Sonraki Cpanel Potansiyel Spam Yapan Hesabı Tespit Etmek

Yazar hakkında

keykubad
keykubad 180 Gönderiler

2012 yılında yeni kimliği ve yeni bilgilerle sizlere teknoloji,web programlama,tasarim,güvenlik,internet ve programlar hakkında detaylı bilgiler vermek amaçlı kurulmuş kişisel web sayfamdır.

Yazara ait tüm yazılar

Diğer yazılarımız

Bilim ve Teknoloji 0 Yorum

Tarihin En Güçlü Güneş Fırtınası Carrington Olayı

Güneş Fırtınası Nedir ? Güneş lekeleri olarak bilinen bölgeler, uygun filtreleme yöntemleriyle gözlemlendiği zaman etrafına göre daha soğuk olan bölgelerdir. Bu alanlarda oluşan yüksek manyetik alan güneş püskürtüleri ve kütle

Genel 0 Yorum

Geçmişe İz Bırakan Büyük Londra Yangını

Tarih’te büyük yankı uyandıran ve iz bırakan olaylardan olan Büyük Londra Yangını kötü bir durum olmasına karşın insanlık tarihinde yeni  gelişmelerin oluşmasınada vesile olmuştur. Büyük Londra yangını Sanayi devrimini tetiklemiş

Haberler 0 Yorum

Ayda Su Bulundu Su Buzları Tespit Edildi

İnsan yaşamı için gerekli olan su ve oksijen bir gezegende yaşam için gereklidir. Uydumuz olan Ay’da su bulunması haberleri medyada fazlasıyla yer bulmaktadır. Bulunan bu su buzulları yaşam olma durumu

0 Yorum

Herhangi bir yorum yapılmamış!

İlk yazan olabilirsin bu yazıyı yorumlamak istermisin?

Cevap bırakın

This site uses Akismet to reduce spam. Learn how your comment data is processed.