Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to zip a folder and upload to my dropbox from Ubuntu shell. I intend to use this as a backup solution, so it would also be nice to run everyday and replace the older file.. If dropbox doesn't allow this what other cloud services you think it would work?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

Zipping and moving files

The following will zip the directory foo in your home folder to a file called backup.zip, which will also be stored in your home folder.

zip -r ~/backup.zip ~/foo

Now, all you have to do is move that file to your Dropbox:

mv ~/backup.zip ~/Dropbox/

If the backup file already exists, mv will overwrite it without prompting you, so be aware of that.


Automating it

You can put that in a script file, maybe call it backup.sh and store it in your home folder.

#!/bin/bash
zip -r ~/backup.zip ~/foo
mv ~/backup.zip ~/Dropbox/

That's it. If you rather want to keep your old versions, you can timestamp the created file by executing the date command before:

#!/bin/bash
d=$(date +"%Y-%m-%d") # => this returns 2012-03-25, for example
zip -r ~/backup-$d.zip ~/foo
mv ~/backup-$d.zip ~/Dropbox/

Now, in your command line, make that file executable:

chmod +x ~/backup.sh

The only thing you have to do to add this to a schedule is edit your crontab:

EDITOR=nano;crontab -e

Add the following line:

0   15  *   *   *   ~/backup.sh >/dev/null

Press Ctrl-O and enter to save. Your backup will now run at 15:00, every day. For more options, check out Wikipedia's article on Cron.

share|improve this answer
    
I would also suggest that if you want to keep a backup history (which is typically the good thing to do), you can have the script timestamp the .zip file and clean out older versions, if desired. –  Ben Richards Jun 7 '12 at 21:25
    
True, I added an example. –  slhck Jun 7 '12 at 21:30
    
@slhck perfect, thanks! –  Francisco Costa Jun 7 '12 at 22:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.