rsync 在守护进程下失败,但从终端运行时成功

rsync 在守护进程下失败,但从终端运行时成功

我有一个脚本 [1],它由 Postgres 守护进程 (WAL 归档程序) 执行,并失败,退出代码为 12;请参阅 [2]。但如果我在终端/ssh 会话中执行相同的脚本,它会成功;请参阅 [3]。

freenode IRC 频道 #rsync 上的用户 BasketCase 尝试诊断该问题,但无济于事。请参阅 [4] 了解对话。

并非所有使用过该设备的机器都会发生这种情况,但这是我第二次遇到这种情况。

任何帮助都将受到高度赞赏。

提前致谢。

[1] WAL归档脚本

#!/bin/bash
# $1 is the %p substituted by postgres in archive_command
# $2 is the %f substituted by postgres in archive_command
# This script backs up the WAL file to every replica, and
# exits with the last failure code, if any.
final_exit_code=0
replicas=$(grep REPLICA /some/file | sort | uniq | cut -d = -f 2-)

for replica_url in $replicas; do
     echo Sending WAL file to $replica_url
     rsync --timeout=10 -avz -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -i /opt/PostgresPlus/CloudDB/data/cluster_ssh.key' "$1" root@$replica_url:/mnt/pcs/wal_archive/"$2"
     exit_code=$?
     if [ $exit_code -ne 0 ] ; then final_exit_code=$exit_code ; fi
  done
exit $final_exit_code

[2] 将 WAL 文件发送到 10.33.177.184 rsync:连接意外关闭(迄今为止已接收 0 字节)[发送方] rsync 错误:io.c(600) 处的 rsync 协议数据流(代码 12)中发生错误 [发送方=3.0.6] 日志:存档命令失败,退出代码为 12 详细信息:失败的存档命令为:./wal_archive.sh pg_xlog/0000000100000005000000EE 0000000100000005000000EE

[3] $ ./wal_archive.sh pg_xlog/0000000100000005000000EE 0000000100000005000000EE 将 WAL 文件发送到 10.33.177.184 警告:永久将“10.33.177.184”(RSA)添加到已知主机列表中。发送增量文件列表 0000000100000005000000EE

发送 5180930 字节 接收 31 字节 941992.91 字节/秒 总大小为 16777216 加速比为 3.24

[4]http://gurjeet.privatepaste.com/dc98277db3

答案1

问题在于LD_LIBRARY_PATH终端和 Postgres 守护进程的环境之间的差异。

LD_LIBRARY_PATH如果我在终端中使用相同的功能,那么终端中的 rsync 也会失败:

$ export LD_LIBRARY_PATH=/opt/PostgresPlus/9.1AS/lib:
$ ./wal_archive.sh pg_xlog/0000000100000005000000EE 0000000100000005000000EE
Sending WAL file to 10.33.177.184
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [sender=3.0.6]

ssh正在使用中的库/opt/PostgresPlus/9.1AS/lib,它们可能与ssh二进制不兼容。

以下是设置导出后的ldd输出sshLD_LIBRARY_PATH

$ ldd `which ssh`
    linux-vdso.so.1 =>  (0x00007fff3fa28000)
    libfipscheck.so.1 => /lib64/libfipscheck.so.1 (0x00007fe726907000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fe7266e7000)
    libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007fe72634d000)
    libutil.so.1 => /lib64/libutil.so.1 (0x00007fe72614a000)
    libz.so.1 => /opt/PostgresPlus/9.1AS/lib/libz.so.1 (0x00007fe725f34000)
    libnsl.so.1 => /lib64/libnsl.so.1 (0x00007fe725d1b000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fe725ae4000)
    libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fe7258c9000)
    libgssapi_krb5.so.2 => /opt/PostgresPlus/9.1AS/lib/libgssapi_krb5.so.2 (0x00007fe725690000)
    libkrb5.so.3 => /opt/PostgresPlus/9.1AS/lib/libkrb5.so.3 (0x00007fe7253d3000)
    libk5crypto.so.3 => /opt/PostgresPlus/9.1AS/lib/libk5crypto.so.3 (0x00007fe7251aa000)
    libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fe724fa6000)
    libnss3.so => /usr/lib64/libnss3.so (0x00007fe724c6a000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fe7248d6000)
    libplc4.so => /lib64/libplc4.so (0x00007fe7246d1000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fe7244cd000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fe726d76000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007fe72426a000)
    libcom_err.so.3 => /opt/PostgresPlus/9.1AS/lib/libcom_err.so.3 (0x00007fe724067000)
    libkrb5support.so.0 => /opt/PostgresPlus/9.1AS/lib/libkrb5support.so.0 (0x00007fe723e60000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fe723c42000)
    libnssutil3.so => /usr/lib64/libnssutil3.so (0x00007fe723a1c000)
    libplds4.so => /lib64/libplds4.so (0x00007fe723818000)
    libnspr4.so => /lib64/libnspr4.so (0x00007fe7235da000)

LD_LIBRARY_PATH下面是没有设置命令的相同命令

$ ldd `which ssh`
    linux-vdso.so.1 =>  (0x00007fff941ff000)
    libfipscheck.so.1 => /lib64/libfipscheck.so.1 (0x00007f93b2ab2000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f93b2893000)
    libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f93b24f8000)
    libutil.so.1 => /lib64/libutil.so.1 (0x00007f93b22f5000)
    libz.so.1 => /lib64/libz.so.1 (0x00007f93b20df000)
    libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f93b1ec5000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f93b1c8e000)
    libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f93b1a74000)
    libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f93b1831000)
    libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f93b1552000)
    libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f93b1326000)
    libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f93b1121000)
    libnss3.so => /usr/lib64/libnss3.so (0x00007f93b0de5000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f93b0a52000)
    libplc4.so => /lib64/libplc4.so (0x00007f93b084c000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f93b0648000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f93b2f21000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007f93b03e6000)
    libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f93b01da000)
    libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f93affd7000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f93afdba000)
    libnssutil3.so => /usr/lib64/libnssutil3.so (0x00007f93afb93000)
    libplds4.so => /lib64/libplds4.so (0x00007f93af98f000)
    libnspr4.so => /lib64/libnspr4.so (0x00007f93af752000)

相关内容