Sunday, July 8, 2018

rsync in action

https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories-on-a-vps

To play in full safety, let's run tests in a docker container!

docker run -dit --privileged --name centos centos
docker attach centos
yum install rsync
yum install openssh openssh-server openssh-clients openssl-libs
groupadd centos
useradd -g centos centos
su - centos
cd ~
mkdir dir1
mkdir dir2
touch dir1/file{1..100}

#the "n" flag is "try-run" only, "v" is verbose, "a" is copy also links and preserve times ownership etc
rsync -anv dir1/ dir2


see also https://www.rosehosting.com/blog/how-to-configure-and-use-openssh-on-centos-7/ to configure sshd

if you get "Failed to get D-Bus connection: Operation not permitted" when starting sshd, probably you are not running the container in privileged mode




remotely:

rsync -a dir1/ centos@localhost:/home/centos/dir2

to syncronize 2 folders upon deletion:

rm dir1/file99
#this will delete file99 also on dir2
rsync -anv --delete dir1/ centos@localhost:/home/centos/dir2




more flags: -z adds compression, -P adds progress report,

No comments: