In my opinion it is not necessary to backup the Google Docs in case of a hard disk crash on the site of Google, but I like to have my documents on my own server also. Just in case of a blocked account or when internet is temporary unavailable.
Download and unpack gdatacopier and gdata-python-client
Remark: Please check if there are newer versions available for gdata-python-client or gdatacopier.
Type the following commands in a console:
$ cd
$ wget http://gdatacopier.googlecode.com/files/gdatacopier-2.1.2.tgz
$ wget http://gdata-python-client.googlecode.com/files/gdata-2.0.13.tar.gz
Unpack them with:
$ tar xzf gdata-2.0.13.tar.gz
$ tar xzf gdatacopier-2.1.2.tgz
Install gdata-python-client
Before installing check for the ElementTree module in Python:
$ python
>>> from xml.etree import ElementTree
If no error is returned, the ElementTree module is available in Python, otherwise check the INSTALL.txt file in the gdata-2.0.13 directory.
Now we are going to install the gdata-python-client in your home directory or like in my case, the /usr/local/sbin directory:
$ cd gdata-2.0.13
$ sudo python setup.py install --home=/usr/local/sbin
$ cd ..
Add the PYTHONPATH environment var to bashrc, so that the gdatacopier scripts can find it:
$ vi /etc/bash.bashrc
PYTHONPATH=/usr/local/sbin/lib/python
export PYTHONPATH
Install gdatacopier
Now we are going to copy the gdatacopier scripts to the /usr/local/sbin/lib/python directory:
$ sudo cp -r gdatacopier-2.1.2 /usr/local/sbin/lib/python
$ cd /usr/local/sbin/lib/python
$ sudo ln -s gdatacopier-2.1.2 gdatacopier
The following commands are now available in the gdatacopier directory:
- gcp.py (man page gcp)
- gls.py (man page gls)
- gmkdir.py
- gmv.py
- grm.py
Example for using gcp.py:
$ /usr/local/sbin/lib/python/gdatacopier/gcp.py -p 'your_password' your_username@gmail.com:/* ~/GoogleDocsBackup/
Daily backup script
The following script will backup all your documents to the docs directory and the spreadsheets to the sheets direcory.
$ vi /usr/local/sbin/backup_googledocs
#!/bin/bash
PYTHONPATH=/usr/local/sbin/lib/python
export PYTHONPATH
USERNAME=your_username
PASSWORD='your_password'
GCP=/usr/local/sbin/lib/python/gdatacopier/gcp.py
LOG_FILE=/tmp/backup_googledocs.log
RETVAL=0
# Backup the spreadsheets from Google Docs
$GCP -o -p $PASSWORD -f xls $USERNAME@gmail.com:/sheets/* /home/user/Nas/GoogleDocsBackup/sheets > $LOG_FILE
if [ $? -ne 0 ]
then
echo "backup_googledocs: gcp.py returned an error while copying docs" >> $LOG_FILE
RETVAL=1
fi
# Backup the documents from Google Docs
$GCP -o -p $PASSWORD -f doc $USERNAME@gmail.com:/docs/* /home/user/Nas/GoogleDocsBackup/docs >> $LOG_FILE
if [ $? -ne 0 ]
then
echo "backup_googledocs: gcp.py returned an error while copying docs" >> $LOG_FILE
RETVAL=1
fi
if [ $RETVAL -ne 0 ]; then
echo "backup_googledocs: ERROR detected while backuping Google Docs, send a mail to report this!" >> $LOG_FILE
mail -s "The backup of Google Docs failed" $USERNAME@gmail.com $LOG_FILE < $LOG_FILE
exit 1
else
echo "backup_googledocs: No ERROR detected while backuping Google Docs" >> $LOG_FILE
mail -s "The backup of Google Docs was successful" $USERNAME@gmail.com < $LOG_FILE
# mail -s "The backup of Google Docs was successful, logfile included" $USERNAME@gmail.com $LOG_FILE
exit 0
fi
$ chmod +x backup_googledocs
Automatically run the script every day (on Ubuntu)
To execute the script every day, it is possible to do that easily in Ubuntu:
$ cd /etc/cron.daily
$ sudo ln -s /usr/local/sbin/backup_googledocs
Now all your Google Docs will be backuped every day to your own machine.