498bb3a3c8
- Move CI/CD configs to config/ci/ directory - Reorganize scripts into categorized directories (deployment, monitoring, testing, utils) - Consolidate documentation into docs/ directory with proper structure - Update linting and testing configurations - Remove obsolete test reports and performance summaries - Add new documentation for code quality tools and contact form security - Improve project organization and maintainability - Fix lint-staged config to only lint JS/TS files - Disable react/react-in-jsx-scope rule for Next.js compatibility - Ignore scripts and test config directories in ESLint
54 lines
1.2 KiB
Bash
Executable File
54 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# 备份脚本
|
|
# 用法: ./scripts/backup.sh
|
|
|
|
set -e
|
|
|
|
BACKUP_DIR="./backups"
|
|
DATE=$(date +%Y%m%d_%H%M%S)
|
|
BACKUP_NAME="backup_$DATE"
|
|
|
|
# 创建备份目录
|
|
mkdir -p "$BACKUP_DIR/$BACKUP_NAME"
|
|
|
|
echo "开始备份..."
|
|
|
|
# 备份数据库
|
|
if [ -f "./data/prod.db" ]; then
|
|
echo "备份数据库..."
|
|
cp ./data/prod.db "$BACKUP_DIR/$BACKUP_NAME/database.db"
|
|
else
|
|
echo "警告: 数据库文件不存在"
|
|
fi
|
|
|
|
# 备份上传文件
|
|
if [ -d "./uploads" ]; then
|
|
echo "备份上传文件..."
|
|
cp -r ./uploads "$BACKUP_DIR/$BACKUP_NAME/uploads"
|
|
else
|
|
echo "警告: uploads目录不存在"
|
|
fi
|
|
|
|
# 备份配置
|
|
if [ -f ".env.production" ]; then
|
|
echo "备份配置..."
|
|
cp .env.production "$BACKUP_DIR/$BACKUP_NAME/.env.production"
|
|
else
|
|
echo "警告: .env.production文件不存在"
|
|
fi
|
|
|
|
# 压缩备份
|
|
echo "压缩备份..."
|
|
tar -czf "$BACKUP_DIR/$BACKUP_NAME.tar.gz" -C "$BACKUP_DIR" "$BACKUP_NAME"
|
|
|
|
# 删除临时目录
|
|
rm -rf "$BACKUP_DIR/$BACKUP_NAME"
|
|
|
|
# 保留最近7天的备份
|
|
echo "清理旧备份..."
|
|
find "$BACKUP_DIR" -name "backup_*.tar.gz" -mtime +7 -delete
|
|
|
|
echo "备份完成: $BACKUP_DIR/$BACKUP_NAME.tar.gz"
|
|
echo "备份大小: $(du -h "$BACKUP_DIR/$BACKUP_NAME.tar.gz" | cut -f1)"
|