Defining a Custom Port for Rsnapshot Backup

  ·   3 min read

Rsnapshot is a powerful filesystem snapshot utility for making backups of local and remote systems. It leverages rsync and hard links to create efficient and space-saving backups. By default, rsnapshot uses SSH to connect to remote systems, which typically operates over port 22. However, there are scenarios where you might need to define a custom port for SSH connections, such as when the remote server is configured to use a non-standard port for security reasons. This article will guide you through the process of configuring rsnapshot to use a custom SSH port.

Prerequisites

Before proceeding, ensure you have the following:

  1. Rsnapshot installed on your system.
  2. SSH access to the remote server with a non-standard port.
  3. Basic understanding of SSH and rsnapshot configuration files.

Step-by-Step Guide

Step 1: Verify SSH Access

First, confirm that you can access the remote server using SSH on the custom port. Use the following command, replacing username, hostname, and port_number with your specific details:

ssh -p port_number username@hostname

If you can successfully connect, proceed to the next step. If not, troubleshoot your SSH access before continuing.

Step 2: Modify Rsnapshot Configuration

Locate your rsnapshot configuration file, typically found at /etc/rsnapshot.conf. Open it in your preferred text editor:

sudo nano /etc/rsnapshot.conf

Step 3: Define the Custom SSH Port

In the rsnapshot configuration file, you’ll need to specify the custom SSH port. Find the backup line that corresponds to the remote server. It should look something like this:

backup  username@hostname:/remote/directory/  local/directory/

To specify a custom port, modify the line to include the -e option for SSH, followed by the custom port number. The updated line should look like this:

backup  username@hostname:/remote/directory/  local/directory/  +rsync_long_args=--rsh='ssh -p port_number'

Step 4: Test the Configuration

Before running a full backup, it’s a good idea to test the configuration to ensure everything is set up correctly. Use the following command to perform a dry run:

sudo rsnapshot -t hourly

This command will simulate the backup process without making any changes. Check the output for any errors related to SSH connectivity or configuration issues.

Step 5: Run the Backup

If the dry run completes without errors, you can proceed to run the actual backup:

sudo rsnapshot hourly

Monitor the output to ensure the backup completes successfully.

Conclusion

By following these steps, you can configure rsnapshot to connect to remote servers using a custom SSH port. This flexibility allows you to adapt to various network configurations and security policies while maintaining efficient and reliable backups.

Additional Resources

By leveraging the power of rsnapshot and SSH, you can create a robust backup solution tailored to your specific needs. Remember to regularly test your backups and review your configuration to ensure ongoing reliability and security.