The Eric Wroolie Blog

Overpass Experiences

  • Blog
  • Videos
  • Overpass Apps

Powered by Overpass Apps

Creating a daily Database backup for MySql (and self-hosted WordPress blogs)

June 8, 2009 by wroolie 2 Comments

Most of the professional work I do is with Microsoft SQL Server and .Net platform.  For my own pet projects, I prefer using MySql as a db engine.  WordPress (and most PHP projects use it primarily).  It’s cheap and efficient to host.

One of the features I always found SQL Server to lack is the ability to generate insert scripts.  Sure, it’s easy to script out tables, views, and stored procs– but you still have to get tricky with transferring data from one database to another.  I know people say “you can just back up the database and restore it to a new server”, but they obviously have never worked in a tight change-controlled enterprise environment where you need everyone under the sun to approve this a dedicated dba overlooking everything.  This method is overkill if you just want to replace the a record that a user has “accidentally deleted”.

MySql has a very handy feature that use frequently called mysqldump.  This will create an sql file of all db objects and store them in an sql file — data structures and data too.  Mysqldump will create one script with table create statments (and drop statements) along with insert statements for all of your data.

I use mysqldump to store local backups of my remote databases.  For example, this blog is backed up every morning– just in case my server goes down and is unrecoverable.   I occasionally back up web code with an FTP routine, but the database needs to be done more often– since it is frequently updated by me or readers of this blog with comments.

Here’s how it’s done using my WordPress database and local XP account:

1.  Make sure you can connect to your remote database from your local pc

To do this, you need to have MySql client tools installed on you local pc.  Just try to log into our remote site using MySQL Administrator. 

image

If you can connect from you local pc, you can use mysqldump from the command line.

2.  Write a batch script to create a folder for each day

I have a folder called “backups” with a date-stamped folder for each day of backup (ie.  2009-06-08).  Here is my code for that batch file (with my db details removed):

rem backup blog

rem create new folder name
set DD=%DATE:~0,2%
set MM=%DATE:~3,2%
set YY=%DATE:~8,2%
set YYYY=%DATE:~6,4%
set FOLDER=%YYYY%-%MM%-%DD%

rem make the new folder
cd g:backups
mkdir %FOLDER%

rem go to folder
cd %FOLDER%

rem create the data dump
mysqldump -h 111.222.111.222 -u username -ppassword wpDBName > blogdump.sql

For the mysqldump line, use the ip address (or host name) of the remote server and user name and password.  In the example above, I am connecting to my db called “wpDBName” on host 111.222.111.222 with the user name “username” and password “password”.  It is writing out to a file on my local pc called “blogdump.sql” in a folder with a date stamp.

NOTE: the -p switch does not have a space between it and the password.  This is bizarre, but that’s how it works.

Save to the above code to a file with a .bat extension.  I called mine “backup.bat”.

3.  Create a scheduled task to run this job.

Use Windows Scheduled Tasks to automatically run your batch job.  This can be found in Control Panel and is easy to use (Wizard Generated).  I run my job at 4:10 am.  To save the environment, I shut down my pc at night, but a bios task wakes it back up at 4.  At 10 minutes past 4, my databases are backed up (just before I sit at the keyboard with my coffee to catch the final innings of a Padres game).  Once a week, I have a similar job that will back up all web code via ftp.

image

 

That’s it, the majority of my disaster recovery problems taken care of.  I have the data stored on my local pc and on the server.  It would be easy to run the same script from another pc if I need to, also.

As you can imagine, this daily backup can take a good deal of disk space.  Each sql dump is about 3mb for this site.  I usually clear things down every few weeks and delete backups that are over a week old.  I don’t replace my backup file every day because it could be a few days before I realise anything has gone wrong.  I may script this at some point in the future.

I’m blogging about this because a few days ago I was playing around with my Plesk settings on my Ubuntu VPS and everything stopped working.  I had to restore to my last VPS backup– which was a few weeks old.  That would have meant losing all my WordPress blog posts and (more importantly) the comments I’ve received from them.  Luckily, I have this backup method in place so I didn’t lose anything.

