数据库备份shell脚本
法一:
#!/bin/bash [ ! -d /server/backup ] && mkdir /server/backup mysqldump -u root -A -B >/server/backup/a.sql [ ! -f /server/backup/a.sql ] && mail -s "bak faile"
法二:
#!/bin/sh DATE=$(date +%Y-%d-%m) DES=/usr/src/mysql_bak MYSQL_U="root" MYSQL_P="123456" MYSQL_H="127.0.0.1" if [ ! -d "$DES" ];then mkdir -p "$DES" fi DB=$(mysql -u $MYSQL_U -h $MYSQL_H -p$MYSQL_P -Bse 'show databases') for database in $DB do if [ ! $database == "information_schema" ];then mysqldump -u $MYSQL_U -h $MYSQL_H -p$MYSQL_P $database |bzip2> "$DES/${DATE}_mysql.gz" fi done
如对您有帮助,支持下呗!
微信
支付宝