Using rsync for One-Way Sync for backup

If you’re looking to set up a one-way sync between a NAS running Debian and a backup machine also running Debian, rsync is a powerful tool to achieve this. This guide will walk you through the necessary steps to ensure your files are securely and efficiently synchronised. It should work with any type of Linux and not just Debian.

1. Install rsync

First things first, ensure that rsync is installed on both your NAS and Backup machine by running the following commands:

sudo apt update
sudo apt install rsync

2. Create an rsync Script

To achieve a one-way sync, we will create a script that uses the rsync command. This setup ensures that if files are deleted from the Backup, they will be copied over from the NAS the next time the script runs, without overwriting any existing files on the Backup machine.
Here’s a sample script you can use:

#!/bin/bash
rsync -av --ignore-existing --delete-missing-args /path/to/nas/ user@backup-machine:/path/to/backup/

Explanation of the options:
-a: Archive mode, which preserves permissions, timestamps, symbolic links, and more.
-v: Verbose output, so you can see what rsync is doing.
--ignore-existing: Ensures that rsync will skip updating files that already exist on the Backup machine.
--delete-missing-args: Deletes files that are missing from the source (NAS), thereby copying them back during the next sync.

3. Set Up SSH Key-Based Authentication

While optional, setting up SSH key-based authentication between your NAS and Backup machine helps automate the process without repeatedly entering a password. Here’s how you can do it:

Generate SSH keys on your NAS:

ssh-keygen

Copy the public key to your Backup machine:

ssh-copy-id user@backup-machine

4. Schedule the Sync Using cron

To automate the sync process every hour, you’ll use cron. Open the crontab configuration for editing:

crontab -e

Add the following line to schedule the script to run every hour:

0 * * * * /path/to/your/rsync-script.sh

With these steps, you’ll have a robust setup for a one-way sync from your NAS to your Backup machine. The files will be copied over if they’re missing in the Backup, without affecting the original files on the NAS.

About Author

Related Posts

php8 gd

PHP8 gd Activate after installation

PHP8 GD activate after installation. GD doesn’t get activated by default. Not even a reboot after installation will activate it. So how do we do it? In…

personal dns

The Thrilling Pros & Sobering Cons of Personal DNS

Consider a personal DNS? Domain Name System (DNS) serves as the internet’s phonebook. Every time you visit a website, your computer or device needs to convert the…

Debian 12: linux-image-6.1.0-10amd64

Troubleshooting dependency issues in Debian 12: Resolving linux-image-6.1.0-10amd64 package dependency problems. If you installed the Debian 12 from the live image the issue is the raspi-firmware. Even…

4 Best Free Nas Software That Is Open Source

Free NAS software or operating systems that are free to use and will turn a computer into a NAS more advanced than the dedicated boxes sold. What…

Raspbian default password

Raspbian default password

Looking for the Raspbian default password? It is the most essential username and password that you will need for your raspberry. At least if you are running…

OpenMediaVault default password

OpenMediaVault default password

OpenMediaVault default password is printed in the documentation. I did not see it the first time I installed it either. So I had to do some detective…

Leave a Reply