Introduction:
This script automates the process of backing up important files by compressing a directory into a timestamped archive.
Code Snippet:
Instructions:
Use the script by specifying the source and backup directories, as shown below:
Example Output:
This script automates the process of backing up important files by compressing a directory into a timestamped archive.
Code Snippet:
Bash:
#!/bin/bash
# Automated Backup Script
SOURCE_DIR="$1"
BACKUP_DIR="$2"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
if [ -z "$SOURCE_DIR" ] || [ -z "$BACKUP_DIR" ]; then
echo "Usage: $0 <source_directory> <backup_directory>"
exit 1
fi
tar -czf "$BACKUP_DIR/backup_$TIMESTAMP.tar.gz" "$SOURCE_DIR"
echo "Backup created at $BACKUP_DIR/backup_$TIMESTAMP.tar.gz"
Instructions:
Use the script by specifying the source and backup directories, as shown below:
Code:
chmod +x backup.sh
./backup.sh /home/user/data /home/user/backup
Example Output:
Code:
Backup created at /home/user/backup/backup_20231010_153000.tar.gz