Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permissions and ownership not correctly synched #24

Open
vstefanoxx opened this issue Feb 18, 2016 · 3 comments
Open

Permissions and ownership not correctly synched #24

vstefanoxx opened this issue Feb 18, 2016 · 3 comments

Comments

@vstefanoxx
Copy link
Collaborator

Hi

When changing only permission and ownership in one side, bsync doesn't detect the modification and doesn't propagate it.

I'm doing it with a separate bash script: it synchronizes only files differents by permissions or ownership, and uses rsync and some trick to force synchronization in the right direction (I can't let rsync decide the direction of synchronization based on modification time, because obviously we need to check the change time).

Here is the bash script I'm using: probably not possible to use any of it to integrate in bsync, but I show just as an example. Also, this is a simple, not updated version, that only synchronize in one direction from remote to local.

#!/bin/bash
scriptname="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"
local_path="$1"
remote_ip="$2"
remote_path="$3"
RSYNC_ARGS="$4"

[ -z "$RSYNC_ARGS" ] && RSYNC_ARGS="-a -A -X -z -E"

local_path="${local_path%%/}"
remote_path="${remote_path%%/}"
tmp_file="/tmp/${scriptname}_$RANDOM"

/usr/bin/rsync --rsync-path="rsync" $RSYNC_ARGS -ui -e "/usr/bin/ssh -C -i /root/.ssh/id_rsa -p 22" \
    "$local_path/" root@$remote_ip:"$remote_path/" --dry-run | \
    grep -Ev "^[^ ]*(c|s|t)[^ ]* " | \
    grep -E "^[^ ]*(p|o|g|a)[^ ]* " | \
    sed -e 's/^[^ ]* //' >"$tmp_file"

cd "$local_path"
cat "$tmp_file" | xargs -I {} stat -c '%n|%Z|%Y' "{}" | sort >"${tmp_file}.1"

cat "$tmp_file" | /usr/bin/ssh -C -i /root/.ssh/id_rsa -p 22 root@$remote_ip "cd \"$remote_path\" ; xargs -I {} stat -c '%n|%Z|%Y' \"{}\"" | sort >"${tmp_file}.2"

join -j 1 -t \| -o 1.1,1.2,2.2 "${tmp_file}.1" "${tmp_file}.2" | awk -F'|' '{if ($2 < $3) print $1}' | \
    /usr/bin/rsync --rsync-path="rsync" $RSYNC_ARGS -ui -e "/usr/bin/ssh -C -i /root/.ssh/id_rsa -p 22" \
    root@$remote_ip:"$remote_path/" "$local_path/" --files-from=-

rm -f "$tmp_file"*
@dooblem
Copy link
Owner

dooblem commented Feb 18, 2016

Hello Stefano,
Thanks for sharing.

I wrote it in the README, in limitations: file ownership is ignored by bsync.

However, it should work for permissions. I was not able to reproduce it. Can you provide more info / steps to reproduce.

Thanks in advance,
Marc

@vstefanoxx
Copy link
Collaborator Author

You are right, permissions are correctly synched.

Do you think is a good idea to add support for ownership synchronization?
It should be pretty easy adding %U and %G format option to find command.

2016-02-18 21:07 GMT+01:00 Marc MAURICE [email protected]:

Hello Stefano,
Thanks for sharing.

I wrote it in the README, in limitations: file ownership is ignored by
bsync.

However, it should work for permissions. I was not able to reproduce it.
Can you provide more info / steps to reproduce.

Thanks in advance,
Marc


Reply to this email directly or view it on GitHub
#24 (comment).

@dooblem
Copy link
Owner

dooblem commented Feb 23, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants