Search the Community
Showing results for tags 'housekeeping'.
Found 1 result
MySQL DB backup v1.1. Note: This script is included in the DayZEpoch 1.0.6 distribution (when released). What is it. This is a Windows batch file (.bat) which will backup your MYSql database(s) for you. If you add it to Windows scheduler it can also run automatically at a frequency you define (every 15 minutes for example). Features. - Backup tables, triggers and events. - Housekeeps old backups after user defined number of days. - Resulting .sql files can be loaded in to a SQL client and run against a MYSQL database to recreate the structure and data from the backed up database. - Server DateTime format independant (works for MM/DD/YYYY or DD/MM/YYYY date formats). - Can be scheduled with Windows scheduler. How to use it. Create a .bat file (call it something like DB_Backup.bat) and paste the following in to it. @REM *** PARAMETERS/VARIABLES *** SET BackupDir="[Where you want to save the backups]" SET mysqldir="C:\Program Files\MySQL\MySQL Server 5.6\bin" SET mysqlschema=[Your DB schema name] SET mysqlpassword=[your DB password] SET mysqluser=[your DB user login] SET housekeepafter=5 for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' SET ldt=%%j set datestamp=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%.%ldt:~8,2%-%ldt:~10,2%-%ldt:~12,2% @REM *** EXECUTION ***@REM Change to mysqldir c: cd %mysqldir% @REM dump/backup ALL database, this is all in one line mysqldump -u %mysqluser% -p%mysqlpassword% --databases %mysqlschema% --routines --events --triggers --quick >%BackupDir%\%mysqlschema%_backup.%datestamp%.sql @REM - Housekeeping forfiles -p %BackupDir% -s -m *.sql -d -%housekeepafter% -c "cmd /c del @path" Configuration Input your DB connection details and desired backup save location. All details that need changing are in . Make the changes without the . e.g. SET mysqlschema=[Your DB schema name] may change to SET mysqlschema=EpochDB SET BackupDir="[Where you want to save the backups]" May change to SET BackupDir="c:\DB-Backups" Housekeeping will clear any .sql files that are over housekeepafter number of days old. You may need to confirm the MySQL path for the mysqldump exe as it may depend on your provider. Add "read" (without "") at the end of the file to require an input for debugging. This allows you to check the test backup is ok and troubleshoot any issues. Remove it when automating or the .bat file will never close. Automation can be done via Windows task scheduler. Create a basic task and then edit the tasks parameters after creating if you want to backup more than once a day. The option is only available after the task is created. Revision History. Current version: v1.1 Changes: - Amended code to cope with US & UK date formats when calculating the resulting .sql files datetimestamp included in the filename. Previous versions: v1.0: Initial version. Possible future improvements. I may add an option to compress (zip) the files if there is enough interest.