1

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?

1 Answer 1

4

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.

2
  • 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. Commented Jun 7, 2012 at 21:25
  • True, I added an example.
    – slhck
    Commented Jun 7, 2012 at 21:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .