← Volver al blog

How to Set Up Automatic Backups in Linux

  • Xernode
  • 1 min de lectura
  • 31 de marzo de 2026
Backups backup cron linux automation server

Introduction

Automatic backups are essential to protect your data from accidental loss or server failure. This guide shows you how to set up scheduled backups in Linux using cron and simple scripts.

Step-by-step Guide

  1. Create a backup script
    Create a file named backup.sh with the following content:n
    • #!/bin/bash
    • tar -czf /home/backup/www-$(date +\%F).tar.gz /var/wwwn
      • Make it executable:n
        • chmod +x backup.sh
  2. Test your script manually
    Run the script to verify it works: n
    • ./backup.shn
      • Check the backup file:n
        • ls -lh /home/backup/
  3. Edit your crontab to schedule the backup
    Open the crontab editor:n
    • crontab -en
      • Add this line to run the backup every day at 2:00 AM:n
        • 0 2 * * * /ruta/completa/a/backup.sh
  4. (Optional) Automate backup cleanup
    Add this line to your script to delete backups older than 7 days:n
    • find /home/backup -type f -mtime +7 -name "*.tar.gz" -delete
  5. (Optional) Send backups to a remote server
    Add this line to your script to copy the backup to another server:n
    • scp /home/backup/www-$(date +\%F).tar.gz user@remote_ip:/remote/backup/path/

Recommendations

  • Store backups on a separate disk or remote server for extra safety.
  • Regularly test your backups by restoring files.
  • Monitor disk space to avoid failed backups.

Call To Action

eed reliable storage for your backups? Check out our VPS plans! https://xernode.com/#pricing

Related Guides