まずはそのバックアップ用のディレクトリーを作ります
mkdir /home/example_user/MySQL_Backup mkdir /home/example_user/MySQL_Backup/script vim /home/example_user/MySQL_Backup/script/backup.sh
ここでスクリプトの本体を入力します
#!/bin/bash BK_PATH="/home/example_user/MySQL_Backup" DATE="`date +'%m%d%Y-%H%M%S'`" CONFIG_PATH="$BK_PATH/script" DB_USER="root" DB_PASS="mysql_password" DB_TOBACKUP="to_backup.txt" LOG="log.txt" LOGDATE="`date +'%m/%d/%Y-%H:%M:%S'`" DELETE="delete.txt" FTP="ftp://ftp_user:ftp_password@ftp_server.domain.tld/MySQL_Backup/" echo "---------------Backup Starts @ ""$LOGDATE""---------------" >> $CONFIG_PATH/$LOG echo -----Backup----- >> $CONFIG_PATH/$LOG cat $CONFIG_PATH/$DB_TOBACKUP | while read LINE do mysqldump --opt --force -u$DB_USER -p$DB_PASS $LINE > "$BK_PATH/""$LINE""_$DATE.sql" echo $LINE >> $CONFIG_PATH/$LOG done echo -----Delete----- >> $CONFIG_PATH/$LOG find $BK_PATH -ctime +7 -type f -name "*.sql" -print > $CONFIG_PATH/$DELETE cat $CONFIG_PATH/$DELETE | while read LINE do wput -nc -t 10 --basename=$BK_PATH/ $LINE $FTP rm $LINE echo $LINE >> $CONFIG_PATH/$LOG done echo "---------------Backup Ends @ ""$LOGDATE""---------------" >> $CONFIG_PATH/$LOG
自分でデータベースやFTPサーバーなどの情報を編集することを忘れないように