-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


[ ] Windows-

, 18 2017 . 15:48 +
urfinejuse 15:48

Windows-

, ( ), , UNIX-way.
7za.exe (a = alone ()) 7-Zip, , UNIX-like pdate.exe, , *NIX, bash BAT. .


, .exe . , - , . , , , , , , , .

, , ( ) Windows Server 2003 SP2 x64. , , , Windows . -, , cold-data (, ) . -, , , . , ( ), , .

, , . , , , -, , -.

, fsbackup www.opennet.ru/dev/fsbackup , , (tar). , *NIX / Linux. Google Windows. , antip0d . .


, . 16.04. 7z : , / , 7z 10-20 !

:
7za.exe 7-Zip.
7za.dll 7z
7zxa.dll 7z .
64- x64.
, pdate ,
pdate v1.1 build 2007.12.06
© 2005-2007 Pavel Malakhov 24pm@mail.ru
pdate , .
pm4u.opennet.ru/mysoft/pdate.htm
, , .

:
D:\winfsbackup
D:\winfsbackup\7z 7za
D:\winfsbackup\backup ( , )
D:\winfsbackup\lists .
D:\winfsbackup\log
D:\winfsbackup\pdate
D:\winfsbackup\tmp
D:\winfsbackup\winfsbackup.bat .


:Main, , . , , backup \backup\old, .
, + ~250 . 550 ( 55 ). , , ( chkdsk), , -.

:Main
REM   ,       \  ,    .

REM   -       
IF NOT EXIST %baseArch% GOTO BaseArchive

REM     + t   
IF %dm% EQU 1 GOTO BaseArchive ELSE GOTO UpdateArchive

REM     1  
REM IF %dm% EQU 1 GOTO UpdateBase ELSE GOTO UpdateArchive

REM    (2, 19, 36  )
REM IF NOT %wn%.%dw% EQU 02.5 GOTO UpdateArchive
REM IF NOT %wn%.%dw% EQU 19.5 GOTO UpdateArchive
REM IF NOT %wn%.%dw% EQU 36.5 GOTO UpdateArchive

REM   ,  
REM IF %dw% EQU 6 (GOTO UpdateBase) ELSE (GOTO UpdateArchive)

REM     ,       .
REM     
ECHO Warning! No one condition matching, check :Main block of script >> %Log%
GOTO End

2 -, + . , , .


dm, dw, wn , ( ).
verboseLevel , , , . , .
tmpDir . , 7-Zip , . , , . , , ; .


, , , . , . 7z.

( ) . ( ) , , .


-bsp2 STDERR. STDOUT 7z , , , . STDERR, .

-ssw , . , 7-Zip .

-slp . . , , 7-Zip . 7-Zip , . , , 7-Zip . Windows 2003 / XP x64. . 3 . -slp, Windows , 7-Zip . Windows 7-Zip, Windows . , , , , 7-Zip . -slp, , . , -slp ( 100 ). (300 ) LZMA , 5% -10% -slp.
-mmt=on . / , . 7-Zip LZMA/LZMA2 / BZip2.

-ms=off solid-. , , , , , . Non-solid , .

Include / exclude
2 / (include_general.txt), 2 (exclude_general.txt, exclude_regexp.txt).

UNC-. , / , .

, E:\foo\bar, E:\foo\bar\somefolder, exclude_general.txt bar\somefolder bar\somefolder\

, .
exclude_regexp.txt regexp , . * ,? .
7-Zip , 7 Zip '*', '*.*' , .

, :

@ ECHO OFF
REM Sources were found on http://sysadminwiki.ru/wiki/___Windows
CD %~dp0
TITLE winfsbackup
MODE CON: COLS=120 LINES=55
ECHO Setting vars...
REM --- Definition block ---
SET verboseLevel=1
SET tmpDir=D:\winfsbackup\tmp
SET run_7z=D:\winfsbackup\7z\7za.exe
SET run_pdate=D:\winfsbackup\pdate\pdate.exe
FOR /F "usebackq" %%a IN (`%run_pdate% e`) DO (SET dm=%%a)
FOR /F "usebackq" %%a IN (`%run_pdate% u`) DO (SET dw=%%a)
FOR /F "usebackq" %%a IN (`%run_pdate% V`) DO (SET wn=%%a)
SET LogDir=D:\winfsbackup\log
SET Log=%LogDir%\general.log
SET dDir=D:\winfsbackup\backup
SET dlmDir=D:\winfsbackup\backup\old
SET baseArch=%dDir%\general.7z
SET IncludeList=lists\include_general.txt
SET ExcludeList=lists\exclude_general.txt
SET ExcludeRegexp=lists\exclude_regexp.txt
SET updArch_dw=%dDir%\day_general_%dw%.7z
SET updArch_wn=%dDir%\week_general_%wn%.7z

