I was one of the lucky ones who got my hands on a free 50 GB account on Box.com (former Box.net) with their campaign to launch their new Android app (the campaign runs until March 23, 2012). A similar campaign ran earlier with their IPhone/IPad app. Unfortunately, they don't offer a Linux sync app, so here I describe, step by step, how I did some ninja tricks in order to be able to automatically synchronize a certain directory on my harddrive with my Box.com account from my Ubuntu 11.10 (Oneiric Ocelot) installation.
If you don't feel like experimenting with this, I can recommend the fairly new similar service Copy.com which comes with a Linux sync app and gives you 15 GB for free (invite your friends and get up to 50 GB in total). If you follow this link, you'll get 20 GB initially.
The trick is this: Using WebDav you can mount your Box.com account as if it was a normal harddisc. Then, once mounted, set up an rsync script to synchronize your selected local directory with the WebDav mount. Personally, I use it to keep an always updated online backup of my family photograph directory, which tends to take up several gigabytes, and counting. Just remember, Box.com will only allow each file to take up a maximum of 100 MB for free accounts. Something similar to this procedure will also work for other services that offer WebDav connections, e.g. One.com.
This how-to might work on other versions of Ubuntu, too (maybe even on other flavours of Linux), perhaps with a few changes here and there, or it might not work for you at all, even though your setup is exactly the same as mine. Use with caution, and at your own risk. Be sure to backup your data before attempting this. But here goes...
A. Install and set up WebDav
- Open a terminal window, and install the WebDav file system package:
sudo apt-get install davfs2
- Make sure you can mount as your normal user (not just root)
sudo chmod u+s /sbin/mount.davfs sudo usermod -a -G davfs2 mylinuxusername
Of course, change "mylinuxusername" into your linux user name. - Tell the system how and where to mount the Box.com account. Edit the /etc/fstab file as root:
sudo gedit /etc/fstab
Add this line to the file:https://dav.box.com/dav /home/mylinuxusername/box.com davfs rw,user,auto 0 0
- Let the system know your Box.com user name and password to enable automatic mounting. Edit the /etc/davfs2/secrets file as root and add this line:
https://dav.box.com/dav myboxusername myboxpassword
- Tell WebDav not to use locks, as this won't work with Box.com. Edit the /etc/davfs2/davfs2.conf file as root and add this line:
use_locks 0
- Make the mountpoint (an empty directory) for the Box.com account, and mount for the first time:
cd ~ mkdir box.com mount box.com
B. Create a sync script and make it execute once an hour
- Create a script that synchronizes your local directory of choice with the Box.com account. Create a new text file somewhere which will contain the command(s) to do the sync. I suggest ~/bin/boxcomsync . Add the following lines to the file:
#!/bin/bash rsync -avr --delete /home/mylinuxusername/directorytosync/ /home/mylinuxusername/box.com/
This will put the files in the root of your Box.com account. You can also create a directory in Box.com and sync the files to there instead. If you want several local directories synced, you can repeat the rsync line for every directory. - Make the script executable:
chmod u+x ~/bin/boxcomsync
- Test your script to see if everything works as expected. Also, if you have a lot of data to sync, it is probably best to do the first run manually, so that the automated runs will only handle changes to the synced files.
~/bin/boxcomsync
- Set up a cronjob to run the sync script every hour. Run the command:
crontab -e
A text editor will appear (probably nano). Add the following line to the file which has been opened, save, and exit the editor.0 * * * * /home/mylinuxusername/bin/boxcomsync
See e.g. this guide with examples of how to set other times. Don't set it too often, though, as one run must have time to finish before another is executed.
fantastic guide worked perfectly... much appreciated
ReplyDeleteThanks a lot!!
ReplyDeleteIs working perfect and for me is very usefull. Thanks again!.
Tota
Is this work offline or we must connected to internet to access the file on box folder..?
ReplyDeleteThe sync script in the last part downloads your box files to your local harddrive and keeps them synchronized so that you can access your files even without being online. Of course, you need to be online to run the syncscript, though.
DeleteAlso remember to backup your box files before following this guide, just in case.
nice tutorial, I used it here in brasil, thanks
ReplyDeleteI wold like to know, how can I set up de speed of download and up load, it is automatic?
thanks again
The script/tutorial on this page does not take transfer speed into account. That is, it uses the full speed available to it, though of course not faster than the slowest speed on the route from your computer to the Box.com server containing your files. So, if e.g. the Box.com servers are currently slow, so will your up/download be.
DeleteI had to add the "c" parameter to rsync:
ReplyDeletersync -avrc --delete /home/mylinuxusername/directorytosync/ /home/mylinuxusername/box.com/
This causes rsync to synchronize by checksum, not by modification time. Without that, it would re-upload every file on every synchronization.
The downside: it needs longer to find the files that must be synchronized.
I had tried this. But, it gets stuck at "sending incremental file list"
DeleteIm trying to setup a remote repo on my box.com account and this is exactly what i was looking for.Many thanks!
ReplyDeleteGracias por la ayuda funcionó muy bien en Mint 13.
ReplyDeletethanks for you help, it works very well in Linux Mint 13
You may want to add a file to the Box.com mount then check for it's existence before running the rsync. I'm doing the following:
ReplyDeletefirst:
touch /mnt/Box.com/MOUNTED
Then edit ~/bin/boxcomsync to look like this
#!/bin/bash
if [ -f /mnt/Box.com/MOUNTED ];
then
echo "Box WEBDAV is mounted."
rsync -avrc --delete /mnt/Box.com/somedirectory /home/linuxusername/Box/somedirectory
else
echo "Box WEBDAV is not mounted."
fi
This works fine if you only use one machine, but if the file is not in the synced directory it DELETES it from box
ReplyDeleteThank you for mentioning this. I put a warning in the text above.
DeleteGreat solution... but... does this works both ways? If I put some new information into my Box account from another device (Cell or PC) will it refresh my local folder?
ReplyDeleteTo be honest, I haven't tested this, as my needs only includes syncing in one direction. A quick Google search reveals that it might not, though. Perhaps this can be solved using something like this suggestion: http://goo.gl/7cN5V ?
DeleteSomeone wrote a comment about how to revert this change. Unfortunately I accidentally removed the comment. He/she wasn't able to boot the computer after following this guide.
ReplyDeleteAs far as I can see this must be caused by the system trying to unsuccessfully mount the box drive at boot time. To disable this, you need to remove the added line from /etc/fstab. This is of course hard to do if you can't boot the computer, but it's not impossible.
Booting into Ubuntu's Recovery Mode (see e.g. http://goo.gl/7k3fr) should allow you to do this. If not, try booting the computer as long as it gets to, then see if you can ssh into it from another computer. Otherwise you might need to physically connect the harddisk to a working computer and do the change from there.
Works perfectly for me!
ReplyDeleteThanks :)
ohhh Fine info
ReplyDeleteAlso visit my homepage - analytics
Server webdav address has changed. You must replace:
ReplyDeletehttps://www.box.com/dav
for this
https://dav.box.com/dav
give me also for dropbox
ReplyDeleteHi-
ReplyDeleteWorks for me!
But then, How to send a email out with the URL to the file location from the Ubuntu server..
Any inputs on this.. ?
Looks like the Box URL has changed to https://dav.box.com/dav, if you wish to keep this post current. Thanks!
ReplyDeletePlease give Box URL . https://dav.box.com/dav URL not working.
ReplyDeleteWhen i tried to login with credentials, i got the XML with exception given below :
Sabre_DAV_Exception_NotImplemented
GET is only implemented on File objects
i was getting an error, the way i solved it is...
ReplyDeletesudo chmod 600 /etc/davfs2/secrets
i couldnt mount the box.com place...