【mysqldump备份指定数据库表】my_dump.sh
#!/bin/bash # # 2014/12/12 function dump_db_table() { local d_db_base=‘/data/svr/mysql‘ local s_datetime=$(date +%Y%m%d_%H%M%S) local s_port=3306 local s_password=‘xxx‘ local s_db=$1 if [ -z ${s_port} ]; then echo "Usage: $0 database table" exit 2; fi local s_table=$2 local d_backup="/home/backup/mysql/${s_port}/mysqldump/${s_db}" if [ -z ${s_table} ]; then local dump_args="${d_db_base}/bin/mysqldump -h 127.0.0.1 -P ${s_port} -u root --password=${s_password} -B ${s_db}" local f_dump_tar="${d_backup}/${s_datetime}-${s_db}.gz" else local dump_args="${d_db_base}/bin/mysqldump -h 127.0.0.1 -P ${s_port} -u root --password=${s_password} ${s_db} ${s_table}" local f_dump_tar="${d_backup}/${s_datetime}-${s_table}.gz" fi test -d ${d_backup} || mkdir -p ${d_backup} echo "[+] `date` Port: ${s_port} DB: ${s_db}.${s_table}" #${d_db_base}/bin/mysqldump -h 127.0.0.1 -P ${s_port} -u root --password=${s_password} ${s_db} ${s_table} |gzip >${f_backup_db_compressed} ${dump_args} |gzip >${f_dump_tar} #echo "${dump_args}" echo "[-] `date` Saved to: ${f_dump_tar}" echo "[-] `date` Done." echo sleep 1s } dump_db_table d_abc t_abc dump_db_table d_def t_def
原文地址:http://nosmoking.blog.51cto.com/3263888/1594800