Streamlined My Digital Life, Here Here!

So, I feel like I accomplished a lot this weekend… Not that many would care, but for those of you interested in backing up your godaddy shared hosting accounts, or for those interested in streaming media at home, this is what I did:

  • First, I got my mini-mac server up and running as both an FTP server and a Rivet Streaming server for myself. This also included hooking my phone into Magic Jack through this server so I don’t have to pay attention to all their ad streaming on my own personal computer
  • I then installed Jenkins-CI to manage backing up my GoDaddy databases, files; all stored on my private FTP folders, so I can manage and access these backups at any time. This includes the awesome crontab like scheduling available in Jenkins-CI, to back my sites up 2 times a day
  • By the way, it just feels so damn good to not have to manage this stuff anymore, just keep an eye on it and make sure that: a.) My TV Shows and Movies through digital backups remain available, b.) Phone stays on, c.) Sites get backed up a couple times a week!!!

Finally, I still have more stuff to do, but luckily this is a very short list. I would like to install the same backup mechanisms on my other web servers to make sure my site databases are backed up on an hourly (or so) basis. These sites have more users than my godaddy sites and they are more dynamic in nature. So I will be doing this next weekend.

Last, but not least, if you would like me to post any of the specific information listed above like techniques or software used, then let me know and I’ll be sure to post about it!

Backup Mysql Database on GoDaddy

Assumptions: You are trying to back up MySQL Databases on a GoDaddy Shared Linux package where you have access to SSH and know what your credentials are. If you know either of these, but are unsure of how to get to it, check out this article first: Enabling SSH on your Godaddy Account.

Here are the steps we will use to back up a MySQL database on GoDaddy:

  1. SSH To your GoDaddy Account
  2. Make a directory to store your script
  3. Write the script
  4. Change the script to executable
  5. Execute the script
  6. Verify your backup was created

It’s easy to know that you should run backups on a normal basis, and as my web presence grows and I continue gaining more information (i.e. this example here), then it becomes more important to make sure I don’t lose this information. If you are here, you probably have or know the reasons for completing these steps.

SSH’ing to your GoDaddy Account:
I complete this step with my Unix Mac, but if you are on Windows, you may want to try Putty or some other interface for SSH’ing. For Mac’s, it’s as easy as:


If prompted to accept a certificate, type yes and hit enter, and then put in the password for your GoDaddy Shared Hosting SSH Login.

Make a directory to store your scripts:
This is debatable as to how you want to do this, I created a directory for my scripts and a directory for my backups.

mkdir -p site_backups/scripts
mkdir -p site_backups/databases

Note: Some of this upcoming tasks depend on the location of the database directory, so make sure you remember where that is.

Write the script:
This you can do however you want, I chose to use an ftp editor and save it in my local git repository and then I upload it to the server. Here are the contents of the script that I create. To complete this script, you will want to log into your GoDaddy hosting account and and go to Databases -> MySQL, and click the little pencil button. That should give you everything you need except your password. Here is what you need:

  • Database Name: DBNAME
  • Database Host: DBHOST
  • Database Password: DBPASSWORD

Below is the contents of the bash script. This script generates a database backup in the previously created directory, and down one more directory to the DBNAME, with a time stamp that drills down to the minute. I have somewhat modulated this script because I have several backups. It could even be more modular, and as you mature this script, you should keep that in mind. Additionally, telling me what you did as a comment here may help others, so feel free to coment.



function create_directory {
	if [ ! -d "$1" ]; then
	    mkdir -p "$1"

function execute_command {
	$1 | gzip > $2`date '+%m-%d-%Y_%H-%M'`.sql.gz

# hurlme_main

COMMAND="mysqldump --add-drop-table -h $DBHOST -u $DBNAME -p$DBPASSWORD $DBNAME"

echo "Creating directory if it doesn't exist: $BACKUPLOCATION"
create_directory "$BACKUPLOCATION"
echo "Executing $DBNAME backup..."
execute_command "$COMMAND" "$BACKUPLOCATION"

Make this script above executable:
You can do this via FTP or SSH, pick your flavor and change the script permissions to 700. Via ssh, you can do it:
IMPORTANT: If you put your passwords and locations in this file, be weary to make sure you can’t access it via the public web. It is helpful to make sure this ISN’T in your HTML directory

ssh my_user@myresource
cd site_backup/scripts
chmod 700

Execute and verify your script ran properly:
Here, I am just chaining off of the above, so I am ssh’ed into my directory and executing the script directly:

ll ../databases/DBNAME
-->  inetuser  2388 Mar 27 15:01 03-27-2011_15-01.sql.gz

The 2388 symbolizes the size of the database, If this is very small, like 20, then you probably haven’t got a good back up. For sakes sake, I would restore this to a local database or manually view the SQL to make sure it has done exactly what you wanted it to do.

Now, we must look at our next steps. Some people use CRONTAB to complete a schedule of scripts and you can do this easily right in your home directory. I, however, like to manage everything using Jenkins or any web based solution that makes this stuff easier to remember as I am very forgetful. We will look at this in an upcoming article. Until then, feel free to make suggestions and improve my solution and share it with all of us in the comments.

Using CakePHP with Godaddy

I was able to setup CakePHP on godaddy, the most frustrating part I dealt with was the wild goose chase I was sent on by Google trying to figure it out.

  1. Add Options +FollowSymlinks to three .htaccess files
  2. Add RewriteBase /path/to/app to the /.htaccess file

I first set my site up to work on a sub-directory for practice as the site was already live. When I did this, I set RewriteBase /test (where my directory was test).

Here are the three .htaccess files:

  • base_directory/.htaccess (this was /test while I was setting it up, and / after I moved it later)
    <IfModule mod_rewrite.c>
    	 Options +FollowSymlinks
       RewriteEngine on
    	 RewriteBase /
       RewriteRule    ^$ app/webroot/    [L]
       RewriteRule    (.*) app/webroot/$1 [L]
  • webapp/.htaccess
    <IfModule mod_rewrite.c>
        Options +FollowSymLinks
        RewriteEngine on
        RewriteRule    ^$    webroot/    [L]
        RewriteRule    (.*) webroot/$1/    [L]
  • /app/webroot/.htaccess
    <IfModule mod_rewrite.c>
        Options +FollowSymLinks
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
  • For what it’s worth, I would just complete the first step and see if this suffices (the .htaccess in the application root). I had already changed the latter two files, and didn’t feel like going back and editing them, just in case it might have caused a new headache

After these few changes, it was a breeze really. I just wish I hadn’t been sent on the proverbial wild goose chase for this 2 lines of code that got this app working.

© 2012 - Jeff Ancel
Wordpress Themes
Scroll to Top