المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : [xBackup.sh] لتسهيل عملية الباك اب buckup الخارجي لسيرفر SERVERك السي بنل!



linnou
11-02-2013, بتوقيت غرينيتش 02:12 AM
السلام عليكم ورحمة الله وبركاته


الكثير منا يعاني من مسألة الباك اب buckup الخارجي ونعلم جميعاً مدى أهميته لشركات الإستضافة hosting
البعض منا يستخدم الباك اب buckup الداخلي فقط , والبعض الآخر يستخدم الخارجي فقط حيث أن لوحة تحكم السي بنل تسمح بأحد الطريقتين فقط

ف إذا كنا نستخدم الباك اب buckup الداخلي ,, ومطنشين الخارجي ,, نضطر نعمل الباك اب buckup الخارجي بشكل يدوي ,, والبعض منا مسوي لنفسه سكربت من تحت لتحت ومايحب يشارك فيه احد , اليوم حنفتح الملفات ونعرض المواضيع للجميع للفائدة إهداء لمنتديات لينوكس العربية .

تشغيل السكربت الموضح كود codeه بالأسفل ألا وهو xBackup.sh آمن جداً , يمكنك تجربته فقط بدون تشغيل عملية الرفع وخلافه , حيث يمكنك تشغيله وقراءة الأسئلة والإجابة عنها خطوة بخطوة.

ماذا يحتاج السكربت ليعمل؟
1- لوحة تحكم سي بنل
2- مساحة في بارتشن ال home مساوية لمساحة الباك اب buckup الداخلي لديك
لمعرفة المساحة المستهلكة من بارتشن الباك اب buckup لديك قم بتطبيق الأمر التالي:

رمز Code:
du -h /backup/cpbackup/daily --max-depth=0أو قم بتقديرها تقديراً
ولمعرفة المساحة المتبقية لديك ,, طبق الأمر التالي

رمز Code:
df -h3- قم بتشغيل السكربت في خارج أوقات الباك اب buckup الداخلي لديك لمنع حدوث لود لديك.


طريقة عمل السكربت:
1- يسألك السكربت عن معلومات بسيطة
ماهو عنوان سيرفر SERVER الإف تي بي الذي تريد رفع الملفات عليه ؟
ماهو اليوزر؟
ماهو الباسورد ؟

بإمكانك عدم الإجابة عليها وتركها فارغة إذا كنت تريد وضعها كل مرة (ننصح بهذه الطريقة من نواحي أمنية)

بإمكانك وضع هذه البيانات بحيث في المستقبل , ضغطة زر واحدة تقوم بعمل باك اب buckup خارجي لك , أو تركها فارغة بحيث يطلبك البرنامج اليوزر والباسورد كل مرة لعمل الباك اب buckup الخارجي.

2-بعد هذا السؤال
سيقوم السكربت بتركيب install سكربت آخر مخصص لك على السيرفر SERVER , فيه بيانات الإف تي بي المعطاه سابقا

3-سيسألك السكربت , هل تريد رفع الباك اب buckup الآن ؟
في حالة نعم:
سيسألك مرة أخرى , هل تريد أن تقرأ نتائج العمليات stdout و stderror على الشاشة ؟ أو تريد أن يقوم السكربت بالعمل في ال Background ويقوم بإنشاء ملفات لوق ؟
في حالة لا:
سيقوم السكربت بتقديم أمر على طبق من ذهب تقوم بإستخدامه في أي وقت تشاء رفع الباك اب buckup الخارجي فيه.

لتنزيل السكربت ومعرفة الأوامر المطلوبة إنزل لآخر الموضوع

هذا كود code السكربت للمطورين والمبرمجين ,


اقتباس
#!/bin/bash
#?################################################ ########
# External Backup Script v 1.0 ! #
################################################## ########
# #
# This Script works on cPanel servers . #
# Runing this script for testing is safe . #
# This Script will prompt you and create another script #
# to maintain your needs . #



