我正在尝试rsnapshot
将远程文件同步到我自己的计算机。但是,当我需要访问不属于通过 SSH 连接到远程计算机的用户的文件时,我遇到了一些麻烦。
我的/etc/rsnapshot.conf
样子是这样的:
config_version 1.2
snapshot_root /shared/.backup/
cmd_cp /bin/cp
cmd_rm /bin/rm
cmd_rsync /usr/bin/rsync
cmd_ssh /usr/bin/ssh
cmd_logger /usr/bin/logger
cmd_du /usr/bin/du
retain hourly 6
retain daily 7
retain weekly 4
retain monthly 3
verbose 2
loglevel 5
logfile /shared/.backup/rsnapshot.log
ssh_args -i ~/.ssh/id_rsa -p 62222
# BACKUP DEFINITIONS
backup [email protected]:/ dev.local.root/ exclude_file=/shared/.backup/exclude.root,+rsync_long_args=--rsync-path='sudo rsync',rsync_short_args=-zalhHx
运行后rsnapshot hourly
我看到这个错误:
bash: sudo rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: remote command not found (code 127) at io.c(226) [Receiver=3.1.0]
----------------------------------------------------------------------------
rsnapshot encountered an error! The program was invoked with these options:
/usr/bin/rsnapshot hourly
----------------------------------------------------------------------------
ERROR: /usr/bin/rsync returned 127 while processing [email protected]:/
如果我检查我的rsnapshot.log
文件,我可以看到rsnapshot
尝试了这个命令:
/usr/bin/rsync -zalhHx --delete --numeric-ids --relative --delete-excluded --exclude-from=/shared/.backup/exclude.root --rsync-path='sudo rsync' --rsh=/usr/bin/ssh -i ~/.ssh/id_rsa -p 62222 [email protected]:/ /shared/.backup/hourly.0/dev.local.root/
如果我尝试在终端中运行相同的命令,我会收到此错误:
Unexpected remote arg: [email protected]:/
rsync error: syntax or usage error (code 1) at main.c(1348) [sender=3.1.0]
但是,如果我用引号括住--rsh
部分内容,一切就都正常了:
/usr/bin/rsync -zalhHx --delete --numeric-ids --relative --delete-excluded --exclude-from=/shared/.backup/exclude.root --rsync-path='sudo rsync' --rsh='/usr/bin/ssh -i ~/.ssh/id_rsa -p 62222' [email protected]:/ /shared/.backup/hourly.0/dev.local.root/
一些事实
username ALL=(ALL) NOPASSWD:ALL
在远程机器上, sudoers 文件中有一行。- 我通常可以使用我的 SSH 密钥通过 SSH 连接到远程机器。
- 我可以
sudo
在服务器上调用命令而不需要输入密码。 - 我无法以 root 身份 SSH 到远程计算机,
PermitRootLogin on
因为AllowUsers username
sshd_config
- 如果我尝试,输出是
ssh [email protected] -p 62222 -i ~/.ssh/id_rsa which rsync
/usr/bin/rsync
- 如果我尝试,输出是
ssh [email protected] -p 62222 -i ~/.ssh/id_rsa echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
所以....我的问题很简单:如何正确构建此rsync
命令rsnapshot
?
谢谢帮助!
答案1
我遇到了完全相同的错误,我被迫指定一个手动脚本
--rsync-path='sudo rsync' > --rsync-path='/usr/local/bin/rsync'
使用远程的 /usr/local/bin/rsync
#! /bin/sh
exec /usr/bin/sudo /usr/bin/rsync "$@"