← Volver al blog

How to Set Up a Backup Script with tar

  • Xernode
  • 1 min de lectura
  • 12 de abril de 2026
VPS backup linux vps automation tar script

Introduction

Automated backups are essential for data safety. This guide shows you how to create a simple backup script using tar on your Linux VPS.

Step-by-step Guide

  1. Create a backup script file
    • ano ~/backup.sh
  2. Add the following script (replace /source/folder and /backup/folder as needed):
    • #!/bin/bash
    • DATE=$(date +%F)
    • tar -czvf /backup/folder/backup-$DATE.tar.gz /source/folder
  3. Save and close the file.
  4. Make the script executable
    • chmod +x ~/backup.sh
  5. Run the script manually
    • ~/backup.sh
  6. (Optional) Schedule daily backups with cron
    • crontab -e
    • Add this line to run the backup every day at 2 AM:n
      • 0 2 * * * /home/youruser/backup.sh

Recommendations

  • Store backups on a separate disk or remote server for extra safety.
  • Regularly test your backups by restoring files.
  • Clean up old backups to save space.

Call To Action

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

Related Guides