Setting Up Automated Data Transfer from Master to Slave Server

Prerequisites:

  • rsync and ssh installed on both master and slave servers.
  • SSH access without password from slave to master. You can achieve this using SSH keys.

1. Setup SSH Key-based Authentication:

On the slave server:

# Generate the SSH key (press Enter for all prompts to accept defaults)
ssh-keygen

# Copy the SSH key to the master server
ssh-copy-id username@master_server_ip

This process ensures the slave server can SSH into the master server without a password.

2. Create the Rsync Script:

On the slave server:

a. Create the Script:

nano /path/to/your/script/pull_backup.sh

b. Add the Following Content:

#!/bin/bash

# Define source and destination
MASTER_DIR="username@master_server_ip:/home/your_user/DB-VK/"
SLAVE_DIR="/path/on/slave/to/store/backups"

# Use rsync to pull the backup folder
rsync -avz --delete $MASTER_DIR $SLAVE_DIR

echo "Data sync completed!"

Note: The --delete option will make sure that if a file is deleted on the master, it will also be deleted on the slave during the sync process.

c. Make the Script Executable:

chmod +x /path/to/your/script/pull_backup.sh

3. Automate the Data Transfer with Cron:

a. Open Crontab:

crontab -e

b. Schedule the Rsync Script:

To run the script daily at 2:30 AM, 30 minutes after the backup process on the master server:

30 2 * * * /path/to/your/script/pull_backup.sh >> /path/to/your/log/sync_log.txt 2>&1

4. Final Notes:

  • Ensure you have enough storage space on the slave for the pulled backups.
  • Monitor sync_log.txt regularly to ensure data is being synchronized without issues.

With this setup, you’ll have the backup data automatically pulled from the master server to the slave server daily. This further enhances your backup strategy by ensuring you have copies of the backup in two different serve

Leave a Reply

Your email address will not be published. Required fields are marked *