
When it comes to cheap and secure off-site backup and storage, few services can beat Amazon S3. And if you want to easily back up your OpenOffice.org documents on Amazon S3, you can do so using a simple OpenOffice.org Basic macro and the s3cmd utility (http://s3tools.logix.cz/s3cmd). First of all, you have to install the s3cmd tool on your system. Download the latest version of s3cmd, unpack it, switch to the resulting directory in the terminal, and run the python setup.py install command as root. Run then the s3cmd –configure command to configure the utility. Next, you have to create a so-called bucket — a repository on the Amazon S3 servers for storing your files and documents — using the s3cmd mb s3://BUCKET command, where BUCKET is a unique name for your bucket (e.g., d3b84nm_126d9sp5gg8). Once s3cmd is configured and ready to go, you start working on an OpenOffice.org macro that backs up the currently opened document on Amazon S3 via s3cmd. The macro starts with obtaining the currently active document and checking whether it has already been saved. The latter is required to obtain the path to the document:
ThisDoc=ThisComponent
If ThisDoc.hasLocation=False Then
MsgBox (”You have to save to document first!”, 16, “Attention!”) :End
End If
Next, the macro saves all unsaved changes in the document and obtains its path:
If ThisDoc.isModified Then
ThisDoc.storeAsURL(ThisDocURL, Args)
End If
DocPath=ConvertFromURL(ThisDoc.getURL())
To upload a file to Amazon S3, s3cmd uses the put command which has the following format:
s3cmd put /path/to/file s3://BUCKET
The path/to/file part refers to the file or document you want to upload, while BUCKET refers to a bucket on Amazon S3. So to construct the command that uploads the current OpenOffice.org document, the macro simply inserts the obtained DocPath value in a string which is then passed to the Shell routing:
PutCommand=”put ” & DocPath & ” s3://d3b84nm_126d9sp5gg8″
Shell(”s3cmd”, 1, PutCommand)
Here is the entire macro in all its beauty:
Sub AmazonS3Backup()
ThisDoc=ThisComponent
If ThisDoc.hasLocation=False Then
MsgBox (”You have to save to document first!”, 16, “Attention!”) :End
End If
If ThisDoc.isModified Then
ThisDoc.storeAsURL(ThisDocURL, Args)
End If
DocPath=ConvertFromURL(ThisDoc.getURL())
PutCommand=”put ” & DocPath & “s3:// d3b84nm_126d9sp5gg8″
Shell(”s3cmd”, 1, PutCommand)
End Sub
Being a Linux user, I tested this solution on Ubuntu and Sidux. If you had luck making it work on other platforms, share your experiences with other users in the comments area.
by Dmitri Popov of Nothickmanuals.info