I use the following script under /etc/crontab
to make a daily backup of my MySQL database (up to the last 30 days):
0 8 * * * mysqldump -u root -PASSWORD --all-databases > /root/backups/mysql/db.sql
1 8 * * * zip /root/backups/mysql/db-$(date +\%F-\%T-).sql.zip /root/backups/mysql/db.sql
2 8 * * * rm /root/backups/mysql/db.sql
2 8 * * * find /root/backups/mysql/* -mtime +30 -exec rm {} \;
I need to type my password where it is written PASSWORD. This is problematic because then my root DB password is exposed if someone hacks the system. Is there a way to make the exact same automatic backups without writing the password exposed?
root
access), the system, including the database, should be considered lost and be reinstalled anyway. See also https://dev.mysql.com/doc/refman/5.7/en/password-security-user.html – Kusalananda Apr 17 '17 at 16:14