Files
score-backend/deploy.sh
2026-01-08 14:30:11 +08:00

35 lines
1.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
###
# @Date: 2025-06-13 16:11:38
# @LastEditors: 陈子健
# @LastEditTime: 2025-06-23 17:24:22
# @FilePath: /my-score/honoback/deploy.sh
###
# 服务器配置
SERVER="123.57.93.143"
USER="root"
REMOTE_DIR="/home/media-backend"
# 本地构建
echo "Building project..."
bun install
# 创建远程目录
echo "Creating remote directory..."
ssh $USER@$SERVER "mkdir -p $REMOTE_DIR"
# 1. 远程备份数据库
ssh $USER@$SERVER "cp $REMOTE_DIR/db/media.db $REMOTE_DIR/db/media.db.bak 2>/dev/null || true"
# 2. 同步代码到服务器(只同步白名单内容,且排除 media.db
rsync -avz --exclude='.git/' --exclude='node_modules/' --exclude='db/media.db' \
--include='*.ts' --include='*.json' --include='*.sh' --include='*.service' \
--include='package.json' --include='package-lock.json' --include='bun.lockb' \
--include='db/' --include='db/*.ts' --include='routes/' --include='routes/*.ts' \
--exclude='*' ./ $USER@$SERVER:$REMOTE_DIR
# 在服务器上安装依赖并重启服务
echo "Installing dependencies and restarting service..."
ssh $USER@$SERVER "cd $REMOTE_DIR && bun install && systemctl restart my-score"