大家好, 作为系统管理员,你需要每天备份的数据。备份恢复对于任何崩溃或损坏的数据非常有用。我写了一个简单的脚本,从MySQL服务器采取数据库备份并上传到FTP服务器。作为一个系统管理员,我建议,让您的每个备份的远程副本。 此脚本在 CentOS 5,6和REDHAT 5,6测试。如下脚本:
#!/bin/bash
######################################################
# Script Written by : Ray
# Date: Feb 21, 2013
######################################################
DATE=`date +%d%b%y`
LOCAL_BACKUP_DIR="/backup/"
DB_NAME="test"
DB_USER="root"
DB_PASSWORD="your password"
FTP_SERVER="ftp.youcl.com"
FTP_USERNAME="ftp user name"
FTP_PASSWORD="ftp user password"
FTP_UPLOAD_DIR="/backup/"
LOG_FILE=/backup/backup-DATE.log
############### Local Backup ########################
mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME | gzip > $LOCAL_BACKUP_DIR/$DB_NAME-$DATE.sql.gz
############### UPLOAD to FTP Server ################
ftp -n $FTP_SERVER $LOG_FILE
else
echo "Error in database Upload to Ftp Server" > $LOG_FILE
fi
设置详细信息:
LOCAL_BACKUP_DIR => Local direction path to store backup
DB_NAME => database name
DB_USER => database adminitrator user name
DB_PASSWORD => database administrator password
FTP_SERVER => ftp server ip for hostname
FTP_USERNAME => ftp username
FTP_PASSWORD => ftp password
FTP_UPLOAD_DIR => ftp server backup path
LOG_FILE => log file name and location
我希望这个脚本将帮助您采取数据库备份在FTP服务器。