Users of QNAP NAS devices have been asking for an out-of-the-box solution to backup to Rackspace Cloud Files for a few years now. There is already a tool in the QNAP Web UI for backing up your shares to Amazon S3, Elephant Drive, or Symform.

The best solution I have so far is utilizing Pyrax, the Python SDK for Rackspace public cloud. The cf_pyrax script makes use of the sync_folder_to_container function found in Pyrax to sync a directory to a Cloud Files container. Even though the QNAP NAS is Linux-based, a lot of the usual methods for installing packages and scheduling jobs do not apply.

Here is what I did to configure my QNAP TS-419P II for a scheduled backup to Rackspace Cloud Files.

Install Python 2.7

Navigate to the QNAP web interface and install the Python v2.7 .qpkg from the App Center.

Verify the Installation

Verify that Python 2.7 was successfully installed:

python --version

Install PIP

Install PIP 1.2.1:

curl -o https//:pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz
tar xvfz pip-1.2.1.tar.gz
cd pip-1.2.1
python setup.py install

If you get "ImportError: No module named setuptools", install setuptools first:

wget https://pypi.python.org/packages/source/s/setuptools/setuptools-1.0.tar.gz --no-check-certificate
tar xf setuptools-1.0.tar.gz
cd setuptools-1.0
python setup.py build
python setup.py install

Install Pyrax

I had some issues with the NAS running out of room on tmpfs when installing Pyrax so provide a cache path with ample space:

pip install pyrax --download-cache /share/path/to/directory

Grab the cf_pyrax.py script from https://github.com/Linuturk/www.onitato.com/blob/master/cf_pyrax.py

Create a Credentials File

Create a credentials file with the following info:

[rackspace_cloud]
username = myusername
api_key = myapikey

Test Sync

Your syntax to sync to a specific container should be as follows:

python cf_pyrax.py TestContainer1 /share/MD0_DATA/testshare1 DFW /share/MD0_DATA/credentials.txt

Edit Crontab

After ensuring that the sync works properly, setup a cron job to backup your shares at a desired time.

QNAP overwrites crontab with etc/config/crontab after every system reboot/shutdown. You must modify this file if you want new cron job entries to stick:

echo "1 4 * * * python cf_pyrax.py TestContainer1 /share/MD0_DATA/testshare1 DFW /share/MD0_DATA/credentials.txt" >> /etc/config/crontab
echo "1 4 * * * python cf_pyrax.py TestContainer2 /share/MD0_DATA/testshare2 DFW /share/MD0_DATA/credentials.txt" >> /etc/config/crontab
crontab /etc/config/crontab


Comments

comments powered by Disqus