Anonim / 2 lata, 3 miesiące temu | Download | Plaintext | Odpowiedz |

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
:: Tomasz Zdziech
:: agron@helpdeski.pl

echo off

:: DANE
set BACKUPPATH=H:\BACKUP_FOLDER
set DATABASE=WAPRO
set SERVERNAME=localhost
set DATESTAMP=%DATE%_%TIME:~0,2%-%TIME:~3,2%
:: data rrrr-mm-dd, time gg:mm:ss,ms
set FILENAME=%BACKUPPATH%\%DATABASE%_%DATESTAMP%.bak
set ZIPPATH=C:\Program Files\7-Zip
::Rozszerzenie pliku
set EXTENSION=bak


:: -----------Backup bazy danych----------
sqlcmd -E -S %SERVERNAME% -d master -Q "BACKUP DATABASE [%DATABASE%] TO DISK = N'%FILENAME%' WITH INIT , NOUNLOAD , NAME = N'%DATABASE% backup', NOSKIP , STATS = 10, NOFORMAT"

:: -----------Pakowanie plików i usuwanie-----------
for /f %%F in ('dir %BACKUPPATH%\*.%EXTENSION% /b') do del %BACKUPPATH%\%%F.7z & "%ZIPPATH%\7z.exe" a %BACKUPPATH%\%%F.7z %BACKUPPATH%\%%F & del %BACKUPPATH%\%%F


::-----------Usuwanie starych plików-----------
:: Wyszukiwanie po dacie (usuwa starsze niż 7 dni)
forfiles /p %BACKUPPATH% /d -7 /c "cmd /c del @path"

:: usuwa najstarsze pliki (pozostawia 7 najmłodszych backupów)
for /f "skip=7 delims=" %%F in ('dir %BACKUPPATH%\*.* /b/o-d') do del %BACKUPPATH%\%%F