binaryorganic
binaryorganic

Reputation: 1594

How best could I optimize the way I'm backing up MySQL databases?

I have several websites hosted on a VPS and am currently performing database backups by running a shell script via cron that looks something like this:

mysqldump -uusername1 -prootpassword dbname1 > /backup/dbname1.bak
mysqldump -uusername2 -prootpassword dbname2 > /backup/dbname2.bak
mysqldump -uusername3 -prootpassword dbname3 > /backup/dbname3.bak

I have a couple of concerns about this process.

Firstly, I'm using the root server password to perform mysqldump, and the file is being stored in clear text on the server (not publicly accessible or anything, but there are obviously concerns if I grant other users access to the server for one reason or another). I'm using root because it's simpler than tracking everybody that creates a database down and asking them for their specific db passwords.

Secondly, this process only works if people inform me that they've added a database (which is fine for the most part, we're not doing anything super complicated over here). I would prefer to have a backup of everything without worrying that I've overlooked something.

Upvotes: 0

Views: 886

Answers (2)

Marc B
Marc B

Reputation: 360572

You could always just dump ALL the databases:

mysqldump --all-databases | gzip -9 > /backup/dbs.bak.gz

That'd free you from having to keep track of which dbs there are. The downside is that restoring gets a bit more complicated.

As for using root, there's no reason you couldn't create another account that has permissions to do backups - you should never use the root account for anything other than initial setup.

Upvotes: 1

Johan
Johan

Reputation: 1988

I use this script: http://sourceforge.net/projects/automysqlbackup/ It works perfectly. Also, you should add a backup MySQL user that has global SELECT and LOCK TABLES permissions. That way you don't need everyone's username and password/

Upvotes: 1

Related Questions