WordPress Database Backups

Backing up the WordPress database is an essential part of keeping your blog up and running smoothly. I was looking for a solution that would automatically do a nightly backup for me. I looked at several plugins, some third-party free and paid solutions, and a few manual ones as well.

I eventually settled on just implementing this awesome shell script as a cron job. What’s even more awesome is that the one dependency, mutt, is already installed in the DreamHost environment I’m using to run this blog. Sa-weet! One slight gotcha was that DreamHost also doesn’t run MySQL servers on the same machine as you get ssh access to, so I added one command line parameter, ‘-h myhostname’, to the mysqldump command. Substitute this with whatever hostname you chose for your MySQL database in the Panel. Fill in the rest of the variables like the shell script site says.

Now all I had to do was put this script in my home directory, a little scp foo (set up password-less authentication for ssh if haven’t already done so):

scp ~/Downloads/cronjob2.sh user@host
view raw upload.sh This Gist brought to you by GitHub.

And lasty, set up a cron job for this bad boy.

ssh user@host
chmod u+x cronjob2.sh
crontab -e
view raw edit_cron.sh This Gist brought to you by GitHub.

Add the following line to the file (and fill in the mail address if it prompts you, its a good idea):

@daily /home/user/cronjob2.sh
view raw cron_job.sh This Gist brought to you by GitHub.

Save, close, exit. Now every night you should get an email with a sql dump of your whole WordPress database. If you don’t want this sitting in your personal email, just set up a new Gmail account and let it accumulate there, free backup storage!

Git: Adding an origin into an existing repo and tracking it

When you git clone and existing repo you get a nice remote called origin as well as knowing that your local master branch also tracks the origin/master. This makes it convenient to run git push all by itself and it really becomes part of your memorized workflow if you do it enough.

What happens if the repo starts on your local machine and now you want to put it on a server? It would be really nice to have a similar setup, and all it takes is a few commands to make it feel right.

First, add the remote:

git remote add origin gitolite@myserver.com:MyRepo
view raw add_remote.sh This Gist brought to you by GitHub.

Next we want to identify the origin’s master branch as our local master branch’s ‘upstream’. This is the same as saying our local master branch ‘tracks’ the origin’s master branch.

git branch --set-upstream master origin/master

Now we should be able to just push our local code up to the newly added remote origin like so:

git push
view raw push.sh This Gist brought to you by GitHub.

I came across this problem while trying to set up gitolite on a remote machine and it went ahead and created my repo on the server. But I wanted the same kind of workflow I got by just git clone-ing from a remote like I usually do. If you have any questions or know of a better way to do this, leave me a comment. FYI, the --set-upstream option is new in git since 1.7.0 (although not very new anymore).

Design Products for Yourself

Quote

Totally agree with Steve on this one.

I think every good product I’ve seen has been created because a group of people really cared about making something wonderful for themselves and their friends to use. Why did we build Apple II? We really, really wanted it.

~ Steve Jobs @ WWDC 1997

We already know this. Looking at it slightly differently, all he is saying is that you must maintain a sharp focus on the target audience. What is the best way to know you product is satisfying the need of that target audience? Well duh, you being in the target.