Automated Backups With Rsync on Linux VPS (Step-by-Step)

Automated Backups With Rsync on Linux VPS (Step-by-Step)

Automated Backups With Rsync on Linux VPS (Step-by-Step) blog

Ever wondered how automated backups rsync Linux VPS protect critical data daily? Losing data on a Linux VPS hurts any Linux system, business, or developer.

This guide explains rsync backups, the rsync command, and a simple backup process. You’ll automate backups using a cron job, crontab file, ssh keys, and a secure remote server.

Automated backups with Rsync require stable storage and consistent network performance. The comparison table below highlights VPS hosting providers that support secure, scheduled backup processes without resource bottlenecks. Explore our recommended VPS hosting options.

Linux VPS Hosting Providers Suited for Automated Backup Workflows

ProviderUser RatingRecommended For 
Kamatera Logo4.8ScalabilityVisit Kamatera
4.6AffordabilityVisit Hostinger
4.7DevelopersVisit IONOS

Takeaways
  • Rsync transfers changed files, saving time.
  • Linuxinclude the source host and the backup server.
  • Passwordless SSH keys enable automated backups.
  • A cron job runs the backup script automatically on Linux.
  • Restore files by reversing the rsync command.
  • Log file and alerts track backup process failures.
  • Dry run test verifies rsync backups before restore.

Understanding the Importance of Automated Backups Rsync Linux VPS

An arrow with two servers showing data backup on a computer screen.

Rsync (Remote Sync) is a built-in Linux utility for efficient, secure file transfers. It uses delta-transfer logic to sync only changed files between systems.

This method cuts bandwidth use and speeds up each rsync backup. For instance, if a directory is 100 GB total, rsync transfers only the 500 MB of data that has changed. It makes the rsync utility ideal for frequent automated backups.

Automating backups ensures data integrity without daily manual intervention. Schedule cron jobs run during off-peak. This backup system maintains business continuity and Linux VPS performance.

The rsync utility syncs the local machine or Linux VPS using encrypted SSH connections. It supports remote server, external drive backups, and reliable rsync backups. This setup fits modern backup systems.

Prerequisites for Setting Up Your Linux System

An illustration of automated backups with Rsync on a whiteboard.

Before setup, prepare two Linux instances: a source “host” and a “backup server.” Use a backup server, a Linux VPS hosting, a Raspberry Pi, or a Linux machine. Ensure sufficient storage capacity for the backup directory.

You need administrative sudo access on both Linux machines. Without root privileges, you cannot install packages. You also can’t safely change permissions or system configuration files.

For external drive backups, use the ext4 file system. Ext4 works best across most Linux distributions. Get the UUID via sudo blkid and add it to /etc/fstab for persistent mounting across reboots.

Reliable connectivity keeps automated backups running without failure. Use static IPs for local networks (e.g., 192.168.0.5) or for public VPS servers. Dynamic addresses break automation when connections change unexpectedly.

Namecheap

Get Your Domain and All You Need to Launch you Online business
Visit Site Coupons6

Step 1: How to Install Rsync on Both Servers

Most modern Linux distributions include rsync by default. Verify installation by running rsync –version on your Linux server. If version details appear, then you’ve installed the rsync utility.

If rsync is missing, install it before continuing setup. On Ubuntu, Debian, or Raspbian systems, run:

sudo apt-get -y install rsync

The tool must be present on both the Linux VPS source and destination backup systems. The rsync command-line utility relies on compatible versions. It ensures reliable syncing files between systems.

Rsync works across most modern Linux distributions and servers. It includes Ubuntu 20.04 and AWS Linux instances. In most cases, repositories provide a stable default version.

rsync installation on Ubuntu.

Step 2: Configuring Passwordless SSH for Remote Backups

To automate backups, configure passwordless authentication between your Linux machines. Generate a secure SSH key pair on the local machine using:

ssh-keygen -t rsa -b 4096

Leave the password field blank to allow scripts to run unattended. Passphrases increase security but block automated backup process execution. This step enables smooth automation of cron jobs and shell scripts.

