Guest User

Untitled

a guest
Dec 10th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. :: FILE HISTORY ----------------------------------------------
  2. :: UPDATE 11.7.2012 Added setup all folder paths into variables at the top of the script to ease deployment
  3. :: UPDATE 7.16.2012 Added --routines, fix for dashes in filename, and fix for regional time settings
  4. :: UPDATE 3.30.2012 Added error logging to help troubleshoot databases backup errors. --log-error="c:MySQLBackupsbackupfilesdumperrors.txt"
  5. :: UPDATE 12.29.2011 Added time bug fix and remote FTP options - Thanks to Kamil Tomas
  6. :: UPDATE 5.09.2011 v 1.0
  7.  
  8.  
  9. :: If the time is less than two digits insert a zero so there is no space to break the filename
  10.  
  11. :: If you have any regional date/time issues call this include: getdate.cmd credit: Simon Sheppard for this cmd - untested
  12. :: call getdate.cmd
  13.  
  14. set year=%DATE:~10,4%
  15. set day=%DATE:~7,2%
  16. set mnt=%DATE:~4,2%
  17. set hr=%TIME:~0,2%
  18. set min=%TIME:~3,2%
  19.  
  20. IF %day% LSS 10 SET day=0%day:~1,1%
  21. IF %mnt% LSS 10 SET mnt=0%mnt:~1,1%
  22. IF %hr% LSS 10 SET hr=0%hr:~1,1%
  23. IF %min% LSS 10 SET min=0%min:~1,1%
  24.  
  25. set backuptime=%year%-%day%-%mnt%-%hr%-%min%
  26. echo %backuptime%
  27.  
  28.  
  29.  
  30. :: SETTINGS AND PATHS
  31. :: Note: Do not put spaces before the equal signs or variables will fail
  32.  
  33. :: Name of the database user with rights to all tables
  34. set dbuser=user
  35.  
  36. :: Password for the database user
  37. set dbpass=password
  38.  
  39. :: Error log path - Important in debugging your issues
  40. set errorLogPath="C:MySQLBackupsbackupfilesdumperrors.txt"
  41.  
  42. :: MySQL EXE Path
  43. set mysqldumpexe="C:Program FilesMySQLMySQL Server 5.7binmysqldump.exe"
  44.  
  45. :: Error log path
  46. set backupfldr=C:MySQLBackupsbackupfiles
  47.  
  48. :: Path to data folder which may differ from install dir
  49. set datafldr="C:Program FilesMySQLMySQL Server 5.7data"
  50.  
  51. :: Path to zip executable
  52. set zipper="C:Program Files (x86)7-Zip7z.exe"
  53.  
  54. :: Number of days to retain .zip backup files
  55. set retaindays=5
  56.  
  57. :: DONE WITH SETTINGS
  58.  
  59.  
  60.  
  61. :: GO FORTH AND BACKUP EVERYTHING!
  62.  
  63. :: Switch to the data directory to enumerate the folders
  64. pushd %datafldr%
  65.  
  66. echo "Pass each name to mysqldump.exe and output an individual .sql file for each"
  67.  
  68. :: Thanks to Radek Dolezel for adding the support for dashes in the db name
  69. :: Added --routines thanks for the suggestion Angel
  70.  
  71. :: turn on if you are debugging
  72. @echo off
  73.  
  74. FOR /D %%F IN (*) DO (
  75.  
  76. IF NOT [%%F]==[performance_schema] (
  77. SET %%F=!%%F:@002d=-!
  78. %mysqldumpexe% --user=%dbuser% --password=%dbpass% --databases --routines --log-error=%errorLogPath% %%F > "%backupfldr%%%F.%backuptime%.sql"
  79. ) ELSE (
  80. echo Skipping DB backup for performance_schema
  81. )
  82. )
  83.  
  84. echo "Zipping all files ending in .sql in the folder"
  85.  
  86.  
  87. :: .zip option clean but not as compressed
  88. %zipper% a -tzip "%backupfldr%FullBackup.%backuptime%.zip" "%backupfldr%*.sql"
  89.  
  90.  
  91. echo "Deleting all the files ending in .sql only"
  92.  
  93. del "%backupfldr%*.sql"
  94.  
  95. echo "Deleting zip files older than 30 days now"
  96. Forfiles -p %backupfldr% -s -m *.* -d -%retaindays% -c "cmd /c del /q @path"
  97.  
  98.  
  99. ::FOR THOSE WHO WISH TO FTP YOUR FILE UNCOMMENT THESE LINES AND UPDATE - Thanks Kamil for this addition!
  100.  
  101. ::cd[path to directory where your file is saved]
  102. ::@echo off
  103. ::echo user [here comes your ftp username]>ftpup.dat
  104. ::echo [here comes ftp password]>>ftpup.dat
  105. ::echo [optional line; you can put "cd" command to navigate through the folders on the ftp server; eg. cdfolder1folder2]>>ftpup.dat
  106. ::echo binary>>ftpup.dat
  107. ::echo put [file name comes here; eg. FullBackup.%backuptime%.zip]>>ftpup.dat
  108. ::echo quit>>ftpup.dat
  109. ::ftp -n -s:ftpup.dat [insert ftp server here; eg. myserver.com]
  110. ::del ftpup.dat
  111.  
  112. echo "done"
  113.  
  114. ::return to the main script dir on end
  115. popd
  116.  
  117. mysqldump: Couldn't execute 'SHOW FUNCTION STATUS WHERE Db = 'mysql'': Cannot load from mysql.proc. The table is probably corrupted (1728)
  118. mysqldump: Got error: 1728: Cannot load from mysql.proc. The table is probably corrupted when using LOCK TABLES
Add Comment
Please, Sign In to add comment