crontab 使用docker mysqldump备份
2020-07-29 本文已影响0人
梨花菜
#!/bin/bash
# ignore report and report_detail
now=$(date "+%Y-%-m-%d_%H-%M-%S")
test_ignore_report="/root/test_data_backup/test_ignore_report{$now}.sql"
# don't use -it, it's a trap
$ docker exec {container} mysqldump --ignore-table={database}.{table} -u{user} -p{password} {database} > {target filename}
docker exec mysql mysqldump --ignore-table=test.report --ignore-table=test.report_detail -utest -ptest2020 test > $test_ignore_report
# delete the first line, because there's mysqldump useing password at command waring at first line.
sed -i '1d' $test_ignore_report
# only table struct, use -d
# specify table, use --tables {table}
report="/root/test_data_backup/report{$now}.sql"
docker exec mysql mysqldump -utest -ptest2020 -d test --tables report report_detail > $report
sed -i '1d' $report