Archive for May, 2009
Automating Your MySQL Database Backup On Media Temple’s Grid-Server
Let me admit this – I did not backup the Tweeght‘s database until today. Somehow I kept procrastinating it for no reason. Since Tweeght is growing consistently, it was crucial for me to backup its database on daily basis and prepare myself from loosing all the crucial data in some sort of catastrophic event.
I use Media Temple’s Grid-Server for Tweeght. MT has good knowledge base article on – How can I Backup and Restore a MySQL database?.
But this article just mentions about how to backup your database for once. I wanted to automate this backup process on daily basis. So I Googled a little-bit, and came across this wonderful script. So I took that script, updated it for MT’s Grid-Server infrastructure, and now I’m all set within 20 minutes to take daily backups of my crucial databases.
Here are the steps I followed:
1. Go to /data directory in your account. I preferred this over /domains directory because this is accessible only by you and not by public. You don’t want the public to accidentally access dump of your database.
2. Create /db_backup directory. Go to /db_backup directory and create three new directories – /scripts , /daily and /recent.
3. Go to /scripts directory and open up your favorite editor. Copy and paste following code -
#!/bin/bash
# Set a value that we can use for a datestamp
DATE=`date +%Y-%m-%d`
# Our Base backup directory
BASEBACKUP="/home/XXXXX/data/db_backup/daily"
for DATABASE in `cat /home/XXXXX/data/db_backup/scripts/db_list.txt`
do
# This is where we throw our backups.
FILEDIR="$BASEBACKUP/$DATABASE"
# Test to see if our backup directory exists.
# If not, create it.
if [ ! -d $FILEDIR ]
then
mkdir -p $FILEDIR
fi
echo -n "Exporting database: $DATABASE"
mysqldump --add-drop-table -h internal-db.sXXXXX.gridserver.com -udbXXXXX -pPASSWORD $DATABASE | gzip -c -9 > $FILEDIR/$DATABASE-$DATE.sql.gz
echo " ......[ Done Exporting to local backup, now exporting for remote backup] "
cp $FILEDIR/$DATABASE-$DATE.sql.gz /home/XXXXX/data/db_backup/recent/$DATABASE.sql.gz
echo " .......[Done]"
done
# AutoPrune our backups. This will find all files
# that are "MaxFileAge" days old and delete them.
MaxFileAge=4
find $BASEBACKUP -name '*.gz' -type f -mtime +$MaxFileAge -exec rm -f {} \;
4. Change few things in above code -
- Replace all the instances of ‘XXXXX’ with your gridserver account number.
- Replace ‘PASSWORD’ with your SSH password
5. Now save this file as something like ‘db_backup.sh’
6. Open up your editor one more time, and write the names of databases you want to back up on each single line -
dbXXXXX_proj1 dbXXXXX_proj2
7. Now save this file as something like ‘db_list.txt’
8. Basically, the script pulls a list of databases to be backed up from a file called db_list.txt, this file takes 1 database name per line. It then exports the database and compresses, then saves it with a date-stamped filename to a directory called ../daily/<db_name>/.
Then, the script copies a non-date-stamped filename to a directory called ../recent/, thus overwriting the previous file stored there.
Finally it goes through the daily directory structure and deletes any files older than 4 days.
9. Now you can test your backup script by running following command -
./db_backup.sh
10. The script will echo out some progress messages. If no error message, then hopefully your databases should be backed up.
To see if it was successful execution, go to ../daily directory. You will see directories created with <db_name> names. Under these directories, you’ll see compressed version of sql dumps. Similarly, go to ../recent directory, and you’ll see the similar compressed version of sql dump.
To automate this backup process, go to your MediaTemple’s admin section of your primary domain and click the “Cron Jobs” link.
11. Click on the ‘Add a new cron job’ button.
12. Add your email address in the “Notification Email” field. This will send you emails whenever the cron job runs and will let you know if it was successful or not.
13. Also add path of your script in the “Command or script to execute” field. Enter: /home/XXXXX/data/db_backup/scripts/db_backup.sh. Again, replace ‘XXXXX’ with your gridserver account number.
14. On the same page, you can specify how often you’d like your script to run. This entire section is up to you requirements. I’ve set mine to run daily at 3:00 AM when traffic on my site is slower.
15. Click Save and you’re all set to backup your databases on daily basis!
I hope this will be useful to you. If you see any issues, please let me know in the comment section.
Startup and Entrepreneurship Resources: Thirteen key characteristics of a great startup culture
I read this fascinating article about what defines a great start-up culture?
Author Greg Gottesman has brilliantly explained following thirteen key characteristics of a great startup culture.
- No politics.
- It’s not a job, it’s a mission.
- Intolerance for mediocrity.
- Watching pennies.
- Equity-driven.
- Perfect alignment.
- Good Communication, Even in Bad Times.
- Strong leadership.
- Mutual respect.
- Customer-obsessed.
- High energy level.
- Fun.
- Integrity.
Read the original article in detail here: 13 key characteristics of a great startup culture.
Shopialize #1: Idea formalization, Product plan, and Customer development
Few days ago I mentioned about starting a new journey – building Shopialize application in the part-time. I was busy with following activities in the last week -
Getting feedback
Till last week, it was just an idea in my head and I was the only one who was excited about it. So first step was to share that idea with others and get their feedback. And as you guessed it right, I shared it with my friends and interestingly they also liked the idea very much, and they too are excited about its potential. But as we know, friends are always supportive and always give us positive feedback.
As I wrote in my previous post – what I really need is “loving critic” – someone who care deeply enough about me to give me honest feedback – both positive and negative about what I’m doing. So in next few weeks I’ll be discussing the idea with more friends and advisers (which I need to look for as well) and try to get their feedback and refine the idea as much as possible in early stages itself.
Formalizing the idea
Idea in head is of no use. It’s important to write it down and formalize it more structurally. I tried to write it’s scope, what problem it’s solving, what are its possible solutions. Interestingly, there are many ways to solve the problem I’m trying to solve. So I listed down all different solutions. But some are complex and will take lot of time and resources to build. So finally I prioritized the scope of solutions I’ll be implementing. I’ll start with comparatively simpler solution and then I’ll keep adding complex features as application grows.
Creating product plan
Once I decided which solution approach I’m taking, I’ve started listing down the product features I’ll be implementing. I know, in part-time projects you don’t want to waste time in writing down these things, but instead want to code it. But I’m taking balanced approach – I think it’s the right approach. I’ve followed user stories approach i.e. listing features based on different types of users of your application.
Customer development
I’m also working on identifying potential customers and listing down their contact details. I’m still researching about customers and trying to understand what they use currently and how can I help them by providing better solution. This effort will be ongoing. My plan is once I’ve basic prototype, I’ll contact these potential customers and will validate the idea from them.
Evaluating technology
I’ve also spent some time in evaluating the technology I’ll be using to develop this application. I’ll be using Symfony 1.2 – a PHP MVC framework and MySQL database. I’ve used Symfony 1.0 previously to develop few other applications, but Symfony 1.2 is lot different than Symfony 1.0, so there is some learning curve is involved. I could have dropped the idea of learning Symfony 1.2 and could have started coding the features right away using Symfony 1.0. But Symfony 1.2 is lot faster and better, so decided to invest some time to learn it now rather than investing more time at later stage in migrating Symfony 1.0 code base to Symfony 1.2 platform.
Tools I’m using
I’m using Pbworks application to write down everything, of course its free version. I really like Pbworks. It’s amazingly simple service with great features and usability. I’ve created many sections like – Business Development, Marketing, Product Management, and Engineering and it’s helping me a lot to organize my documentation in early stages. Though wiki might look over-kill for a one-person project, I believe that this will be useful when more team members will join me.
For project planning I’m using free version of Basecamp. I’m fan of 37Signals product and I love Basecamp’s simplicity. I use it to list down milestones and detailed tasks – and it helps me to get things done.
Next week’s action plan
The same activities will continue in the next week. Primarily Customer development and Technology development will be prime tasks. Another important task is to look for teammates and advisers. So I’m going to meet few people and going to pitch my idea to them and get their feedback and opinions. There are lots of things to work on so I’ll get back to work now.
Beta Signup
Don’t forget to signup at Shopialize for it’s beta launch. I’ll keep sharing more details on this blog so stay tuned.