# #
# You can run this script every time you need to do an #
# an external backup, or you can execute the generated #
# Script instead . #
# #
# Scripted By Mo9a7i . #
# email : livehostsupporthttp://www.dzbatna.com/images/mail.gifgmail.com #
# Please report any errors or suggestions to Mo9a7i . #
# #
################################################## ######?#

ParDir=`pwd`
RunFile="$ParDir/xBacker.sh"

intro()
{
clear
echo ""
echo -e "\t########################################### #### ###################"
echo -e "\t# Welcome \033[34m to xBackup v 1.0 \033[0mBy Mo9a7i (Systems Admin) #"
echo -e "\t# Please note that this script will work only with systems that #"
echo -e "\t# run cPanel. #"
echo -e "\t# #"
echo -e "\t#\t\t \033[31mRUN AT YOUR OWN RISK \033[0m #"
echo -e "\t########################################### #### ###################"
echo ""
}

getInfo()
{
echo -e "\033[34mNote that it is recommended that you leave these lines empty for security reasons"
echo -e "You can fill them manually at another point\033[0m"
echo ""
echo -n "Please enter the external ftp server's address:"
read ftp_server
echo -n "Enter ftp username:"
read ftp_user
echo -n "Enter password:"
read ftp_pass
corInfo
}

corInfo()
{
echo -e "\a"
echo -e "\033[31m#####################Please make sure of the information below!#####################\033[0m"
echo
echo -e "Address : \t\033[34m $ftp_server\033[0m"
echo -e "Username :\t\033[34m $ftp_user\033[0m"
echo -e "Password :\t\033[34m $ftp_pass\033[0m"
checkInfo
}

checkInfo()
{
echo "Are these information correct? (yes/no)"
read ynanswer

if [ $ynanswer = "yes" ]
then
echo "Thanxk you"
elif [ $ynanswer = "no" ]
then
echo "\aPlease Correct Them"
getInfo
elif [ -n $ynanswer ]
then
echo "\aPlease enter yes or no as an answer, case is sensitve"
checkInfo
fi
}

write2file()
{
echo "#!/bin/sh" > $RunFile
echo "##########################################" >> $RunFile
echo "# By: Mo9a7i (livehostsupporthttp://www.dzbatna.com/images/mail.gifgmail.com #" >> $RunFile
echo "##########################################" >> $RunFile
echo "" >> $RunFile
echo "#Enter the directory name that script could create to store backups in before uploading" >> $RunFile
echo "TempDir=$ParDir/exbackup" >> $RunFile
echo "" >> $RunFile
echo "temp=\"/tmp/\$(basename \$0).\$\$\" ; trap \"/bin/rm -f \$temp\" 0" >> $RunFile
echo "remote=$ftp_server" >> $RunFile
echo "ftpu=$ftp_user" >> $RunFile
echo "ftpp=$ftp_pass" >> $RunFile
echo "" >> $RunFile
echo "if [ -z \$remote ] ; then" >> $RunFile
echo "echo \"Enter Ftp server:\"" >> $RunFile
echo "read remote" >> $RunFile
echo "fi" >> $RunFile
echo "if [ -z \$ftpu ] ; then" >> $RunFile
echo "echo \"Enter Ftp username:\"" >> $RunFile
echo "read ftpu" >> $RunFile
echo "fi" >> $RunFile
echo "if [ -z \$ftpp ] ; then" >> $RunFile
echo "echo \"Enter Ftp password:\"" >> $RunFile
echo "read ftpp" >> $RunFile
echo "fi" >> $RunFile
echo "" >> $RunFile
echo "mkdir \$TempDir" >> $RunFile
echo "cd \$TempDir;echo -n \"Now in: \";pwd" >> $RunFile
echo "" >> $RunFile
echo "echo \"Creating Users list\"" >> $RunFile
echo "ls -1 /var/cpanel/users > tempusers.txt" >> $RunFile
echo "tail -n +3 tempusers.txt >users.txt" >> $RunFile
echo "rm -rf tempusers.txt" >> $RunFile
echo "" >> $RunFile
echo "for Users in \$(cat users.txt)" >> $RunFile
echo "do" >> $RunFile
echo " echo -e \"\033[34mBacking Up \$Users\033[0m\"" >> $RunFile
echo " /scripts/pkgacct \$Users" >> $RunFile
echo " ech -r \"\033[34mMoving cpmove-\$Users.tar.gz to \$TempDir\033[0m\"" >> $RunFile
echo " mv /home/cpmove-\$Users.tar.gz \$TempDir" >> $RunFile
echo " echo -e \"\033[34m...................Done\033[0m\"" >> $RunFile
echo "done" >> $RunFile
echo "" >> $RunFile
echo "echo \"user \$ftpu \$ftpp\" > \$temp" >> $RunFile
echo "echo \"lcd \$TempDir\" >> \$temp" >> $RunFile
echo "for file in \`find . -name \"*.tar.gz\"\`" >> $RunFile
echo "do" >> $RunFile
echo "if [ -f \$file ] ; then" >> $RunFile
echo " echo \"!echo \"Uploading \$file\"\" >> \$temp" >> $RunFile
echo " echo \"put \$file \$file\" >> \$temp" >> $RunFile
echo " echo \"!echo \".....Done\"\" >> \$temp" >> $RunFile
echo "else" >> $RunFile
echo " echo \"skipping \$file: not a file.\" >&2" >> $RunFile
echo "fi" >> $RunFile
echo "done" >> $RunFile
echo "echo \"quit\" >> \$temp" >> $RunFile
echo "" >> $RunFile
echo "echo \"Script will start the FTP Session now\"" >> $RunFile
echo &quot;ftp -n -u -v \$remote < \$temp&quot; >> $RunFile
echo &quot;echo \&quot;Closed FTP Session\&quot;&quot; >> $RunFile
echo &quot;&quot; >> $RunFile
echo &quot;rm -rf \$TempDir&quot; >> $RunFile
echo &quot;exit 0&quot; >> $RunFile

}

