Posted at

redmineのdbをlinuxからwindowsサーバにバックアップ

More than 1 year has passed since last update.


redmineのdbをバックアップ


mysql_backup.sh

#!/bin/sh

dumpfile=/tmp/redmine_`date "+%Y%m%d%H%M"`.dump

find /tmp -mtime +14 -name '*_*.dump' -exec rm -f {} \; >/dev/null 2>&1
mysqldump --defaults-extra-file=/etc/redmine_my.cnf --single-transaction redmine > $dumpfile

exit 0



取得したdumpをwindowsサーバにアップロード


send_file_srv.bat

set DATE_NOW=%date:~0,4%%date:~5,2%%date:~8,2%

set TARGET_DIR=\\Foo\hoge\redmine\%DATE_NOW%
mkdir %TARGET_DIR%

cd "%~dp0%"
start "send_dump"
cscript send_file_srv.vbs

timeout 5
cp *.dump %TARGET_DIR%
del *.dump

pause



send_file_srv.vbs

set WshShell = WScript.CreateObject("WScript.Shell")

strScpCmd = "scp -P 4400 foo@hoge:/tmp/redmine_"+ Replace(Left(Now(),10), "/", "")+"*dump .~"
WshShell.AppActivate "send_dump"
WshShell.SendKeys strScpCmd
WScript.Sleep 10000
WshShell.SendKeys "PASSWORD~"
WScript.Sleep 1000
WshShell.SendKeys "exit~"