This project provides a productionβready Bash script that performs an automatic daily backup of a Linux directory (default: /home) using rsync.
The script is designed with system administration and security best practices, including:
- Incremental backups using
rsync - Timestamped backup directories
- Centralized logging
- Safe default behavior
- Full compatibility with
cron
- β Automatic daily backups
- β
Uses
rsync(fast and efficient) - β Timestamped backup folders
- β
Detailed logging (
backup.log) - β Prints every successful operation
- β Sensible defaults when no input is provided
- β Cronβfriendly (nonβinteractive)
If no input is provided, backups are created like this:
/home/
βββ user1
βββ user2
βββ backups/
βββ 2025-12-19_07-00-00/
βββ 2025-12-20_07-00-00/
βββ backup.log
- Linux system
- Bash shell
rsyncinstalled- Cron service enabled
Check rsync:
rsync --version1οΈβ£ Clone the repository:
git clone https://github.com/yourusername/daily-backup-script.git
cd daily-backup-script2οΈβ£ Make the script executable:
chmod +x daily_backup.sh./daily_backup.shBehavior:
- Source directory:
/home - Backup directory:
/home/backups/ - Log file:
$HOME/backup.log
- You should use sudo with commend , so you will write like it
sudo ./project_backup.sh
- or
sudo ./project_backup.sh < dir >
---
### πΉ Run with custom source and destination
```bash
./daily_backup.sh /home/username /mnt/backup
- First argument β source directory
- Second argument β backup destination
1οΈβ£ Open crontab:
crontab -e2οΈβ£ Add the following line:
0 7 * * * /full/path/to/daily_backup.shπ Important Notes:
- Always use the full path to the script
- Ensure the script has execute permission
- Cron uses a limited environment (no aliases)
3οΈβ£ Verify:
crontab -lAll operations are logged to:
$HOME/backup.logEach log entry includes:
- Timestamp
- Operation details
- Success or failure status
rsync is preferred over cp because it:
- Copies only changed files
- Preserves permissions and timestamps
- Supports mirroring with
--delete - Is ideal for backups and recovery
- Backup compression (
tar.gz) - Backup encryption (
gpg) - Email alerts on failure
- Excluding directories (
--exclude) - Remote backups over SSH
This project is released for educational and personal use. You are free to modify and extend it.
Shady Ahmed Computer Science Student | Cybersecurity Enthusiast Focus: Linux, Automation, Backup Systems, Security Engineering