makeFile()
{
touch $RunFile

if [ -f $RunFile ]
then
echo -n &quot;File Exists!&quot;
write2file
chmod 750 $RunFile
echo &quot; And been successfully written to&quot;
else
echo &quot;File does not exist&quot;
exit 0
fi
}

eXec()
{
echo -e &quot;Do you want to execute the file now? (yes-no)&quot;
read ysno
if [ $ysno = &quot;yes&quot; ]
then
echo -e &quot;Do you want to read the output? (yes-no)&quot;
echo -e &quot;write (no) to let the program run in the Background and create log files&quot;
read noys
if [ $noys = &quot;yes&quot; ]
then
sh $RunFile
elif [ $noys = &quot;no&quot; ]
then
sh $RunFile > $ParDir/normal.log 2> $ParDir/error.log &
else
sh $RunFile
fi
elif [ $ysno = &quot;no&quot; ]
then
echo &quot;To manually execute the script and upload your files you can run the command \&quot;sh $RunFile\&quot;&quot;
else
echo &quot;Please chose a correct answer (yes/no)&quot;
eXec
fi
}


intro
getInfo
makeFile
eXec

echo &quot;Have A Nice Day!&quot;

للتنزيل والتشغيل طبق الأوامر التالية أول بأول في الشل:

رمز PHP:

<code style="white-space:nowrap"> <code> wget http://www.hardlayers.com/download/xBackup.sh

chmod 750 xBackup.sh
</code> </code>

لتشغيل البرنامج وقت ماتشاء , إذهب للمسار الذي قمت بتنزيل السكربت فيه
وقم بتشغيله بالأمر التالي:

رمز PHP:

<code style="white-space:nowrap"> <code> ./xBackup.sh
</code> </code>

تحياتي ///





https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-ash4/482113_236967293114455_1193518507_n.png (http://www.dzbatna.com)
©المشاركات المنشورة تعبر عن وجهة نظر صاحبها فقط، ولا تُعبّر بأي شكل من الأشكال عن وجهة نظر إدارة المنتدى (http://www.dzbatna.com)©

استعمل مربع البحث في الاسفل لمزيد من المواضيع


سريع للبحث عن مواضيع في المنتدى