1.数据库备份
#!/bin/bash user="root" psword="root" bakdir="/data/mysqlbak" Date=$(date +%F) dbnames=$(mysql -u root -proot -e "show databases" | sed 1d | egrep -v "(schema$|mysql)") #删除3天之前的备份 find $bakdir -ctime +3 -name \*.sql | xargs rm -f #备份数据库 for dbname in $dbnames do mysqldump -u$user -p$psword --databases $dbname > $bakdir/${dbname}-${Date}.sql done