-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchive-code
More file actions
34 lines (25 loc) · 774 Bytes
/
Copy patharchive-code
File metadata and controls
34 lines (25 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Check if log directory argument is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <log-directory>"
exit 1
fi
LOG_DIR="$1"
# Verify directory exists
if [ ! -d "$LOG_DIR" ]; then
echo "Error: Directory '$LOG_DIR' does not exist."
exit 1
fi
# Create archive directory
ARCHIVE_DIR="./archives"
mkdir -p "$ARCHIVE_DIR"
# Generate timestamp
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
# Archive filename
ARCHIVE_NAME="logs_archive_${TIMESTAMP}.tar.gz"
# Create compressed archive
tar -czf "$ARCHIVE_DIR/$ARCHIVE_NAME" -C "$(dirname "$LOG_DIR")" "$(basename "$LOG_DIR")"
# Log archive creation
echo "$(date '+%Y-%m-%d %H:%M:%S') - $ARCHIVE_NAME" >> "$ARCHIVE_DIR/archive_log.txt"
echo "Archive created successfully:"
echo "$ARCHIVE_DIR/$ARCHIVE_NAME"