posimai-root/scripts/export-article.sh

27 lines
886 B
Bash

#!/bin/bash
# Brain記事エクスポートスクリプト (Git Bash用)
if [ -z "$1" ]; then
echo "使用方法: ./export-article.sh <記事ID>"
echo "例: ./export-article.sh 78"
exit 1
fi
ARTICLE_ID=$1
OUTPUT_FILE="article-${ARTICLE_ID}.md"
echo "📥 記事ID ${ARTICLE_ID} をエクスポート中..."
# SSHでPostgreSQLから取得して、\nを実際の改行に変換
ssh mai@100.76.7.3 "/usr/local/bin/docker exec gitea_db psql -U gitea -d posimai_brain -t -A -c 'SELECT full_text FROM articles WHERE id=${ARTICLE_ID}'" | sed 's/\\n/\n/g' > "${OUTPUT_FILE}"
if [ $? -eq 0 ] && [ -s "${OUTPUT_FILE}" ]; then
FILE_SIZE=$(du -h "${OUTPUT_FILE}" | cut -f1)
echo "✅ 保存完了: ${OUTPUT_FILE}"
echo " ファイルサイズ: ${FILE_SIZE}"
else
echo "❌ エラー: 記事の取得に失敗しました"
rm -f "${OUTPUT_FILE}"
exit 1
fi