IF %verboseLevel%==0 GOTO Main
ECHO Verbose mode ON!
ECHO Today is %wn% week of year, %dw% day of week.
ECHO Full quarter backup will execute (if enabled) on 2, 19 and 36 week, friday.
ECHO Temporary directory is %tmpDir%
ECHO Now logging into %Log%
ECHO Current backup directory is %dDir%, older backups stored into %dlmDir%

:Main
REM Here discribed conditions - in which case script will make new backup, update older one, etc
REM You are free to change these conditions
REM Make sure you envisaged all possible cases
REM Actions here are not disigned to be active more than 1 at same time, excluding base condition
REM If you want multiple conditions, you should edit it

REM Base condition - full backup will be created if it is not exist
IF NOT EXIST %baseArch% GOTO BaseArchive

REM Command below turns on making full backup at 1'st day of every month, in other days - increments
REM IF %dm% EQU 1 GOTO BaseArchive ELSE GOTO UpdateArchive

REM This option enables updating full backup every month
IF %dm% EQU 1 GOTO UpdateBase ELSE GOTO UpdateArchive

REM Uncomment these 3 commands if you want to run full backup ~every quarter (2, 19, 36 week of year)
REM IF NOT %wn%.%dw% EQU 02.5 GOTO UpdateArchive
REM IF NOT %wn%.%dw% EQU 19.5 GOTO UpdateArchive
REM IF NOT %wn%.%dw% EQU 36.5 GOTO UpdateArchive

REM This option enables rewriting base archive every saturday with new files in order to decrease size of increments
REM IF %dw% EQU 6 (GOTO UpdateBase) ELSE (GOTO UpdateArchive)

REM Here you can place default action if conditions of previous ones were not executed.
%run_pdate% "Z --- \A\c\t\i\o\n \w\a\s\ \n\o\t \s\e\l\e\c\t\e\d\! >> %Log%
ECHO Warning! No one condition matching, check :Main block of script
GOTO End

:BaseArchive
ECHO Clear %dlmDir% and move data of previous month to that dir...
IF NOT EXIST %dlmDir%\nul MKDIR %dlmDir%
DEL /Q %dlmDir%\*
MOVE /Y %dDir%\* %dlmDir% 2> nul

%run_pdate% "====== Y B =======" > %Log%
%run_pdate% "Z --- \S\t\a\r\t \t\o \c\r\e\a\t\e \n\e\w \a\r\c\h\i\v\e" >> %Log%

ECHO Creating new backup %baseArch%
%run_7z% a %baseArch% -w%tmpDir% -i@%IncludeList% -x@%ExcludeList% -xr@%ExcludeRegexp% -bsp2 -ssw -slp -scsWIN -mmt=on -mx3 -ms=off >> %Log%
IF %ERRORLEVEL%==0 (
	%run_pdate% "Z --- \E\x\i\t \c\o\d\e \0 \- \a\r\c\h\i\v\e \s\u\c\c\e\s\s\f\u\l\l\y \c\r\e\a\t\e\d!" >> %Log%
	) ELSE (
		IF %ERRORLEVEL%==1 (
		%run_pdate% "Z --- \W\a\r\n\i\n\g\! \R\e\c\i\e\v\e\d\ \e\x\i\t \c\o\d\e \1" >> %Log%
			) ELSE (
				IF %ERRORLEVEL%==2 (
				%run_pdate% "Z --- \E\x\i\t \c\o\d\e \2 \- \F\A\T\A\L \E\R\R\O\R\!" >> %Log%
				) ELSE (
					IF %ERRORLEVEL%==7 (
					%run_pdate% "Z --- \E\x\i\t \c\o\d\e \7 \- \C\o\m\m\a\n\d \p\r\o\m\p\t \e\r\r\o\r!" >> %Log%
					) ELSE (
						IF %ERRORLEVEL%==8 (
						%run_pdate% "Z --- \E\x\i\t \c\o\d\e \8 \- \N\o\t \e\n\o\u\g\h \m\e\m\o\r\y" >> %Log%
						) ELSE (
							ECHO Recieved error 255 - user stopped running process or exit code unknown! >> %Log%
						)
					)
				)
			)
		)
	)
)
GOTO End

