1.mysql Sub-Library backup
Myuser=root
mypass=yzg1314520
Mycmd= "Mysql-u$myuser-p$mypass"
mydump= "Mysqldump-u$myuser-p$mypass"
For database in MySQL test
Do
$mydump $database > $database _$ (Date +%f). sql
TAR-ZCVF $database _$ (date +%f). tar.gz $database _$ (date +%f). sql
RM-RF $database _$ (date +%f). sql
Done
2.mysql Sub-database sub-table backup
Myuser=root
mypass=yzg1314520
Mycmd= "Mysql-u$myuser-p$mypass"
mydump= "Mysqldump-u$myuser-p$mypass"
For database in ' $mycmd-e ' show databases | Sed ' 1,3d '
Do
Mkdir-p/home/scripts/mysqlbak
For table in ' $mycmd-e ' show tables from $database; "|sed ' 1d"
Do
$mydump $database $table > ${database}_${table}_$ (Date +%f). sql
TAR-ZCVF ${database}_${table}_$ (Date +%f). tar.gz ${database}_${table}_$ (date +%f)
. sql
mv./${database}_${table}_$ (date +%f). Tar.gz/home/scripts/mysqlbak
rm-rf/home/scripts/${database}_${table}_$ (date +%f). sql
RM-RF $ (find/home/scripts/mysqlbak-name "*.tar.gz"-mtime +5-type f)
Done
Done
MySQL Sub-Library-sub-table backup