Using @Rat2000's suggestion, I did this. In one terminal,
while true; do dropbox status; sleep 1; done;
In another terminal:
touch ~/Dropbox/test
The first terminal shows approximately the following output:
Idle
Idle
Idle
...
...
Updating (1 file)
Indexing 1 file...
Updating (1 file)
Indexing 1 file...
...
...
Downloading file list...
Downloading file list...
...
...
Idle
Idle
So we can define a script, using expect
, to do a one-time dropbox sync at controlled times, assuming that the dameon does not report "Idle" until it has finished syncing.
Edit:
This solution seems to work for me:
#!/usr/bin/python
import subprocess, time, re
print "Starting dropbox daemon"
print subprocess.check_output(['dropbox', 'start'])
started_sync = False
conseq_idle = 20
while True:
status = subprocess.check_output(['dropbox', 'status'])
print status
if re.search("Updating|Indexing|Downloading", status):
started_sync = True
conseq_idle = 20
elif re.search("Idle", status):
conseq_idle-=1
if not conseq_idle:
if started_sync:
print "Daemon reports idle consecutively after having synced. Stopping"
time.sleep(5)
else:
print "Daemon seems to have nothing to do. Exiting"
subprocess.call(['dropbox', 'stop'])
break
time.sleep(1)
Notes:
Depending on your Dropbox release you might have to replace
elif re.search("Idle", status):
with
elif re.search("Up to date", status):
To reduce the impact on system performance you can experiment with utilities such as nice, ionice, and nocache, e.g.:
print subprocess.check_output(['nice', '-n10', 'ionice', '-c3', 'nocache', 'dropbox', 'start'])
Setting the script up with anacron
Of course, I schedule this script to run via anacron, like this:
1 10 dropbox_do_sync su myuser -p -c "python /home/myuser/scripts/dropbox_do_sync.py" >> /home/myuser/logs/anacron/dropbox_do_sync
Dropbox currently does not support syncing folders outside the Dropbox folder, according to their web site.
However you can achieve this by creating a symbolic link
between the Dropbox folder and the other folder you want sync, using this command:
sudo ln -s ~/Dropbox **/path/to/another/folder**
So when you go inside /path/to/another/folder
, you will be taken into ~/Dropbox
Make sure the other folder is accessible after linking.
Best Answer
You can control the Dropbox daemon by using
dropbox
with thestart
andstop
command. Typedropbox help
to view the full list of available commands.