> For the complete documentation index, see [llms.txt](https://sh.howtocode.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sh.howtocode.dev/3.0.0.part3intro/3.6.0.archiving-and-backup/3.6.4.rsync.md). Agents can also search and read this documentation through its [MCP server](https://sh.howtocode.dev/~gitbook/mcp).

# সিনক্রোনাইজেশন

নির্দিষ্ট সময় পর পর প্রয়োজনীয় তথ্য ব্যাকআপ রাখা একটা সাধারণ ব্যাপার বিশেষ করে সার্ভারের ক্ষেত্রে। ব্যাকআপ রাখার জায়গাটি কোনো লোক্যাল স্টোরেজ ডিভাইস হতে পারে(এক্সটার্নাল হার্ডডিস্ক বা পেনড্রাইভ) বা রিমোটলি নেটওয়ার্কে সংযুক্ত কোনো কম্পিউটারও হতে পারে। এধরণের ব্যাকআপ রাখতে সবচেয়ে জনপ্রিয় টুল হল `rsync`। এর মাধ্যমে আপনি রিমোট বা লোকাল স্টোরেজে ডাটা সিনক্ করতে পারবেন। এর কমান্ড কাঠামোটি এরকম:

```
rsync options source destination
```

`source` ও `destination` নীচের যেকোনো একটি হতে পারে:

* লোকাল ফাইল বা ডিরেক্টরি।
* রিমোট ফাইল বা ডিরেক্টরি যাকে এভাবে চিহ্ণিত করা যাবে: \[user@]host:path
* একটি রিমোট সিনক্রোনাইজেশন সার্ভার। যার URI এরকম হবে: rsync://\[user@]host\[:port]/path

উল্লেখ্য, একইসাথে সোর্স ও ডেস্টিনেশন দুটোই রিমোট হতে পারবে না।

এবার আমরা আগে থেকে তৈরী করা playground ডিরেক্টরিটি playground\_mirror নামের ডিরেক্টরির সাথে সিনক্রোনাইজড করবো এভাবে:

```
me@howtocode-pc:~$ mkdir playground_mirror
me@howtocode-pc:~$ rsync playground playground_mirror
...
...
...
sent 137,585 bytes  received 49,867 bytes  374,904.00 bytes/sec
total size is 0  speedup is 0.00
```

আমরা প্রথমে `mkdir` দিয়ে playground\_mirror ডিরেক্টরিটি তৈরী করেছি। তারপর `rsync -av playground playground_mirror` কমান্ড দিয়ে সিনক্ করেছি। `-a` অপশন দিয়ে আমরা archive মোড সিলেক্ট করেছি। যার ফলে ফাইল ও ডিরেক্টরির পার্মিশন ও ওনার ইনফরমেশন পরিবর্তিত হবে না। এবং `-v` দিয়ে verbose ট্রিগার করেছি যেন কাজের সময় তথ্য দেখায়।

`rsync` শুধু সেইসব ফাইলই কপি করে যেগুলো পরিবর্তিত হয়েছে। এজন্য এখন আবার আমরা যদি পূর্ববর্তী কমান্ডটি দিই তাহলে এরকম দেখতে পাবো:

```
me@howtocode-pc:~$ rsync -av playground playground_mirror
sending incremental file list

sent 35,823 bytes  received 125 bytes  71,896.00 bytes/sec
total size is 0  speedup is 0.00
```

আমরা দেখতে পাচ্ছি কোনো ফাইল পাঠায়নি। এবার একটা ফাইলকে `touch` কমান্ডের মাধ্যমে নতুন মোডিফিকেশন ডেট দেবো এবং আবার কমান্ডটি দিয়ে দেখবো:

```
me@howtocode-pc:~$ touch playground/dir-051/file-A
me@howtocode-pc:~$ rsync -av playground playground_mirror
sending incremental file list
playground/dir-051/file-A

sent 35,876 bytes  received 150 bytes  72,052.00 bytes/sec
total size is 0  speedup is 0.00
```

আমরা দেখতে পাচ্ছি নতুন মোডিফিকেশন ডেটের ফাইলটি শুধু কপি করেছে।

কখনো কখনো আমরা চাই মিররে সেইসব ফাইল থাকবে না যা মূল জায়গায় নেই সেক্ষেত্রে `--delete` অপশন যোগ করতে হয়। আমরা প্রথমে playground এর কিছু ফাইলসহ একটি ডিরেক্টরি ডিলিট করে দেবো এবং এর উদাহরণ দেখবো:

```
me@howtocode-pc:~$ rm playground/dir-099
me@howtocode-pc:~$ rsync -av --delete playground playground_mirror
sending incremental file list
deleting playground/dir-099/file-Z
deleting playground/dir-099/file-Y
deleting playground/dir-099/file-X
deleting playground/dir-099/file-W
deleting playground/dir-099/file-V
deleting playground/dir-099/file-U
deleting playground/dir-099/file-T
deleting playground/dir-099/file-S
deleting playground/dir-099/file-R
deleting playground/dir-099/file-Q
deleting playground/dir-099/file-P
deleting playground/dir-099/file-O
deleting playground/dir-099/file-N
deleting playground/dir-099/file-M
deleting playground/dir-099/file-L
deleting playground/dir-099/file-K
deleting playground/dir-099/file-J
deleting playground/dir-099/file-I
deleting playground/dir-099/file-H
deleting playground/dir-099/file-G
deleting playground/dir-099/file-F
deleting playground/dir-099/file-E
deleting playground/dir-099/file-D
deleting playground/dir-099/file-C
deleting playground/dir-099/file-B
deleting playground/dir-099/file-A
deleting playground/dir-099/
playground/

sent 35,480 bytes  received 912 bytes  72,784.00 bytes/sec
total size is 0  speedup is 0.00
```

আমরা দেখতে পেলাম আমাদের ডিলিট করা ডিরেক্টরি ও ফাইলসমূহও মিরর থেকে ডিলিট করে ফেলা হল।
