当您不知道第一个文件名时如何检索所有远程 mysql 二进制日志文件(由于远程服务器上的轮换)

How to retrieve all remote mysql binary log files when you don't know the first filename (due to rotation on remote server)

非常感谢任何指导

我们想使用 mysqlbinlog 从远程服务器下载二进制日志(必须是 mysqlbinlog 而不是 scp,因为这是我们唯一开放的协议)

远程服务器设置为在 2 天后轮换日志,因为每 24 小时进行一次完整备份。

当二进制日志首次启动时文件名是 mysql-bin.000001 和 crontab 命令 运行 很好:

mysqlbinlog mysql-bin.000001 --ssl=0 --read-from-remote-server --host=xxxxxxxxxxxx --user=xxxxxxx --password=xxxxxxxx --raw --to-last-log --result-file=/opt/tb_mysql_backup_binary_logs/production/

现在,由于日志轮换,日志文件名现在从 ...bin.00008 开始,命令当然会失败。我知道我们可以手动 mysql 和 运行 SHOW BINARY LOGS

但是无论如何我们可以'ask for all the log files from the first up to latest WITHOUT knowing the first name'

干杯 套件

没有,尽管您可以组合命令并获得大致相同的结果。

mysqlbinlog $(mysql -e 'show binary logs;' --skip-column-names | head -n 1) --ssl=0 ...

$()内部命令得到的结果被放到外部命令中。在 $() 中,您还需要重复 --host--user 等参数以针对服务器进行身份验证。