crontab 使用docker mysqldump备份

#!/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

参考:

最后编辑于:2020/11/10作者: 编程小战

我不入地狱,谁入地狱?

评论已关闭