Our Blog

mysql-backup

There is my approach to backup a mysql database. I have put all the required parameters in bash variables, so the code can be easily reusable.

In addition to the core functionality (making backup) there is also the functionality to delete the older files that the specified number of days. For example, we can set to delete the backup files older than one month. The code is located below:


Explanation of the code above:

  1. Setting database parameter (username, password, database name and the host address to the database)
  2. Setting file system parameters:
    1. Folder where the backup will be exported
    2. Prefix of the backup file
    3. And the information how old files you want to delete after the backup is done
  3. Then is taking place the file name generator of the new backup file
  4. Then the backup is finally retrieved
  5. And in the last step is taking place the deleting of older backup files

If this code is usefully for you, just grab it and customize it as you want. You can also fork it from my github repository:

github-logo

 

Cheer

deanpodgornik

So, what do you think ?