The cart is empty

In today’s digital age, backing up data is more important than ever. Whether you are running websites, applications, or any other services on a Virtual private server (VPS), ensuring that your data is securely backed up to a remote storage server is essential. This article will guide you through the steps required to set up automatic backup for your VPS.

Prerequisites

Before starting the configuration, make sure you have:

  • Root or sudo access to your VPS.
  • A remote storage server or Cloud storage with sufficient storage space.
  • SSH key installed and configured for secure communication between VPS and remote storage.

Step 1: Installing and Configuring Backup Tool

For automatic backups, you can use various tools like rsync, Bacula, or rclone. For the purposes of this article, we will use rsync for its simplicity and efficiency.

  1. Install rsync on your VPS using the command line:
    sudo apt update && sudo apt install rsync -y
    ​
  2. Ensure rsync is installed:
    rsync --version
    ​

Step 2: Setting Up SSH Keys for Secure Communication

Generate an SSH key on your VPS if you haven't already:

ssh-keygen -t rsa -b 4096

Copy the public key to the remote storage server:

ssh-copy-id This email address is being protected from spambots. You need JavaScript enabled to view it.

 

Step 3: Configuring Automatic Backup Using rsync

Create a backup script:

Open a text editor:

nano /usr/local/bin/backup_script.sh

Insert the following command into the script, replacing user, remote-storage.com, and /path/to/your/data and /path/to/remote/storage with your actual details:

#!/bin/bash
rsync -avz -e ssh /path/to/your/data This email address is being protected from spambots. You need JavaScript enabled to view it.:/path/to/remote/storage

 

Save and close the editor (CTRL+X, then Y and Enter to save changes).

 

 

Step 4: Setting Up a Cron Job for Automatic Backup Execution

Open the crontab configuration:

crontab -e

Add a line defining how often you want the backup to run. For example, for daily backup at 2:00 AM:

0 2 * * * /usr/bin/bash /usr/local/bin/backup_script.sh

 

Save and close the crontab.

 

 

Your VPS should now be configured for automatic backup to a remote storage server. It’s important to regularly check the backups to ensure the process is running smoothly. Don’t forget to update your backup scripts and strategies as needed to accommodate the growing needs of your projects and data.