Skip to content

shadyProg/BackUp_script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation


πŸ—‚οΈ Automatic Daily Home Directory Backup (Bash + rsync + cron)

πŸ“Œ Overview

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

✨ Features

  • βœ… 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)

πŸ“ Backup Structure

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

πŸ›  Requirements

  • Linux system
  • Bash shell
  • rsync installed
  • Cron service enabled

Check rsync:

rsync --version

πŸ“₯ Installation

1️⃣ Clone the repository:

git clone https://github.com/yourusername/daily-backup-script.git
cd daily-backup-script

2️⃣ Make the script executable:

chmod +x daily_backup.sh

▢️ Usage

πŸ”Ή Run with default settings

./daily_backup.sh

Behavior:

  • Source directory: /home
  • Backup directory: /home/backups/
  • Log file: $HOME/backup.log

🧾 Notes

  • 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

⏰ Automating with Cron (Daily at 7:00 AM)

1️⃣ Open crontab:

crontab -e

2️⃣ 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 -l

🧾 Logs

All operations are logged to:

$HOME/backup.log

Each log entry includes:

  • Timestamp
  • Operation details
  • Success or failure status

πŸ” Why rsync?

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

πŸš€ Possible Enhancements

  • Backup compression (tar.gz)
  • Backup encryption (gpg)
  • Email alerts on failure
  • Excluding directories (--exclude)
  • Remote backups over SSH

πŸ“„ License

This project is released for educational and personal use. You are free to modify and extend it.


πŸ‘€ Author

Shady Ahmed Computer Science Student | Cybersecurity Enthusiast Focus: Linux, Automation, Backup Systems, Security Engineering


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages