REM INIT→既に指定したファイルが有った場合, 上書きする
REM NORECOVERY→接続先データベースへの既存の接続を閉じる
REM REPLACE→既存のデータベースを上書きする
set BkupPath={path1}
sqlcmd -S (local)\{SERVICENAME} -U {user} -P {password} -Q "BACKUP DATABASE {DBNAME} TO DISK=‘%BkupPath%\{backfilename}.bak‘ WITH INIT, NORECOVERY, REPLACE" > %BkupPath%\backup.log
pause
set BkupPath={path1}
set DBPath={path2}
sqlcmd -S (local)\{SERVICENAME} -Q "RESTORE DATABASE {DBNAME} FROM DISK = N‘%BkupPath%\{backfilename}.bak‘ WITH RECOVERY, MOVE ‘{MDFNAME}_Data‘ TO N‘%DBPath%\{MDFNAME}_Data.mdf‘, MOVE ‘{LOGNAME}_Log‘ TO N‘%DBPath%\{LOGNAME}_Log.ldf‘" > %BkupPath%\restore.log
pause