Pit*_*itt 6 unix svn permissions rsync
我目前正在编写一个bash shell脚本,以将我们svn存储库的最新版本传输到Web服务器.这是通过使用svn导出到服务器A并使用web服务器进行rsync来完成的,创建了一个特殊用户(称为sync_user),在每一方(服务器A和Web服务器)上具有足够的权限来执行这些更新.该脚本使用"su sync_user"执行svn导出,使用rsync作为sync_user:
export -f sync_section
su sync_user -c "sync_section $source $tmp $dest"
Run Code Online (Sandbox Code Playgroud)
其中sync_section是脚本中的一个函数:
# critical section which performs the actual website update (export & sync)
# takes 3 parameters: source, tmp, dest
function sync_section {
source=$1
tmp=$2
tmp_old=$tmp"_old"
dest=$3
#enter critical section
set -e
# export to temp folder on server A
svn export -q --force $source $tmp --native-eol LF
# rsync with remote live website folder.
rsync -avzhiO $tmp $dest
# clean up
rm -rf $tmp_old
mv -f $tmp $tmp_old
# exit critical section
set +e
}
Run Code Online (Sandbox Code Playgroud)
我们的想法是,每个有权更新/同步网络服务器的人都知道sync_user的密码,因此可以进入"su sync_user"部分.
理论上听起来不错但是rsync对这个设置并不满意,并且给出了以下错误消息:(user_x是用户调用脚本)
#### rsync output:
building file list ... rsync: pop_dir "/home/user_x" failed: Permission denied (13)
rsync error: errors selecting input/output files, dirs (code 3) at flist.c(1314) [sender=2.6.8]
Run Code Online (Sandbox Code Playgroud)
经过一些googeling我发现我遇到的问题是由rsync引起的,因为它要求sync_user对脚本调用者的主目录具有完全访问权限.那是对的吗?如果是这样,为什么?它有解决方法吗?
注意:脚本中根本不使用用户的主目录.仅使用服务器A上的/ tmp /和Web服务器上的/ var/www/vhosts /.
好吧,经过一番来回,我们终于解决了这个问题。这完全是一个用户权限问题,与 rsync 无关。
运行“susync_user ...”时,活动终端指向调用脚本的用户的主目录(user_x)。由于sync_user甚至不允许位于该文件夹中,因此不允许运行某些命令(如rsync或ls),这会导致错误消息。
为了解决这个问题,我在运行“sync_section 脚本”之前添加了“cd ~”:
su sync_user -c "cd ~; sync_section $source $tmp $dest"
Run Code Online (Sandbox Code Playgroud)
现在这个脚本就像一个魅力:)
我希望这对将来的人有帮助!