The ssh-keygen command creates files in the SSH directory. They are: private key (idrsa) and a public key (idrsa.pub). A private key stays on the local machine. The public key gets copied to the remote server.

Copy the public key using the following command:

ssh-copy-id username@remote_ip

It stores the key and enables passwordless connection. Test SSH access to confirm proper permissions and configuration. Use rsync with restricted access to limit access to a specific backup directory.

Generating an ssh key on Ubuntu.

Step 3: Performing Your First Backup Manually

Before automating rsync backups, test the connection first. This simple step checks permissions and finds setup problems early. It helps protect your backup process.

Run this rsync command to test syncing files:

rsync -avz –progress ~/Documents/ backup_server:~/Documents

Let’s break down what each flag does:

  • -a: Archive mode keeps permissions, symlinks, and timestamps.
  • -v: Verbose output shows transferred files.
  • -z: Compresses data during transfer to save bandwidth.

This copies data safely to the backup server.

Progress displays live transfer stats. Your first backup may be slow. Later rsync backups sync only changes. Speed depends on hardware, network, and server limits.

Running a manual rsync test.

Step 4: Creating a Robust Backup Script

Manual commands help with testing, but automation needs a shell script. Create a bash script like do_backup.sh to manage rsync backups. Scripts simplify the backup process and reduce the need for repeated commands.

Use an exclude file to skip directories like /.cache, /.ssh, or specific log files. It saves space and avoids copying temporary files. It keeps the backup directory clean.

Basic script example using the rsync command:

#!/bin/bash

rsync -avz –exclude-from=’/home/user/backup/exclude.txt’ \

 /home/user/ user@backup_server:/backup/home/

Add error checks and write output to a log.

if [ $? -eq 0 ]; then
  echo “Backup completed successfully”>> /var/log/backup.log
else
  echo “Backup failed”>> /var/log/backup.log
fi

Make the script executable so cron can automate backups:

chmod a+x ~/backup/do_backup.sh

A simple Bash backup script using rsync with an exclude list and basic success-failure logging.

Why a High-Performance Linux VPS is Essential for Growth

Reliable automated backups rsync Linux VPS need a stable Linux server environment. Setting up a professional website or store is the first step to business success.

Managing your own server requires an understanding of managed vs unmanaged VPS. This choice affects provider backups or custom rsync backup system setups.

Advanced users prefer full control over their backup system. Choosing the right VPS provider ensures bandwidth and reliable hardware.

Once your data is secure, explore VPS use cases confidently. Servers support the development, hosting, and business applications.

Build Your App Now with Hostinger Horizons
Turn your idea into a powerful app in minutes with Hostinger Horizons. No coding, no hassle, just AI-powered building that brings your vision to life.
Visit Hostinger

Step 5: Using a Crontab File for Automation

Cron is a time-based scheduler on every Linux server. Open the cron configuration using the command line utility crontab -e. This edits the active crontab file.

The crontab file follows the time fields: minute, hour, day of month, month, and day of week. Add the following line format.

Use this example to automate backups every fifteen minutes:

*/15 * * * * /path/to/backup_script.sh > /dev/null 2>&1

For daily remote backups at 2:05 AM, schedule this cron job:

5 2 * * * /path/to/backup_script.sh

The > /dev/null 2>&1 portion redirects output to avoid emails, but logs help verify execution. 

Cron configuration with a scheduled rsync backup job running every 15 minutes.

Comparison of Rsync Backup System Configurations

Compare rsync backup system configurations for different needs

FeatureStandard SyncAdvanced AutomationSecurity-Focused 
ScheduleManualEvery 15 minutesDaily at 2:05 AM
LoggingConsole outputbackup.log via cronLogrotate (7-day history)
Flags-avz-avz –delete-excluded-az –delete -e ssh
SecurityPassword-basedPasswordless SSHrrsync restricted shell

Step 6: Managing Logs and Notifications for Your Backup System

Proper logging helps monitor rsync backups and overall backup system health. Redirect script output to a log file for easy review:

