Posts Tagged ‘backup’

One-way MySQL DB Syncing for Dummies

June 3rd, 2009

To ease my development while on the move, I have local development copies of my websites running on my MacBook Pro. This has always worked pretty well for me, as content for my websites was created, predominantly, by myself, and when new content was created at a single site I could sync that database manually and get an up to date local content set.

With my recent efforts into lifestreaming, this is no longer the case. My content now comes in whenever I post content on any website. I’m a fairly frequent user of the internet services that feed my lifestream (Twitter, Delicious, Flickr, etc), and keeping the content on my local version up to date was turned into a troublesome task, forcing manual, tedious syncing each time I went to work.

Without further explanation, here are the steps I took to make a one line MySQL database syncing command. There may be better ways to do this and if you know them, please comment.

1. Setup a MySQL “dump” user. Mine is cleverly named “dump” and is passwordless, although if you are more security conscious than I am, you can add a password of your choosing. On the server, log into mysql and issue this GRANT statement from a user with the proper permissions.

1
GRANT SELECT, LOCK TABLES ON `dbname_remote`.* TO 'dump'@'localhost';

2. Create a bash alias
~/.bashrc :

1
ALIAS clone_lifestream='ssh -q -t hostname "mysqldump -u dump dbname_remote" | mysql -u root dbname_local'

Notes: For this example, you need to replace a few things.

  1. dbname = the remote database name
  2. hostname = the remote hostname
  3. dbname_local = the local database name
  4. clone_lifestream = the name of the alias, can be anything.

github? we don’t need no stinking github…

February 2nd, 2009

I use git for all my projects… I love the ability to commit changes when I’m on an airplane or stuck somewhere without internet access. However, I still like to be able to push my git project to a remote server for backup and accessibility, and I’m not going to pay for github. Don’t get me wrong, github is fine for public projects and collaborative development, but for my personal development stuff, it’s an unnecessary expense.

Well, I always forget how to setup a remote master so that I can push and pull and keep a backup on a remote server. Here are my quick notes…. for a detailed explanation see Tim Lucas’s tutorial.

On server:

1
2
mkdir /srv/git/whatever
git init /srv/git/whatever

On local machine:

1
2
git remote add origin ssh://host/srv/git/whatever
git push origin master

And you’re all set!