Rsync viết tắt của “Remote Sync.” là công cụ command line được sử dụng để đồng bộ dữ liệu giữa các máy tính với nhau thông qua kết nối bảo mật SSH. Rsync có nhiều ưu điểm với cả nén và giải nén dữ liệu khi đồng bộ giúp bạn tiết kiệm thời gian cũng như chi phí băng thông.
Thông thường Rsync đã được cài đặt sẵn trong các phiên bản Linux, tuy nhiên vì có 1 lý do nào đó mà máy bạn chưa được cài đặt thì bạn có thể cài bằng command sau:
sudo apt -y install rsync
sudo yum -y install rsync
1. Cú pháp lệnh
# copy file/folder từ server hiện tại tới 1 remote server rsync [-options] <source_path> <your_user>@<destination_server>:<destination_path> # Copy file/folder từ 1 remote Server tới server hiện tại rsync [-options] <your_user>@<source_server>:<source_path> <destination_path>
2. Đồng bộ file
Đồng bộ file từ local to remote server
rsync -av test.txt user@10.0.2.2:/tmp
Đồng bộ ngược file từ remote server về local
rsync -av user@10.0.2.2:/tmp/test.txt /home/vinasupport/database
Với tham số:
3. Đồng bộ folder
rsync -aP ~/Desktop/test test@vinasupport.com:~/Desktop/test/
Tham số -P để hiển thị process thực hiện
Trường hợp port ssh của remote server không phải là port mặc định thì ta sử dụng tham số -e để thay đổi port
rsync -aP -e 'ssh -p 2222' ~/Desktop/test test@vinasupport.com:~/Desktop/test/
Với Rsync chúng ta có thêm 1 giải pháp tốt cho việc đồng bộ dữ liệu trên môi trường Linux.
Nguồn: vinasupport
Tips: Tham gia Channel Telegram KDATA để không bỏ sót khuyến mãi hot nào