This is a simple yet robust backup automation script written in Bash, designed to run on Linux systems. It was created as a foundational project to practice Linux system administration and automation skills for a DevOps/Cloud engineering path.
This script performs two primary functions:
- Automated Backup: It compresses a specified source directory (
tar) and saves it to a target directory with a unique, timestamped filename (backup-YYYY-MM-DD.tar.gz). - Log Rotation: It automatically cleans up the target directory by deleting any backups older than 7 days, preventing disk space from filling up.
All actions (backup success, cleanup, errors) are logged with a timestamp to an external backup.log file for easy monitoring.
-
Make the script executable:
chmod +x backup.sh
-
Run the script by providing the source and target directories as arguments:
./backup.sh /path/to/source_directory /path/to/backup_destination
Example:
./backup.sh /home/ilhan/Documents /mnt/external_drive/backups
- Bash Scripting (Variables, Parameters, Functions,
ifconditions) - Linux Core Utilities:
date,echo,tar(for compression) - File System:
find(for locating files by time-mtimeand deleting-delete) - I/O Redirection:
>>(for logging)