Ubuntu One Backup

A couple of weeks ago I was looking for a backup solution for my MySQL databases. As I don’t want to spend money on this, I chose to backup using one of the cloud drives available around. I already use Google Drive for my companies’ files and Dropbox for my personal needs. In order to keep each thing in it’s own place, I decided to use Ubuntu One to host my backups.

You can find this project on GitHub: https://github.com/oscardias/u1backup

How to

The class code is defined in u1backup.php and a simple usage example is at backup.php. You can (should) create a cron job to execute your version of backup.php in a regular basis.

What it does

The class made available here will dump your MySQL databases (one or more) and save them into a folder (defined by you – test if the script can write to this folder).

Next, it will connect to Ubuntu One using the credentials you provide. If it’s the first time running the script, it will create a file named u1backup with the token information from Ubuntu One.

When you execute it a second time, the token info will be already available and the script won’t authorize itself twice (unless you delete the file u1backup).

Finally, the files will be uploaded to Ubuntu One using OAuth PUT.

What you need

Besides setting things up in the script, you need PHP’s OAuth. After you have it installed, remember that this script will run in CLI, which meand you need to enable OAuth in php.ini for CLI (it’s a different file than Apache’s).

PHPClasses

PHPClasses winnerThis project won the September 2013 innovation award of PHPClasses. Check the website: www.phpclasses.org/package/8269-PHP-Send-MySQL-database-backup-files-to-Ubuntu-One.html

References

Most of this code came from the web, so these are the sources: