{"id":225,"date":"2019-05-13T14:44:10","date_gmt":"2019-05-13T14:44:10","guid":{"rendered":"https:\/\/blog.iabsolute.com\/?p=225"},"modified":"2019-05-13T14:44:10","modified_gmt":"2019-05-13T21:44:10","slug":"mssql-backup-on-windows-box","status":"publish","type":"post","link":"https:\/\/blog.iabsolute.com\/?p=225","title":{"rendered":"mssql backup on windows box"},"content":{"rendered":"\n<p>:: Auto MySQL Backup For Windows Servers<br>\n:: By CONSULTING, INC.<\/p>\n\n\n\n<p>:: \u2014\u2014\u2014\u2014\u2014\u2014 FILE HISTORY \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2013<br>\n:: UPDATE 03.10.2017  v 1.0 <\/p>\n\n\n\n<p>:: If the time is less than two digits insert a zero so there is no space to break the filename<\/p>\n\n\n\n<p>set year=%DATE:~10,4%<br>\nset day=%DATE:~7,2%<br>\nset mnt=%DATE:~4,2%<br>\nset hr=%TIME:~0,2%<br>\nset min=%TIME:~3,2%<\/p>\n\n\n\n<p>IF %day% LSS 10 SET day=0%day:~1,1%<br>\nIF %mnt% LSS 10 SET mnt=0%mnt:~1,1%<br>\nIF %hr% LSS 10 SET hr=0%hr:~1,1%<br>\nIF %min% LSS 10 SET min=0%min:~1,1%<\/p>\n\n\n\n<p>set backuptime=%year%-%mnt%-%day%-%hr%-%min%<br>\necho %backuptime%<\/p>\n\n\n\n<p>:: SETTINGS AND PATHS<br>\n:: Note: Do not put spaces before the equal signs or variables will fail<\/p>\n\n\n\n<p>:: Defaults file path \u2013 no hardcoding of mysql password in the script<br>\nset defaultsFilePath=\u201dC:\\Users\\home\\mysql_inspectionapp.cnf\u201d<\/p>\n\n\n\n<p>:: Error log path \u2013 Important in debugging your issues<br>\nset errorLogPath=\u201d\\\\naster\\inspectionBK\\backupfiles\\dumperrors.log\u201d<\/p>\n\n\n\n<p>:: MySQL EXE Path<br>\nset mysqldumpexe=\u201dC:\\Program Files\\MySQL\\MySQL Server 5.5\\bin\\mysqldump.exe\u201d<\/p>\n\n\n\n<p>:: Error log path<br>\nset backupfldr=\\\\naster\\inspectionBK\\backupfiles\\<\/p>\n\n\n\n<p>:: Path to data folder which may differ from install dir<br>\nset datafldr=\u201dC:\\ProgramData\\MySQL\\MySQL Server 5.5\\data\u201d<\/p>\n\n\n\n<p>:: Path to zip executable<br>\nset zipper=\u201d\\\\naster\\inspectionBK\\zip\\7za.exe\u201d<\/p>\n\n\n\n<p>:: Number of days to retain .zip backup files<br>\nset retaindays=5<\/p>\n\n\n\n<p>:: DONE WITH SETTINGS<\/p>\n\n\n\n<p>:: GO FORTH AND BACKUP EVERYTHING!<\/p>\n\n\n\n<p>:: Switch to the data directory to enumerate the folders<br>\npushd %datafldr%<\/p>\n\n\n\n<p>echo \u201cPass each name to mysqldump.exe and output an individual .sql file for each\u201d<\/p>\n\n\n\n<p>:: turn on if you are debugging<br>\n@echo off<\/p>\n\n\n\n<p>FOR \/D %%F IN (*) DO (<\/p>\n\n\n\n<p>IF NOT [%%F]==[performance_schema] (<br>\nSET %%F=!%%F:@002d=-!<br>\n%mysqldumpexe% \u2013defaults-file=%defaultsFilePath% \u2013max_allowed_packet=256M \u2013single-transaction \u2013master-data=2 \u2013quick \u2013databases \u2013routines \u2013events \u2013log-error=%errorLogPath% %%F &gt; \u201c%backupfldr%%%F.%backuptime%.sql\u201d<br>\n) ELSE (<br>\necho Skipping DB backup for performance_schema<br>\n)<br>\n)<\/p>\n\n\n\n<p>echo \u201cZipping all files ending in .sql in the folder\u201d<\/p>\n\n\n\n<p>:: .zip option clean but not as compressed<br>\n%zipper% a -tzip \u201c%backupfldr%FullBackup.%backuptime%.zip\u201d \u201c%backupfldr%*.sql\u201d<\/p>\n\n\n\n<p>echo \u201cDeleting all the files ending in .sql only\u201d<\/p>\n\n\n\n<p>del \u201c%backupfldr%*.sql\u201d<\/p>\n\n\n\n<p>echo \u201cDeleting zip files older than %retaindays% days now\u201d<br>\nForfiles -p %backupfldr% -s -m *.* -d -%retaindays% -c \u201ccmd \/c del \/q @path\u201d<\/p>\n\n\n\n<p>:: IF WHO WISH TO FTP BACKUP FILES UNCOMMENT THESE LINES AND UPDATE <\/p>\n\n\n\n<p>::cd\\[path to directory where your file is saved]<br>\n::@echo off<br>\n::echo user [here comes your ftp username]&gt;ftpup.dat<br>\n::echo [here comes ftp password]&gt;&gt;ftpup.dat<br>\n::echo [optional line; you can put &#8220;cd&#8221; command to navigate through the folders on the ftp server; eg. cd\\folder1\\folder2]&gt;&gt;ftpup.dat<br>\n::echo binary&gt;&gt;ftpup.dat<br>\n::echo put [file name comes here; eg. FullBackup.%backuptime%.zip]&gt;&gt;ftpup.dat<br>\n::echo quit&gt;&gt;ftpup.dat<br>\n::ftp -n -s:ftpup.dat [insert ftp server here; eg. myserver.com]<br>\n::del ftpup.dat<\/p>\n\n\n\n<p>echo \u201cdone\u201d<\/p>\n\n\n\n<p>::return to the main script dir on end<br>\npopd<\/p>\n","protected":false},"excerpt":{"rendered":"<p>:: Auto MySQL Backup For Windows Servers :: By CONSULTING, INC. :: \u2014\u2014\u2014\u2014\u2014\u2014 FILE HISTORY \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2013 :: UPDATE 03.10.2017 v 1.0 :: If the time is less than two digits insert a zero so there is no space to break &hellip; <a href=\"https:\/\/blog.iabsolute.com\/?p=225\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-225","post","type-post","status-publish","format-standard","hentry","category-scripting"],"_links":{"self":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts\/225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=225"}],"version-history":[{"count":1,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts\/225\/revisions"}],"predecessor-version":[{"id":226,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts\/225\/revisions\/226"}],"wp:attachment":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}