logrotate mysql dump

Technique logrotate mysql dump

I chose to use logrotate to execute a copy with rotation and auto purge “of database dumps over which files they need my sites.

In this example I run up to a mysql with mysqldump daily, and cherish the previous 8 with this method.

Let’s see how:

1. Create a file as you wish: mysql-bkup.

We will make copies of all the databases in a single dump. Certainly be staying out of this bath your mysql password.

Vim/etc/logrotate.d/mysql-bkup
/var/backups/db.sql.gz {
daily
Rotate 8
nocompress
create 640 root adm
postrotate
mysqldump-u root-pPassword--all-databases >/var/backups/db.sql--single-transaction
gzip-/var/backups/db.sql 9f
endscript
}

2. One last step:

The empty file must be created, which will then be rotated. Attention if not found, logrotate will break and will generate an error.

touch/var/backups/db.sql.gz

To test the logrotate configuration you just performed, run this command:

logrotate-f/etc/logrotate.d/mysql-bkup

If you do not see errors and how to exit too early, there may be something wrong. Useful to add verbose option.

logrotate-f/etc/logrotate.d/mysql-bkup-v

3. Repeat for the tar of the sites

Do not need much imagination to alter this configuration and a tar cfz file archives sites. So enjoy the rest. Repeat task 1 and 2.

Did. There is no other.

backup, databases, dump, logrotate, mysql

Leave a Reply

Your email address will not be published. Required fields are marked *

For Inspirations, Special Offers and Much More

Via Scoglio grosso 28
05100 Terni, Italy
+39 3388383150
venturini@ict360.it

cf: VNTFNC73P11L117N
p.iva: 00723880555

© 2018 Francesco Venturini. All Rights Reserved