Last active
July 24, 2017 07:23
-
-
Save pvgennip/6ba0654a5957159e7067037e3cca3b39 to your computer and use it in GitHub Desktop.
MySql backup Linux via logrotate.d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create mysql backup user | |
mysql -u root -pRootPassword | |
GRANT LOCK TABLES, SELECT ON *.* TO 'backupuser'@'localhost' IDENTIFIED BY 'secret-password’; | |
# Create log rotate script | |
sudo nano mysql-db-backup | |
/var/backups/db.sql.gz { | |
daily | |
rotate 8 | |
nocompress | |
create 640 root adm | |
postrotate | |
mysqldump -u backupuser -psecret-password --all-databases > /var/backups/db.sql --single-transaction | |
gzip -9f /var/backups/db.sql | |
endscript | |
} | |
# Copy logrotate script to /etc/logrotate.d/ | |
sudo cp mysql-db-backup /etc/logrotate.d/ | |
# Test script | |
sudo logrotate -f /etc/logrotate.d/mysql-db-backup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment