从数据库备份

#!/bin/bash

username=mysqlbackup

password=mysqlbackup

date='date +%Y-%m-%d'

olddate='date +%Y-%m-%d -d '-20 days''

ftpolddate='date +%Y-%m-%d -d '-60 days''

mysql=/usr/local/mysql/bin/mysql

mysqldump=/usr/local/mysql/bin/mysqldump

mysqladmin=/usr/local/mysql/bin/mysqladmin

socket=/tmp/mysql.socket

backdir=/date/backup/db

[ -d ${backdir}] || { mkdir -p ${backdir}}

[-d ${backdir}/{date}] || mkdir ${backdir}/${date}

[! -d ${backdir}/${olddate}] || rm -rf ${backdir}/${olddate}

for dbname in mysql test report

do

${mysqldump} --opt -u ${username} -p ${password} -s ${socket} ${dbname} | gzip > ${backdir}/${date}/${dbname}-backup-${date}.sql.gz

echo "${dbname} has been backup successful"

/bin/sleep 5

done

host=0.0.0.0

ftp_username=dbmysql

ftp_password=dbmysql

cd ${backdir}/${date}

ftp -i -n -v <

open ${host}

user ${ftp_username} ${ftp_password}

bin

cd ${ftpolddate}

mdelete *

cd ..

rmdir ${ftpolddate}

mkdir ${date}

cd ${date}

mput *

bye

!

你可能感兴趣的:(从数据库备份)