ZaZ
30-08-2006, 30 - 08 - 2006
هذا سكربت CGI
تضعه في دليل
/www/cgi-bin/
الدليل الذي سوف تنسخ قاعدة البيانات إليه يجب أن يحمل التصريح 777 (راجع هذا الموضوع لتصاريح المجلدات (http://www.zhra.net/vb/showthread.php?t=160))
#!/bin/sh
# This NOW= line must be the first line of the file.
NOW=`date "+%Y%m%d_%H%M%S"`
# SAVE_PATH: The directory you want your backup and error files saved to
# (SAVE_PATH must include the trailing slash).
# DB_SERVER: The server your database is on (exmaple: mysql01.powweb.com).
# DB_NAME: The name of your database.
# DB_USERNAME: The username you use to log in to your database.
# DB_PASSWORD: The password you use to log in to your database.
# BACKUP_FILE: The name of the file you want to back up the database to
# (this will overwrite any existing file with the same name).
# ERROR_FILE: The name of the file you want errors reported to
# (this will overwrite any existing file with the same name).
# SEND_EMAIL: Set to YES if you want the script to send you an email when
# the backup is complete. Comment out the SEND_EMAIL= line
# if you do not want the script to send you an email.
# EMAIL_FROM: If SEND_EMAIL=YES, the mail is "From" this address.
# EMAIL_TO: If SEND_EMAIL=YES, the mail is sent "To" this address.
# EMAIL_SUBJECT: If SEND_EMAIL=YES, this is the subject line.
SAVE_PATH="/home/zhra/public_html/"
DB_SERVER="localhost"
DB_NAME="zhra_xxxxx"
DB_USERNAME="zhra_xxxx"
DB_PASSWORD="xxxxxxx"
BACKUP_FILE="database_backup_${NOW}.sql"
ERROR_FILE="mysqldump.err"
SEND_EMAIL="YES"
EMAIL_FROM="Database Backup <xxxxxx@hotmail.com>"
EMAIL_TO="xxxxxx@hotmail.com"
EMAIL_SUBJECT="Database backup ${NOW}"
######################################## ###################################
# Do not touch anything below this line!
######################################## ###################################
cd ${SAVE_PATH}
BACKUP_BEGIN=`date "+%A, %B %d %Y, at %l:%M:%S%P"`
/usr/bin/mysqldump \
--user=${DB_USERNAME} \
--password=${DB_PASSWORD} \
--host=${DB_SERVER} \
${DB_NAME} \
> ${BACKUP_FILE} \
2> ${ERROR_FILE}
BACKUP_COMPLETE=`date "+%A, %B %d %Y, at %l:%M:%S%P"`
BACKUP_SIZE=`ls -l ${BACKUP_FILE} | awk '{print $5}'`
BACKUP_ERR_FILE=`cat ${ERROR_FILE}`
[ -n "${BACKUP_ERR_FILE}" ] && {
BACKUP_ERR="`echo -e "Errors:\n${BACKUP_ERR_FILE}"`"
} || {
BACKUP_ERR="No errors"
}
MESSAGE=`echo -e "Backup of database ${DB_NAME} on server ${DB_SERVER}:\n\
Backup began on ${BACKUP_BEGIN}\n\
Backup completed on ${BACKUP_COMPLETE}\n\
\n\
Location of backup: ${SAVE_PATH}\n\
Name of backup: ${BACKUP_FILE}\n\
Size of backup: ${BACKUP_SIZE}\n\
\n\
${BACKUP_ERR}"`
[ -n "${SEND_EMAIL}" ] && {
echo -e "From: ${EMAIL_FROM}\n\
To: ${EMAIL_TO}\n\
Subject: ${EMAIL_SUBJECT}\n\
\n\
${MESSAGE}" \
| /usr/sbin/sendmail -t -i
}
echo -e "Content-Type: text/plain\n\
\n\
${MESSAGE}"
عدل هذه الاسطر كما هو مناسب لموقعك و قاعدة البيانات التي تريد نسخها
SAVE_PATH="/home/zhra/public_html/"
DB_SERVER="localhost"
DB_NAME="zhra_xxxxx"
DB_USERNAME="zhra_xxxx"
DB_PASSWORD="xxxxxxx"
BACKUP_FILE="database_backup_${NOW}.sql"
ERROR_FILE="mysqldump.err"
SEND_EMAIL="YES"
EMAIL_FROM="Database Backup <xxxxxx@hotmail.com>"
EMAIL_TO="xxxxxx@hotmail.com"
EMAIL_SUBJECT="Database backup ${NOW}"
إفتح المفكرة ثم إنسخ الكود السابق ثم قم بحفظة بصيغة التالية:
database_backup.cgi
بعد ذلك قم بطلب السكربت عن طريق المتصفح بهذه الطريقة
http://www.xxxx.com/cgi-bin/database_backup.cgi
سوف تحصل على نسخة إحتياطية في وقت وجيز عن قاعدة البيانات التي تريد
الملف في المرفقات و لا تنسى أن تزيل الوصلة .txt بعد رفعة بواسطة FTP
مواضيع عن نسخ قاعدة البيانات
نسخ و تحميل قاعدة البيانات (http://www.zhra.net/vb/showthread.php?t=158)
نسخ واسترجاع قاعدة البيانات من وإلى الموقع (http://www.zhra.net/vb/showthread.php?t=66)
طريقة إنشاء قاعدة بيانات (2) (http://www.zhra.net/vb/showthread.php?t=275)
تضعه في دليل
/www/cgi-bin/
الدليل الذي سوف تنسخ قاعدة البيانات إليه يجب أن يحمل التصريح 777 (راجع هذا الموضوع لتصاريح المجلدات (http://www.zhra.net/vb/showthread.php?t=160))
#!/bin/sh
# This NOW= line must be the first line of the file.
NOW=`date "+%Y%m%d_%H%M%S"`
# SAVE_PATH: The directory you want your backup and error files saved to
# (SAVE_PATH must include the trailing slash).
# DB_SERVER: The server your database is on (exmaple: mysql01.powweb.com).
# DB_NAME: The name of your database.
# DB_USERNAME: The username you use to log in to your database.
# DB_PASSWORD: The password you use to log in to your database.
# BACKUP_FILE: The name of the file you want to back up the database to
# (this will overwrite any existing file with the same name).
# ERROR_FILE: The name of the file you want errors reported to
# (this will overwrite any existing file with the same name).
# SEND_EMAIL: Set to YES if you want the script to send you an email when
# the backup is complete. Comment out the SEND_EMAIL= line
# if you do not want the script to send you an email.
# EMAIL_FROM: If SEND_EMAIL=YES, the mail is "From" this address.
# EMAIL_TO: If SEND_EMAIL=YES, the mail is sent "To" this address.
# EMAIL_SUBJECT: If SEND_EMAIL=YES, this is the subject line.
SAVE_PATH="/home/zhra/public_html/"
DB_SERVER="localhost"
DB_NAME="zhra_xxxxx"
DB_USERNAME="zhra_xxxx"
DB_PASSWORD="xxxxxxx"
BACKUP_FILE="database_backup_${NOW}.sql"
ERROR_FILE="mysqldump.err"
SEND_EMAIL="YES"
EMAIL_FROM="Database Backup <xxxxxx@hotmail.com>"
EMAIL_TO="xxxxxx@hotmail.com"
EMAIL_SUBJECT="Database backup ${NOW}"
######################################## ###################################
# Do not touch anything below this line!
######################################## ###################################
cd ${SAVE_PATH}
BACKUP_BEGIN=`date "+%A, %B %d %Y, at %l:%M:%S%P"`
/usr/bin/mysqldump \
--user=${DB_USERNAME} \
--password=${DB_PASSWORD} \
--host=${DB_SERVER} \
${DB_NAME} \
> ${BACKUP_FILE} \
2> ${ERROR_FILE}
BACKUP_COMPLETE=`date "+%A, %B %d %Y, at %l:%M:%S%P"`
BACKUP_SIZE=`ls -l ${BACKUP_FILE} | awk '{print $5}'`
BACKUP_ERR_FILE=`cat ${ERROR_FILE}`
[ -n "${BACKUP_ERR_FILE}" ] && {
BACKUP_ERR="`echo -e "Errors:\n${BACKUP_ERR_FILE}"`"
} || {
BACKUP_ERR="No errors"
}
MESSAGE=`echo -e "Backup of database ${DB_NAME} on server ${DB_SERVER}:\n\
Backup began on ${BACKUP_BEGIN}\n\
Backup completed on ${BACKUP_COMPLETE}\n\
\n\
Location of backup: ${SAVE_PATH}\n\
Name of backup: ${BACKUP_FILE}\n\
Size of backup: ${BACKUP_SIZE}\n\
\n\
${BACKUP_ERR}"`
[ -n "${SEND_EMAIL}" ] && {
echo -e "From: ${EMAIL_FROM}\n\
To: ${EMAIL_TO}\n\
Subject: ${EMAIL_SUBJECT}\n\
\n\
${MESSAGE}" \
| /usr/sbin/sendmail -t -i
}
echo -e "Content-Type: text/plain\n\
\n\
${MESSAGE}"
عدل هذه الاسطر كما هو مناسب لموقعك و قاعدة البيانات التي تريد نسخها
SAVE_PATH="/home/zhra/public_html/"
DB_SERVER="localhost"
DB_NAME="zhra_xxxxx"
DB_USERNAME="zhra_xxxx"
DB_PASSWORD="xxxxxxx"
BACKUP_FILE="database_backup_${NOW}.sql"
ERROR_FILE="mysqldump.err"
SEND_EMAIL="YES"
EMAIL_FROM="Database Backup <xxxxxx@hotmail.com>"
EMAIL_TO="xxxxxx@hotmail.com"
EMAIL_SUBJECT="Database backup ${NOW}"
إفتح المفكرة ثم إنسخ الكود السابق ثم قم بحفظة بصيغة التالية:
database_backup.cgi
بعد ذلك قم بطلب السكربت عن طريق المتصفح بهذه الطريقة
http://www.xxxx.com/cgi-bin/database_backup.cgi
سوف تحصل على نسخة إحتياطية في وقت وجيز عن قاعدة البيانات التي تريد
الملف في المرفقات و لا تنسى أن تزيل الوصلة .txt بعد رفعة بواسطة FTP
مواضيع عن نسخ قاعدة البيانات
نسخ و تحميل قاعدة البيانات (http://www.zhra.net/vb/showthread.php?t=158)
نسخ واسترجاع قاعدة البيانات من وإلى الموقع (http://www.zhra.net/vb/showthread.php?t=66)
طريقة إنشاء قاعدة بيانات (2) (http://www.zhra.net/vb/showthread.php?t=275)