Select Page

Mysql database backup in Linux Crontab

Mysql database backup in Linux Crontab

Here is the easiest way to run a daily backup of your database using linux crontab. Thanks to our everyday increasing mailbox size (Thanks Gmail) and their nature to be quite safe for saving document, let’s use them to store the full backup of all our Mysql database!

Requirements

  • Having a shell access to your linux box
  • Creating a user with limited mysql rights: SELECT and LOCK_TABLES is enough, For example a user backup_user with a password ChhdeqyqUzd75687fOnmYar
  • Installing Mpack: Tools for encoding/decoding MIME messages. Mpack and munpack are utilities for encoding and decoding (respectively) binary files in MIME (Multipurpose Internet Mail Extensions) format mail messages. For compatibility with older forms of transferring binary files, the munpack program can also decode messages in split-uuencoded format.

Edit your crontab

crontab -e 

and put inside on one line the following

0 1 * * * /usr/bin/mysqldump -ubackup_user –pChhdeqyqUzd75687fOnmYar yourdb |
gzip > /database_`date +'%m-%d-%Y'`.sql.gz ;
mpack -s "Databases backup"
-c application/gzip /database_`date +'%m-%d-%Y'`.sql.gz email@gmail.com

You can replace the word yourdb with your tablename or –all-databases to dump all database. With the above line a backup will be run at 1AM every day and sent in your mailbox.

About The Author

Cédric Walter

I worked with various Insurances companies across Switzerland on online applications handling billion premium volumes. I love to continuously spark my creativity in many different and challenging open-source projects fueled by my great passion for innovation and blockchain technology. In my technical role as a senior software engineer and Blockchain consultant, I help to define and implement innovative solutions in the scope of both blockchain and traditional products, solutions, and services. I can support the full spectrum of software development activities, starting from analyzing ideas and business cases and up to the production deployment of the solutions. I'm the Founder and CEO of Disruptr GmbH.

Categories

brands

 
 
Cordalo simplify writing Corda applications.
 
tokens-economy.com is a blog / digital playground where Cédric keep track of new developments in the distributed ledger technology space and present all his experimentation and tools, promoting the understanding of digital currencies and assets.
 
Galaxiis premium joomla extensions and plugins
 
Supercars-central.com is a blog about the Audi R8 Spyder V10 and more...