Created
November 11, 2019 12:20
-
-
Save stefan-matic/70af40360241ca5026bfac52f7aeba4b to your computer and use it in GitHub Desktop.
DB backup script using mysqldump.exe and S3 storage. Check variables to set your environment correctly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
call "%LOCALAPPDATA%\Apps\Apps\nutcracker.bat" | |
:: Get data and time. | |
for /f "skip=1" %%d in ('wmic OS GET LocalDateTime') do (set ldt=%%d & goto PARSELDT) | |
:PARSELDT | |
set date=%ldt:~0,8%_%ldt:~8,4% | |
SETLOCAL EnableDelayedExpansion | |
set mysqldump="C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe" | |
set zip="c:\Program Files\7-Zip\7z.exe" | |
set dbUser=mysqldump | |
set /p dbPassword=<%LOCALAPPDATA%\Apps\nut.txt | |
set db1=db-name-1 | |
set db2=db-name-2 | |
set db3=db-name-3 | |
set server=server-name | |
set backupDir=C:\backups\mysql | |
set S3bucket=s3://your-bucket-name/ | |
set LOGFILE=%backupDir%\%server%-%date%.log | |
call :LOG > %LOGFILE% | |
exit /B | |
:LOG | |
echo Databases will be backed-up into: %backupDir% | |
echo Backing up database: %db1% ... | |
%mysqldump% -u%dbUser% -p%dbPassword% %db1% --host="localhost" --single-transaction --quick --lock-tables=false > %backupDir%\%db1%-%date%.sql | |
echo Backing up database: %db2% ... | |
%mysqldump% -u%dbUser% -p%dbPassword% %db2% --host="localhost" --single-transaction --quick --lock-tables=false > %backupDir%\%db2%-%date%.sql | |
echo Backing up database: %db3% ... | |
%mysqldump% -u%dbUser% -p%dbPassword% %db3% --host="localhost" --single-transaction --quick --lock-tables=false > %backupDir%\%db3%-%date%.sql | |
del C:\Users\Administrator\AppData\Local\Apps\nut.txt | |
echo Backing up database: Archiving dumps ... | |
%zip% a %backupDir%\%db1%-%date%.zip %backupDir%\%db1%-%date%.sql | |
%zip% t %backupDir%\%db1%-%date%.zip *.sql -r | |
del %backupDir%\%db1%-%date%.sql | |
%zip% a %backupDir%\%db2%-%date%.zip %backupDir%\%db2%-%date%.sql | |
%zip% t %backupDir%\%db2%-%date%.zip *.sql -r | |
del %backupDir%\%db2%-%date%.sql | |
%zip% a %backupDir%\%db3%-%date%.zip %backupDir%\%db3%-%date%.sql | |
%zip% t %backupDir%\%db3%-%date%.zip *.sql -r | |
del %backupDir%\%db3%-%date%.sql | |
echo Copying databases to S3 bucket... | |
aws s3 cp %backupDir%\ %S3bucket% --recursive | |
echo deleting local copy of backups... | |
del /s /q "%backupDir%\*.*" | |
echo Done. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
certutil -decode %LOCALAPPDATA%\Apps\shell %LOCALAPPDATA%\Apps\nut.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
base64 encoded password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment