This project demonstrates the use of Bash scripting to automate file backups based on modification time. It was completed as the final project for Course 6 – Hands-on Introduction to Linux Commands and Shell Scripting in the IBM Data Engineering Professional Certificate.
The project simulates a real-world DevOps or system administration task: creating a shell script (backup.sh) that identifies recently modified files and backs them up into a timestamped archive. The script uses core Linux utilities including tar, date, mv, and file permission commands, and is designed to support automation via cron.
- Create a Bash script that:
- Accepts source and destination directories as arguments
- Finds files modified within the last 24 hours
- Archives them into a compressed
.tar.gzfile - Moves the archive to the destination folder
- Validate argument count and paths
- Use timestamps to generate unique backup filenames
- Automate the backup using
crontab
| Category | Tools/Technologies |
|---|---|
| OS Environment | Ubuntu Linux (Skills Network Lab) |
| Shell Language | Bash |
| Utilities Used | tar, date, mv, chmod, cron |
| Execution Environment | Terminal / Theia IDE |
The main Bash script that:
- Verifies correct usage and valid input directories
- Identifies files modified in the last 24 hours
- Creates a compressed archive (
.tar.gz) with a unique timestamped name - Moves the archive to the specified backup directory
- Can be scheduled via
crontabfor automation
Sample script execution showing successful backup of recently modified files:
# Script Output
the first argument is important-documents
the second argument is .
ana.txt
doi.txt
zop.txt
Backup successful: /home/project/backup-1718832747.tar.gz
# Backup Directory Contents (filtered to show only backup output)
-rw-r--r-- 1 theia users 4423 Jun 19 17:32 backup-1718832747.tar.gz
| Task | Screenshot |
|---|---|
| Script made executable | task15_executable.png |
| Backup archive created | task16_backup_complete.png |
crontab scheduled for automation |
task17_crontab.png |
Linux_Shell_Backup_Project/
├── README.md # Project overview and usage instructions (this file)
├── backup.sh # Main backup script written in Bash
├── crontab_entry.txt # cron entry to automate backup execution
├── data/ # Input data files (used for test backup)
│ ├── ana.txt
│ ├── doi.txt
│ └── zop.txt
├── output/
│ └── output_log.txt # Sample script execution log
├── images/
│ ├── task15_executable.png # Screenshot: script made executable
│ ├── task16_backup_complete.png # Screenshot: successful backup archive
│ └── task17_crontab.png # Screenshot: crontab entry for automation
-
Make the script executable (if not already):
chmod +x backup.sh
-
Create an output folder (if it doesn’t exist):
mkdir backup-folder
-
Run the backup script using the existing
data/folder as input:./backup.sh data backup-folder
-
If successful, a compressed backup archive (e.g.,
backup-<timestamp>.tar.gz) will appear inside thebackup-folder/directory.
Note:
In the original screenshots and output log, the input folder was namedimportant-documentsas instructed in the course task.
For this repository, the input folder is nameddata/, but the script logic remains the same.
To schedule the backup script to run automatically at a fixed time, you can set up a cron job.
For example, to run the backup daily at midnight, add the following entry to your crontab:
0 0 * * * /usr/local/bin/backup.sh /home/project/important-documents /home/projectFor convenience, this cron entry is also saved in crontab_entry.txt.
To edit your crontab:
crontab -eNote:
This path (/usr/local/bin/backup.sh) reflects the script's location in the original IBM Skills Network environment. On your local system, you may need to adjust the full path to the script and input/output folders accordingly.
Tip for Local Testing:
If you're running this project locally (not in the IBM Cloud IDE), you can use acronjob like the following:0 0 * * * /full/path/to/Linux_Shell_Backup_Project/backup.sh /full/path/to/Linux_Shell_Backup_Project/data /full/path/to/Linux_Shell_Backup_Project/outputBe sure to replace
/full/path/to/with the absolute path to your project directory.
This project was completed as part of the IBM Data Engineering Professional Certificate and is intended for educational use.