:UpdateBase
ECHO Refreshing base archive
ECHO ******* ******* *******  >> %Log%
%run_pdate% "Z --- \S\t\a\r\t \t\o \u\p\d\a\t\e \a\r\c\h\i\v\e" >> %Log%
%run_7z% u %baseArch% -up0q1r2x1y2z1w0 -w%tmpDir% -i@%IncludeList% -x@%ExcludeList% -xr@%ExcludeRegexp% -bsp2 -ssw -slp -scsWIN -mmt=on -mx5 -ms=off >> %Log%
IF %ERRORLEVEL%==0 (
	%run_pdate% "Z --- \E\x\i\t \c\o\d\e \0 \- \u\p\d\a\t\e \s\u\c\c\e\s\s\f\u\l\l\y \f\i\n\i\s\h\e\d" >> %Log%
	) ELSE (
		IF %ERRORLEVEL%==1 (
		%run_pdate% "Z --- \W\a\r\n\i\n\g\! \R\e\c\i\e\v\e\d\ \e\x\i\t \c\o\d\e \1" >> %Log%
			) ELSE (
				IF %ERRORLEVEL%==2 (
				%run_pdate% "Z --- \E\x\i\t \c\o\d\e \2 \- \F\A\T\A\L \E\R\R\O\R\!" >> %Log%
				) ELSE (
					IF %ERRORLEVEL%==7 (
					%run_pdate% "Z --- \E\x\i\t \c\o\d\e \7 \- \C\o\m\m\a\n\d \p\r\o\m\p\t \e\r\r\o\r!" >> %Log%
					) ELSE (
						IF %ERRORLEVEL%==8 (
						%run_pdate% "Z --- \E\x\i\t \c\o\d\e \8 \- \N\o\t \e\n\o\u\g\h \m\e\m\o\r\y" >> %Log%
						) ELSE (
							ECHO Recieved error 255 - user stopped running process or exit code unknown! >> %Log%
						)
					)
				)
			)
		)
	)
)
GOTO End

:UpdateArchive
ECHO Updtaing existing full backup
ECHO ******* ******* *******  >> %Log%
%run_pdate% "Z --- \S\t\a\r\t \t\o \u\p\d\a\t\e \a\r\c\h\i\v\e" >> %Log%
IF %dw%==7 (SET updArch=%updArch_wn%) ELSE SET updArch=%updArch_dw%

REM --- Check files existence ---
IF EXIST %updArch% DEL /Q %updArch%

REM --- Create incremental archive ---
p strTemp=Updating %baseArch% to incremental %updArch% archive
ECHO.
%run_7z% u %baseArch% -u- -up0q0r2x0y2z0w0!%updArch% -w%tmpDir% -i@%IncludeList% -x@%ExcludeList% -xr@%ExcludeRegexp% -bsp2 -ssw -slp -scsWIN -mmt=on -mx5 -ms=off >> %Log%
IF %ERRORLEVEL%==0 (
	%run_pdate% "Z --- \E\x\i\t \c\o\d\e \0 \- \u\p\d\a\t\e \s\u\c\c\e\s\s\f\u\l\l\y \f\i\n\i\s\h\e\d" >> %Log%
	) ELSE (
		IF %ERRORLEVEL%==1 (
		%run_pdate% "Z --- \W\a\r\n\i\n\g\! \R\e\c\i\e\v\e\d\ \e\x\i\t \c\o\d\e \1" >> %Log%
			) ELSE (
				IF %ERRORLEVEL%==2 (
				%run_pdate% "Z --- \E\x\i\t \c\o\d\e \2 \- \F\A\T\A\L \E\R\R\O\R\!" >> %Log%
				) ELSE (
					IF %ERRORLEVEL%==7 (
					%run_pdate% "Z --- \E\x\i\t \c\o\d\e \7 \- \C\o\m\m\a\n\d \p\r\o\m\p\t \e\r\r\o\r!" >> %Log%
					) ELSE (
						IF %ERRORLEVEL%==8 (
						%run_pdate% "Z --- \E\x\i\t \c\o\d\e \8 \- \N\o\t \e\n\o\u\g\h \m\e\m\o\r\y" >> %Log%
						) ELSE (
							ECHO Recieved error 255 - user stopped running process or exit code unknown! >> %Log%
						)
					)
				)
			)
		)
	)
)

:End
ECHO Done!
%run_pdate% "Z --- \D\o\n\e" >> %Log%
ping localhost -w 1000 -n 5 > nul



, , - .

, , , ntbackup.

YandexDisk.

zip- .
, , , welcome!
! , , , .
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/338168/

:  

: [1] []
 

:
: 

: ( )

:

  URL