Recently I’ve been working on a mechanism to mirror a dataset from a local filesystem to Google Nearline cloud storage in an encrypted format. The costs are really the compelling factor. While I could buy some hard drives and put them at another location (called the colo-buddy system!) it just made sense to not have to deal with the logistics, maintenance, power, network, etc…

Of course being me, it’s a PHP cli script, because well – me. If you’re looking for something like this feel free to use and modify to your purposes. This one is built for Linux but it wouldn’t be terribly hard to port it to Windows.

Note that the first step will be to install gsutil which is provided by Google. They have all the documentation on that front. Once it’s working you will want to create your nearline bucket for storage. Make sure you specify the storage type of NL (nearline) and the data center where you want to host it. For me, something like:

gsutil mb -C NL -p backup-storage-3144254 -l US-CENTRAL1 gs://offline-storage

Of course you will have to change offline-storage to the name you want your bucket to have (and note these names are unique across all of google’s customers so you have to come up with something no one else is using.) The -p parameter is your project and you can get that from your cloud account portal.

Next is the script. The basic syntax is simply:

gbackup -d /usr/local/files -u gs://offline-storage

The script will first download all the files at the URL specified and directory as labelled (so a gsutil ls -l gs://offline-storage/usr/local/files/**) and then compare that against all the files in that directory to see if the local file is newer or if the file doesn’t exist. Then the copying begins.

In the script below you will want to set variables for:

  • $key – the location of your aescrypt cipher
  • $aescrypt – the location of your aescrypt executable
  • $gsutil – the location of gsutil
  • $workingdir – the directory to use for temp files created from encrypted copies (aescrypt output)

I’m still copying about 1.5TB of data. (Need to add pthread support because this is well… not fast.) However after some testing I’ll report back on the final costs. (Note, google charges pennies for just about everything you do. Class A requests, storage, early deletion… etc etc etc.)

In otherwords YMMV. Best of luck!