website-scripts/backup-db.sh

29 lines
837 B
Bash
Executable File
Raw 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
# 云端数据库一键备份脚本
# 用法bash backup-db.sh
set -e
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
LOCAL_DIR="/Users/niuniu/programs/docker/db-backups"
log() { echo "[$(date '+%H:%M:%S')] $1"; }
log "开始备份云端数据库..."
# 云端打包
ssh txjp "mkdir -p /tmp/db-backup && \
cp /root/docker/assets-ai/data/assets.db /tmp/db-backup/assets-${TIMESTAMP}.db && \
cp /root/docker/issue-ai/data/issue.db /tmp/db-backup/issue-${TIMESTAMP}.db"
# 复制到本地
log "复制到本地..."
scp "txjp:/tmp/db-backup/assets-${TIMESTAMP}.db" "${LOCAL_DIR}/"
scp "txjp:/tmp/db-backup/issue-${TIMESTAMP}.db" "${LOCAL_DIR}/"
# 清理云端临时文件
ssh txjp "rm -rf /tmp/db-backup"
log "备份完成:${TIMESTAMP}"
ls -lh "${LOCAL_DIR}"/assets-${TIMESTAMP}.db "${LOCAL_DIR}"/issue-${TIMESTAMP}.db 2>/dev/null