shell 数据库定时备份归档

#备份数据库
backup_sql(){
date=$(date +%Y%m%d)
user=root
password=pass
db=dbname
backup_path=/backup

if [ ! -f ${backup_path}/${db}-${date}.sql ];then
   /usr/local/mysql/bin/mysqldump -u${user} -p${password} ${db} > ${backup_path}/${db}-${date}.sql 2> /dev/null
fi
}

#每月移动数据库备份到指定月份目录
mv_directory(){
month=当前年月
backup_path=/backup
if [ -z ${month} ];then
   mkdir ${backup_path}/${month}
fi
mv /${backup_path}/备份文件名  /${backup_path}/${month}
}

backup_sql
mv_directory