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