If you are not backing up your databases (even if they are hosted with a web host), you should really consider it.  It is a trivial task to set this up and could save you in the future.

I hope someone out there finds this useful.  Drop me a line (or post a comment) if you found this to be of any help.

Filed Under: Blogging, Software Dev & Productivity

Dalian CISIS trip in jeopardy

June 2, 2009 by wroolie Leave a Comment

My big news this week (aside from looking for new client opportunities) is that I’ve hit a snag in my visa application to attend CISIS in China in a few weeks.  I’ve registered for CISIS, booked a hotel, and set up meetings in Dalian.  But the passport is taking more time than I allowed for.

The problem with getting a visa for China (which should only take 4 working days) is that I need 6 months remaining on my passport in order to go.  I realised about a month ago that my American passport expires in four months.  Zao Gao! 

So, I had to

  1. Renew my American passport
  2. Transfer to indefinite leave to remain status for the UK to the new passport (an NTL)
  3. Get a visa for China.

The US passport agency said it should take about 3 weeks, since they had to send my passport application to the States.  I got it back in just over two weeks.

The UK border agency didn’t give an estimate, but I figured 3 weeks should be good enough for that.  After all, I already have permanent residency, I just need the stamp in my new passport.  They didn’t need to send it anywhere.  I sent it to them two and a half weeks ago. 

Yesterday, I phoned the Border Agency office.  I had a letter from them saying they had my passport and that I should NOT phone them to check on the status.  But I was worried so I phoned anyway.  After spending ages in a call queue, I got someone on the phone who did not want my reference number when I offered to give it.  “We don’t check on the status of an NTL application until it has been with us for 14 weeks,” they guy told me.  He obviously had to deal with a lot of difficult people and he wasn’t going to give me any lee-way (read “he was kind of rude”).  I asked if there was any way to speed it up, he told me there wasn’t.  He would not check on the status.  I told him it was a renewal, not a new application—but he didn’t help.  He told me that the wait time is between 4 to 14 weeks.  I was speechless.  4 weeks!?!?  There is no way to make this happen before CISIS starts.

Yesterday was a flurry of activity cancelling things.  The hotel was easy to cancel.  The flight was non-refundable (but I might be able to get about half of my money back).  The people at UK Trade and Investment are holding off on booking any more meetings with software companies.  They even offered to help speed up the China visa if it helps.  Still, there is the possibility that the passport might drop through the letter box and everything will be back on.  We’ll see.  I’m not cancelling my flight just yet.

I’m still going to Dalian.  I’m just not sure when.  I might be be a few days later, or a few weeks. 

Tomorrow, I get 4 shots for vaccination. 

I’m trying not to let it get me down too much.  I’m enjoying the beautiful sunshine (which can be rare in England) and re-establishing some old contacts.  I’m still playing with Ruby on Rails and trying to write a few applications which have been in my todo list for a while.  I might as well enjoy the down time.

Filed Under: Chinese, Software Dev & Productivity

Thanks to everyone at BNP Paribas

June 2, 2009 by wroolie 1 Comment

I should have posted this last week.  Friday was my last day working for BNP Paribas (my second time around).

We had very nice leaving drinks and they gave me a wonderful gift and card.  I will definitely miss my fellow developers and business analysts in London and Mumbai.

Thank you all for the card and the gift.  I hope we keep in touch.

Filed Under: Software Dev & Productivity

  • « Previous Page
  • 1
  • …
  • 14
  • 15
  • 16
  • 17
  • 18
  • …
  • 37
  • Next Page »

Recent Posts

  • My Gig and the Imposter Syndrome
  • Getting Picked Last for Teams in PE
  • One Little Growth Opportunity at a Time
  • I’m sorry if I look like I know what I’m doing
  • New Years Reclamations