Menu
User

DropVPS Team

Writer: John hens

How to Create Automated Backups on a Linux VPS

How to Create Automated Backups on a Linux VPS

Publication Date

02/06/2026

Category

Articles

Reading Time

2 Min

Table of Contents

Automated backups are essential to protect your data and ensure quick recovery in case of accidental deletion, server failure, or malware attacks

Step 1: Update Your System

Before setting up backups, make sure your VPS is up to date.Keeps your system secure and ready for backup tools.

sudo apt update && sudo apt upgrade -y

Step 2: Create a Backup Directory

Create a dedicated directory to store backups.Stores all backup files in a central location.

mkdir -p /home/username/backups

Step 3: Create a Backup Script

Write a simple shell script to back up important directories.Compresses important directories into a timestamped backup file.

nano /home/username/backup.sh

Add the following content:

#!/bin/bash
tar -czf /home/username/backups/backup-$(date +%F).tar.gz /var/www /etc

Step 4: Make the Script Executable

Allow the backup script to run.Grants execute permissions to the backup script.

chmod +x /home/username/backup.sh

Step 5: Test the Backup Script

Run the script manually to ensure it works correctly.Verifies that backups are created without errors.

/home/username/backup.sh

Step 6: Automate Backups with Cron

Schedule automated backups using cron.Automates backup execution without manual intervention.

crontab -e

Add a line to run the backup daily at 2 AM:

0 2 * * * /home/username/backup.sh

Step 7: Verify Backups Regularly

Check your backup directory and ensure files are being created.Confirms that automated backups are working as expected.

ls -lh /home/username/backups/

Step 8: Optional – Remote Backup

For extra safety, copy backups to a remote server or cloud storage.Keeps backups safe even if the VPS fails.

rsync -avz /home/username/backups/ user@remote_server:/path/to/backups/
Linux VPS
U
Loading...

Related Posts