我编写了一个脚本来并行恢复一个巨大的 mysqldump 文件
https://gist.github.com/arunp0/4c34caee2432a6f11b91b99dfd2c5ef3
可以将转储文件分成几部分并并行恢复吗?
或者如果有任何改进建议以减少恢复时间
只是为了解释脚本是如何工作的
sed -n -e '/DROP TABLE/,/--/p' "${restoreFile}" > "${tableMetaFile}"
使用 DROP TABLE 、 CREATE TABLE 命令创建新的 sql 文件
然后这个文件被恢复(不是并行的)——所有的表都是在恢复数据之前创建的
# Creates new file with data only for one table (TableName)
grep -E "^INSERT INTO \`${TableName}\`" "${restoreFile}" > "tmp/${TableName}.sql"
# that file is split into as many chunks as the number of cpus
split -n l/$(nproc) --additional-suffix=.sql "tmp/${TableName}.sql" tmp/"${TableName}"/output.
# This comamnd is used to restore the file
pv -f tmp/meta/pre.sql "${item}" tmp/meta/post.sql | mysql --protocol=TCP --port "$PORT" --host "$HOST" -u "${USER}" -p"${PASSWORD}" -f "${DATABASE}" &