Setting Up Automatic Backups on Your Linux VPS

Data loss happens unexpectedly. Hardware fails, software bugs corrupt files, and human error deletes the wrong directory. Relying on manual snapshots is a risky habit. You need a reliable system that secures your files without constant supervision. This guide breaks down the exact steps to automate your server backups. The process uses standard Linux tools available on almost every distribution, including Ubuntu 24.04. You will learn how to install the scheduler, compress your data, store it securely, and run the task automatically. No complex third-party software is required. Just a few terminal commands and a basic text editor. Follow these instructions to protect your web applications and configurations. Your server will handle the heavy lifting while you sleep.

Setting Up Automatic Backups on Your Linux VPS.

Why It's Important to Set Up Automatic Backups

Servers crash without warning. Disks fail, and your data disappears with them. Manual backups rely entirely on your memory, meaning you will eventually forget to run them. Automated systems remove human error from the equation. Your files get copied on a strict schedule. This guarantees recovery points even after catastrophic failures. Off-site storage adds another layer of protection. If the entire data center goes offline, your remote backup remains safe. This simple habit saves businesses from permanent data loss.

How to Set Up Automatic Backups on an Unmanaged VPS: Guide 2026

Update your package lists and install the scheduler. Minimal server images often omit the task daemon by default.

apt update

This command refreshes the local package index to ensure the system knows about the newest versions of available software.

apt install cron -y

This installs the cron daemon for scheduling tasks. The "-y" flag automatically confirms the installation without prompting the user.

systemctl enable --now cron

This starts the cron service immediately and enables it to run automatically after server reboots.

Create the necessary directories before writing the script. Missing folders will cause the archiver to fail silently.

mkdir -p /backup

This creates a dedicated directory at the root of your file system to store all future backup archives.

mkdir -p /var/www

This ensures the standard web directory exists. Creating it prevents the archiver from throwing errors on fresh server installations.

Build the backup script line by line. This method prevents text editor errors and keeps variables intact.

sh -c 'echo "#!/bin/bash" > /usr/local/bin/vps-backup.sh'

This creates the script file and adds the required shebang line to the very first row.

sh -c 'echo "DATE=\$(date +%Y-%m-%d)" >> /usr/local/bin/vps-backup.sh'

This adds a variable that captures the current date for the backup file name. The backslash prevents the system from evaluating the date prematurely.

sh -c 'echo "tar -czf /backup/backup-\$DATE.tar.gz /var/www /etc" >> /usr/local/bin/vps-backup.sh'

This line compresses your web files and system configurations into a single dated archive.

sh -c 'echo "find /backup -type f -mtime +7 -delete" >> /usr/local/bin/vps-backup.sh'

This final command automatically removes any backup files older than seven days to save disk space.

Make the new script executable.

chmod +x /usr/local/bin/vps-backup.sh

This changes the file permissions so the system is allowed to execute the script.

Test the script manually before scheduling it.

/usr/local/bin/vps-backup.sh

Running this manually verifies that the archive is created successfully without any syntax errors.

ls -lh /backup

This lists the contents of your backup folder to confirm the new compressed file exists and has a valid size.

Schedule the script to run daily using the root user crontab.

crontab -e

This command opens the scheduled tasks configuration file for the root user.

Scroll to the bottom of the file and paste the following line.

0 2 * * * /usr/local/bin/vps-backup.sh

Paste this line at the bottom of the file. It triggers the backup script automatically every day at 2:00 AM server time. Save and close the file. The system will install the new cron job automatically.

Conclusion

Your server is now fully automated. Data protection runs silently in the background. You no longer need to worry about manual snapshots. Check your backup folder occasionally. Ensure the file sizes look correct. This quick visual check confirms the system is working properly. Server management becomes much easier with the right routines. You can now focus on building your projects instead of worrying about data loss.

DN

The author

Dmitriy Novitsky

Dmitriy Novitsky, Chief Technology Officer at VPS.one, is a seasoned expert in VPS hosting. With years of experience, he shares valuable insights and technical knowledge to help users optimize their hosting performance and stay ahead in the tech world.

How to Buy a VPS with Bitcoin & Crypto

How to Buy a VPS with Bitcoin & Crypto 2026

How To Setup Pterodactyl: Step-by-Step Guide

How To Setup Pterodactyl: Step-by-Step Guide 2026

Installing SteamCMD on Linux VPS

Installing SteamCMD on Linux VPS