Skip to content

Instantly share code, notes, and snippets.

@gb-swatanabe
Created May 1, 2015 10:29
Show Gist options
  • Save gb-swatanabe/7026eae9e8a213a587e5 to your computer and use it in GitHub Desktop.
Save gb-swatanabe/7026eae9e8a213a587e5 to your computer and use it in GitHub Desktop.
RedmineのWikiをまるごとdumpし保存
#!/bin/bash
# usage: $0 <outdir>
Mysql_cmd='/usr/bin/mysql -Ns' # user/passは~/.my.cnfに
Mysql_db='redmine'
outdir=$1
mkdir -p $outdir
# プロジェクトIDとWiki IDを取得
for widpid in $( $Mysql_cmd -D $Mysql_db -e "SELECT id,project_id FROM wikis" | sed -e 's/ /,/' )
do
wid=$( echo $widpid | awk -F, '{print $1}' )
pid=$( echo $widpid | awk -F, '{print $2}' )
# プロジェクトIDからプロジェクト名を取得、保存用ディレクトリを作成
pname=$( $Mysql_cmd -D $Mysql_db -e "SELECT name FROM projects WHERE id = ${pid}" | sed -e 's/[ |;/:]/_/g' )
dir="${outdir}/${pid}_${pname}"
mkdir -p $dir
# プロジェクトWikiの基本情報を取得
$Mysql_cmd -D $Mysql_db --column-names -e "SELECT name,description,is_public,created_on,updated_on,start_page FROM projects JOIN wikis ON projects.id = wikis.project_id WHERE projects.id = ${pid} \G" > $dir/README
# 各Wikiページを取得
for idtitle in $( $Mysql_cmd -D $Mysql_db -e "SELECT id,title FROM wiki_pages WHERE wiki_id = ${wid}" | sed -e 's/ /,/' )
do
id=$( echo $idtitle | awk -F, '{print $1}' )
title="${id}_$( echo $idtitle | awk -F, '{print $2}' )"
echo "$dir/$title"
$Mysql_cmd -D $Mysql_db -e "SELECT text FROM wiki_contents WHERE id = ${id}" |
perl -pe 's/\r\\n/\n/g' > $dir/$title.md
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment