Internet Defense League script

29 February 2012

How to set up autosync on Ubuntu

I was one of the lucky ones who got my hands on a free 50 GB account on (former 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 account from my Ubuntu 11.10 (Oneiric Ocelot) installation.

Note: Use with caution and make a backup of your data before attempting this. Especially be careful if adding more than one computer to the same Box account. The last added computer might convince rsync that there are no files, and thus delete files that are already on your Box account.
If you don't feel like experimenting with this, I can recommend the fairly new similar service 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 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, 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.

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

  1. Open a terminal window, and install the WebDav file system package:
    sudo apt-get install davfs2
  2. 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.
  3. Tell the system how and where to mount the account. Edit the /etc/fstab file as root:
    sudo gedit /etc/fstab
    Add this line to the file: /home/mylinuxusername/ davfs rw,user,auto 0 0
  4. Let the system know your user name and password to enable automatic mounting. Edit the /etc/davfs2/secrets file as root and add this line:    myboxusername    myboxpassword
  5. Tell WebDav not to use locks, as this won't work with Edit the /etc/davfs2/davfs2.conf file as root and add this line:
    use_locks 0
  6. Make the mountpoint (an empty directory) for the account, and mount for the first time:
    cd ~

B. Create a sync script and make it execute once an hour

  1. Create a script that synchronizes your local directory of choice with the 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:
    rsync -avr --delete /home/mylinuxusername/directorytosync/ /home/mylinuxusername/
    This will put the files in the root of your account. You can also create a directory in and sync the files to there instead. If you want several local directories synced, you can repeat the rsync line for every directory.
  2. Make the script executable:
    chmod u+x ~/bin/boxcomsync
  3. 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.
  4. 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.


  1. fantastic guide worked perfectly... much appreciated

  2. Thanks a lot!!
    Is working perfect and for me is very usefull. Thanks again!.


  3. Is this work offline or we must connected to internet to access the file on box folder..?

    1. The 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.

      Also remember to backup your box files before following this guide, just in case.

  4. nice tutorial, I used it here in brasil, thanks
    I wold like to know, how can I set up de speed of download and up load, it is automatic?

    thanks again

    1. 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 server containing your files. So, if e.g. the servers are currently slow, so will your up/download be.

  5. I had to add the "c" parameter to rsync:

    rsync -avrc --delete /home/mylinuxusername/directorytosync/ /home/mylinuxusername/

    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.

    1. I had tried this. But, it gets stuck at "sending incremental file list"

  6. Im trying to setup a remote repo on my account and this is exactly what i was looking for.Many thanks!

  7. Gracias por la ayuda funcionó muy bien en Mint 13.

    thanks for you help, it works very well in Linux Mint 13

  8. You may want to add a file to the mount then check for it's existence before running the rsync. I'm doing the following:


    touch /mnt/

    Then edit ~/bin/boxcomsync to look like this


    if [ -f /mnt/ ];
    echo "Box WEBDAV is mounted."
    rsync -avrc --delete /mnt/ /home/linuxusername/Box/somedirectory

    echo "Box WEBDAV is not mounted."

  9. This works fine if you only use one machine, but if the file is not in the synced directory it DELETES it from box

    1. Thank you for mentioning this. I put a warning in the text above.

  10. Great 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?

    1. To 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: ?

  11. Someone 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.

    As 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. 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.

  12. Works perfectly for me!
    Thanks :)

  13. ohhh Fine info

    Also visit my homepage - analytics

  14. Server webdav address has changed. You must replace:

    for this

  15. give me also for dropbox

  16. Hi-

    Works 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.. ?

  17. Looks like the Box URL has changed to, if you wish to keep this post current. Thanks!

  18. Please give Box URL . URL not working.
    When i tried to login with credentials, i got the XML with exception given below :

    GET is only implemented on File objects

  19. i was getting an error, the way i solved it is...
    sudo chmod 600 /etc/davfs2/secrets
    i couldnt mount the place...