#!/bin/bash
#设置mysql的备份保存目录
folder=/etc/bashupMysql
cd $folder
#当前日期
time_now=$(date  "+%Y-%m-%d")
#当前时间的前30天 %H:%M:%S
time_30day_ago=$(date -d"25 day ago" "+%Y-%m-%d 00:00:00")
#数据库服务器ip
host="was.baoshi56.com"
test_host="101.133.135.193"
#用户名
user="developer"
test_user="bswas_test"
#密码
password="developer"
test_password="123456"
#要备份的数据库名
db="bswas"
test_db="bswas_test"
#执行备份语句 --single-transaction 是在导出数据时不锁表
mysqldump -h$host -u$user -p$password --single-transaction $db --ignore-table=$db.orders --ignore-table=$db.stores --ignore-table=$db.packages --ignore-table=$db.store_items --ignore-table=$db.commodities --ignore-table=$db.commodity_barcodes --ignore-table=$db.logs --ignore-table=$db.order_commodities --ignore-table=$db.order_bins --ignore-table=$db.w_m_s_waybill_orders --ignore-table=$db.rejected_bills --ignore-table=$db.rejected_bill_items --ignore-table=$db.w_m_s_reflect_packages --ignore-table=$db.w_m_s_reflect_receive_skus --ignore-table=$db.w_m_s_reflect_receives --ignore-table=$db.order_counting_records --ignore-table=$db.order_package_commodities --ignore-table=$db.order_packages --ignore-table=$db.packages> $time_nowall.sql
mysql  -u$test_user -p$test_password  $test_db< $time_nowall.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db orders --where="created_at>='$time_30day_ago'" > $time_noworders.sql
mysql  -u$test_user -p$test_password  $test_db< $time_noworders.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db stores --where="created_at>='$time_30day_ago'" > $time_nowstores.sql
mysql  -u$test_user -p$test_password  $test_db< $time_nowstores.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db store_items --where="created_at>='$time_30day_ago'" > $time_nowstore_items.sql
mysql  -u$test_user -p$test_password  $test_db< $time_nowstore_items.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db commodities --where="created_at>='$time_30day_ago'" > $time_nowcommodities.sql
mysql  -u$test_user -p$test_password  $test_db< $time_nowcommodities.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db commodity_barcodes --where="created_at>='$time_30day_ago'" > $time_nowcommodity_barcodes.sql
mysql  -u$test_user -p$test_password  $test_db< $time_nowcommodity_barcodes.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db order_counting_records --where="created_at>='$time_30day_ago'" > $time_noworder_counting_records.sql
mysql  -u$test_user -p$test_password  $test_db< $time_noworder_counting_records.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db order_bins --where="created_at>='$time_30day_ago'" > $time_noworder_bins.sql
mysql  -u$test_user -p$test_password  $test_db< $time_noworder_bins.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db order_package_commodities --where="created_at>='$time_30day_ago'" > $time_noworder_package_commodities.sql
mysql  -u$test_user -p$test_password  $test_db< $time_noworder_package_commodities.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db rejected_bills --where="created_at>='$time_30day_ago'" > $time_nowrejected_bills.sql
mysql  -u$test_user -p$test_password  $test_db< $time_nowrejected_bills.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db rejected_bill_items --where="created_at>='$time_30day_ago'" > $time_nowrejected_bill_items.sql
mysql  -u$test_user -p$test_password  $test_db< $time_nowrejected_bill_items.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db w_m_s_reflect_receive_skus --where="created_at>='$time_30day_ago'" > $time_noww_m_s_reflect_receive_skus.sql
mysql  -u$test_user -p$test_password  $test_db< $time_noww_m_s_reflect_receive_skus.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db w_m_s_reflect_packages --where="created_at>='$time_30day_ago'" > $time_noww_m_s_reflect_packages.sql
mysql  -u$test_user -p$test_password  $test_db< $time_noww_m_s_reflect_packages.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db w_m_s_reflect_receives --where="created_at>='$time_30day_ago'" > $time_noww_m_s_reflect_receives.sql
mysql  -u$test_user -p$test_password  $test_db< $time_noww_m_s_reflect_receives.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db w_m_s_waybill_orders --where="created_at>='$time_30day_ago'" > $time_noww_m_s_waybill_orders.sql
mysql  -u$test_user -p$test_password  $test_db< $time_noww_m_s_waybill_orders.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db order_commodities --where="created_at>='$time_30day_ago'" > $time_noworder_commodities.sql
mysql  -u$test_user -p$test_password  $test_db< $time_noworder_commodities.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db order_packages --where="created_at>='$time_30day_ago'" > $time_noworder_packages.sql
mysql  -u$test_user -p$test_password  $test_db< $time_noworder_packages.sql
mysqldump -h$host -u$user -p$password --single-transaction -q -e $db packages --where="created_at>='$time_30day_ago'" > $time_nowpackages.sql
mysql  -u$test_user -p$test_password  $test_db< $time_nowpackages.sql
