윈도우 백업스크립트작성 미완

2010. 1. 7. 17:5199. 정리전 - IT/29. IT 잡동지식

윈도우 커맨드에서 사용 가능한것들

%CD% - expands to the current directory string.

%DATE% - expands to current date using same format as DATE command.

%TIME% - expands to current time using same format as TIME command.

%RANDOM% - expands to a random decimal number between 0 and 32767.

%ERRORLEVEL% - expands to the current ERRORLEVEL value

%CMDEXTVERSION% - expands to the current Command Processor Extensions version number.

%CMDCMDLINE% - expands to the original command line that invoked the Command Processor.

//참고url
http://en.wikipedia.org/wiki/Environment_variable

//데이터베이스 백업 bacth file (적용 안해봄)
@echo off
SET fileDir=c:\머시기\
SET fileName=%DATE%_디비이름
SET sqlFile=%fileDir%%fileName%

pg_dump -d doumdb -f %sqlFile%
7z.exe a -t7z "%fileDir%%fileName%.zip" %sqlFile%
7z으로 archive한다, 7z으로 이파일이름으로, 이파일을

=======================================================
@echo off
SET fileDir=D:\workspace\
SET dbName=doumdb
SET YEAR=%DATE:~0,4%
SET MONTH=%DATE:~5,2%
SET DAY=%DATE:~8,2%
SET MYDATE=%YEAR%_%MONTH%_%DAY%

SET fileName=%dbName%_%MYDATE%
SET sqlFile=%fileDir%%fileName%.sql

@echo db dump
pg_dump -d %dbName% -f %sqlFile% -U postgres

@echo archiving sql file
"C:\Program Files\7-Zip\7z.exe" a -t7z "%fileDir%%fileName%.7z" "%sqlFile%"

@echo delete sql file
del %sqlFile%

완성본