Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track folder changes / Dropbox changes

First of: I know of pyinotify.

What I want is an upload service to my home server using Dropbox.

I will have a Dropbox's shared folder on my home server. Everytime someone else, who is sharing that folder, puts anything into that folder, I want my home server to wait until it is fully uploaded and move all the files to another folder, and removing those files from the Dropbox folder, thus, saving Dropbox space.

The thing here is, I can't just track for changes in the folder and move the files right away, because if someone uploads a large file, Dropbox will already start downloading and therefore showing changes in the folder on my home server.

Is there some workaround? Is that somehow possible with the Dropbox API?

Haven't tried it myself, but the Dropbox CLI version seems to have a 'filestatus' method to check for current file status. Will report back when I have tried it myself.

like image 774
cherrun Avatar asked Sep 09 '12 11:09

cherrun


2 Answers

There is a Python dropbox CLI client, as you mentioned in your question. It returns "Idle..." when it isn't actively processing files. The absolutely simplest mechanism I can imagine for achieving what you want would be a while loop that checked the output of dropbox.py filestatus /home/directory/to/watch and performed an scp of the contents and then a delete on the contents if that suceeded. Then slept for five minutes or so.

Something like:

import time
from subprocess import check_call, check_output
DIR = "/directory/to/watch/"
REMOTE_DIR = "user@my_server.com:/folder"

While True:
    if check_output(["dropbox.py", "status", DIR]) == "\nIdle...":
        if check_call(["scp", "-r", DIR + "*", REMOTE_DIR]):
            check_call(["rm", "-rf", DIR + "*"])
    time.sleep(360)

Of course I would be very careful when testing something like this, put the wrong thing in that second check_call and you could lose your filesystem.

like image 107
aychedee Avatar answered Oct 03 '22 09:10

aychedee


You could run incrond and have it wait for IN_CLOSE_WRITE events in your Dropbox folder. Then it would only be triggered when a file transfer completed.

like image 41
user1664174 Avatar answered Oct 03 '22 08:10

user1664174