fix: backup monitoring and PATH environment issues

- Fix backup_monitor.sh find command to sort by modification time
- Fix grep -oP syntax error (change to grep -oE)
- Adjust tier rotation threshold from -mtime +7 to +6
- Add backup_all.sh script with PATH fixes for crontab
- Add mysql-client/bin to PATH for mysqldump command
- Fix backup status check for v2 naming patterns
This commit is contained in:
Warren
2026-03-30 04:11:02 +08:00
parent 2393d81a3f
commit 95b44f1e55
2 changed files with 824 additions and 3 deletions

View File

@@ -92,7 +92,7 @@ check_backup_status() {
if [ -d "$service_backup_dir" ]; then
file_count=$(find "$service_backup_dir" -type f 2>/dev/null | wc -l)
size=$(du -sb "$service_backup_dir" 2>/dev/null | cut -f1)
latest_file=$(find "$service_backup_dir" -type f \( -name "*.tar.gz" -o -name "*.sql.gz" -o -name "*.rdb" \) 2>/dev/null | head -1)
latest_file=$(find "$service_backup_dir" -type f \( -name "*.tar.gz" -o -name "*.sql.gz" -o -name "*.rdb" \) -printf "%T@ %p\n" 2>/dev/null | sort -rn | head -1 | cut -d' ' -f2-)
# 處理 size 為空或 0 的情況
if [ -z "$size" ] || [ "$size" = "0" ]; then
@@ -271,12 +271,12 @@ tier_backups() {
# 7天前: daily -> weekly
# 命名格式: {service}_{type}_{YYYYMMDD}_{HHMMSS}.{ext}
find "$BACKUP_BASE/daily" -type f -mtime +7 | while read -r file; do
find "$BACKUP_BASE/daily" -type f -mtime +6 | while read -r file; do
service=$(basename "$(dirname "$file")")
# 解析時間戳
filename=$(basename "$file")
timestamp=$(echo "$filename" | grep -oP '\d{8}_\d{6}' || echo "")
timestamp=$(echo "$filename" | grep -oE '[0-9]{8}_[0-9]{6}' || echo "")
if [ -n "$timestamp" ]; then
year=${timestamp:0:4}