/path/to/backup_script.sh >> /home/user/backup/backup.log 2>&1

This command saves errors and output inside the backup directory. Logs grow over time and may affect Linux server storage. Managing size protects long-term data.

Use /etc/logrotate.d/ to automatically rotate logs. Create a setup keeping seven weekly logs. It prevents disk overflow and supports troubleshooting.

For alerts, integrate CURL to send notifications to Slack or Mattermost. Notify the user or administrator of failures immediately.

Custom logrotate rule to manage and compress weekly backup logs, keeping seven rotations.

Example webhook notification:

curl -X POST -H ‘Content-type: application/json’ \
  –data ‘{“text”:”Backup failed on server01″}’ \
  YOUR_WEBHOOK_URL

How to Restore Data from Your Rsync Backups

Restoration uses a reverse rsync from the backup server to the host. It mirrors the same backup process, swapping source and destination. This method helps securely transfer files back safely.

Use this rsync command to restore from a remote server:

rsync -az -e ssh username@remote_ip:/backup/folder /local/restore/point

It relies on SSH to copy files securely.

Alternatively, use SCP for single-file restores:

scp -r user@remote_ip:/backup/file ~/Downloads

Always verify with a dry run using -n. The rsync avz flags keep archive mode and compression.

VPS
Cheap VPS
best option

Conclusion

Setting up automated backups rsync Linux VPS protects data with minimal effort. Passwordless SSH, cron, and scripts create a reliable backup system. Regular tests and log checks keep restores dependable.

Ready to improve automated backups rsync Linux VPS today? Start by understanding how to backup VPS and secure your Linux VPS properly.

Next Steps: What Now?

Here’s what to do next after setting up automated rsync backups.

  1. Learn how to secure and optimize your VPS performance.
  2. Review dedicated Linux server backups for larger workloads.
  3. Learn about free Linux VPS services for testing backup scripts.
  4. Understand VPS infrastructure and remote servers.
  5. Learn how to transfer full server backups using cPanel tools.

Frequently Asked Questions

How often should I run automated rsync backups?

Run backups based on how often data changes. Critical Linux servers need frequent backups; less critical runs daily during low traffic.

Can I use rsync to backup a Windows Server?

Rsync is a Linux command-line utility tool. Windows Server needs WSL or cwRsync to install rsync.

What's the difference between rsync and traditional copy commands?

Traditional copy files commands transfer everything each time. Rsync transfers only changed files, saving bandwidth on remote connections.

How do I exclude specific directories from my backup?

Create an exclude file, reference it using –exclude-from=’/path/to/exclude.txt’ in the rsync command. Skip the cache directory, temp files, and the SSH keys in the home directory.

Is rsync secure for transferring sensitive data?

Yes, with SSH, data is encrypted during secure transfers. Use rrsync to restrict the backup user’s access to directories on the remote machine.

Can I automate backups to an external drive?

Yes, mount the external drive using fstab to a fixed location. Configure the backup script to target the mount point automatically.

Handling Webhook Traffic at Scale in n8n

N8n webhook scaling breaks down faster than you'd expect. When request volumes spike, concurrency pressure builds, and executions start backin...
8 min read
Christi Gorbett
Christi Gorbett
Content Marketing Specialist

Running n8n in Production - Stability Checklist

Getting workflows live is only half the battle. n8n production stability is what keeps your automations running reliably when it actually matt...
8 min read
Christi Gorbett
Christi Gorbett
Content Marketing Specialist

CI/CD Pipelines for Deploying n8n Updates

Manually pushing n8n updates across environments is error-prone and time-consuming. A well-configured n8n CI/CD pipeline changes that. It auto...
8 min read
Christi Gorbett
Christi Gorbett
Content Marketing Specialist

Running n8n with Docker Compose vs Bare-Metal VPS

Choosing between n8n Docker Compose vs bare metal VPS comes down to more than personal preference. It affects how you deploy, scale, and maint...
8 min read
Christi Gorbett
Christi Gorbett
Content Marketing Specialist
Click to go to the top of the page
Go To Top
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.