Playing with Debian

Wednesday, 12th March 2008 at 10:36pm

Backup your databases... now

Just like I predicted, I had my first mess up. On the bright side though, it wasn't because of Debian. It was because I wrote a script and replaced all the entries with a blank line... That's not important though, what is important is that I should have backed up, which I didn't. (I had to go through my entries in Google Reader - thank God for them archiving feeds and not getting them live - and copy and paste them back.)

Anyway, backing up your MySQL databases is easy actually. There's a page about it on the MySQL documentation. I chose the mysqldump option.

From PuTTY (you don't need to be in MySQL, mysqldump is part of the mysql-client package, but executable by itself) I did this:

mysqldump -A -u root -p > /home/shamess/backedup-files/20080312.mysql

The -A means "all databases", if you only want one database you can append the database name at the end (and miss out this switch). If you only want one table, put the table name at the end of that too.

The next switch is me giving the MySQL username. I decided to use root, since it has access to all the databases. The "-p" is saying that I'm going to use a password. I didn't put my password after it, because you can leave it out and it'll prompt you for it after you press enter (thanks Marc for that).

Then there's something new for us to get excited about. The greater than symbol (>) means "write whatever output to this file". I did that because I couldn't find the switch to do it for mysqldump, but I'm sure there is one (comment if you find it).

On a side note: if you look through the site and notice an entry is out of place, or the subject has nothing to do with the post (meaning I've pasted the wrong post) then please comment!

Comments

Your name: Your URL:

Body:

User comments

Ober says:

The switch to output to a file is "-r". I do prefer ">" myself though since it's so useful that I use it all the time. You're going to use "<" when you restore a backup anyway. ^.^

Read some previous entries