Back to tools
How to use the backup script
- Generate the script using the form above
- Download or copy the script
- Save it on your server:
sudo nano /usr/local/bin/backup.sh - Make it executable:
sudo chmod +x /usr/local/bin/backup.sh - Test it:
sudo /usr/local/bin/backup.sh - Schedule it in crontab:
sudo crontab -eand add0 2 * * * /usr/local/bin/backup.sh
Requirements
- Linux/Unix with Bash 4+
- tar, gzip/bzip2/xz (depending on chosen compression)
- rsync (if using incremental sync)
- mailutils (for email notifications)
Frequently Asked Questions
What does a professional backup script include?
A professional backup script includes: compression with tar and gzip/bzip2/xz, automatic rotation of old backups, email notifications to the administrator, detailed execution logs, and optionally incremental synchronization with rsync to a remote server.
How often should I back up my server?
For production servers the recommendation is: daily full backups with 7-30 day retention, weekly backups with 3-month retention, and monthly backups with 1-year retention. The frequency depends on data volume and service criticality.
Where should I store the backups?
Follow the 3-2-1 rule: 3 copies of your data, on 2 different storage types, with 1 copy off-site. Example: a local copy on the server, a copy on an external disk or NAS, and a copy in the cloud (S3, rsync.net, Backblaze).
How do I test the backup script before using it in production?
To safely test your backup script: 1) Run it manually with "sudo /usr/local/bin/backup.sh" from a terminal. 2) Verify compressed files are created in the destination directory. 3) Check logs in /var/log/backup/ to confirm no errors. 4) Restore a test file to a temporary directory with "tar -xzf backup.tar.gz -C /tmp/test-restore". 5) Simulate execution with "bash -x backup.sh" to see every step in detail.
How do I restore data from a backup?
To restore from a backup: if using the tar-based script, navigate to the backup directory and run "tar -xzf backup_YYYYMMDD_HHMMSS.tar.gz -C /restore/path". To restore specific files use "tar -xzf backup.tar.gz --wildcards 'specific/path/*'". If you used rsync for remote sync, reverse the command: "rsync -avz user@server:/backup/path/ /restore/path/". Always restore to a temporary directory first to verify integrity before overwriting original data.
What is the 3-2-1 backup rule and why is it important?
The 3-2-1 rule is the industry standard for data protection: 3 copies of your data (1 original + 2 backups), stored on 2 different media types (e.g., local disk + cloud storage), with 1 copy off-site to protect against physical disasters like fire, theft, or flood. This strategy ensures that even if two systems fail simultaneously, you can still recover your data.
What is the difference between full and incremental backup?
A full backup copies all selected data regardless of whether it has changed or not. It takes more space and time, but restoration is faster since you only need one file. An incremental backup only copies data that has changed since the last backup (full or incremental). It takes less space and runs faster, but restoration requires processing the entire chain of incrementals in order.
Backup types: full vs incremental vs differential
| Feature | Full | Incremental | Differential |
|---|---|---|---|
| Data copied | All data | Changes since last backup | Changes since last full |
| Speed | Slow | Very fast | Moderate |
| Storage | High | Low | Medium (grows) |
| Restore | Fast (1 file) | Slow (chain) | Medium (2 files) |
| Frequency | Weekly | Daily | Daily |
Related Tools
Regex Tester
Test regular expressions in real time with predefined patterns for IP, email and more
Downtime Calculator
Calculate availability percentage based on downtime
CRON Visualizer
Interactive visual timeline for CRON expressions
Deployment Simulator
Visualize strategies: Rolling Update, Blue-Green and Canary