logo

How to back up Dropbox automatically – daily, weekly, monthly snapshots

logo

Dropbox is great. Most of the time. It’s great when I need to easily share files with people while working on a project together. It keeps files in sync between multiple computers, and is the only solution I’ve found so far which works seamlessly and instantaneously. If you don’t already use it, I highly recommend it.

Dropbox - Online file backup and sharing

Dropbox - Online file backup and sharing

I’ve recently been having problems with Dropbox ever since joining a shared folder which overflowed my quota. Completely unrelated files mysteriously disappeared. Luckily I had a snapshot from before I had joined the folder and was able to restore the files.

This prompted me to set up a proper backup system which makes snapshots daily, weekly and monthly.

This guide assumes you have a Linux server somewhere with no GUI.

First, follow the Dropbox wiki instructions for installing Dropbox on Linux. The process is relatively painless, and seems to just work. At the end, you’ll end up with a “Dropbox” folder in your home folder. This folder will always have the latest version of your files.

The next step is to take snapshots of that folder at regular intervals. I chose to keep 7 days of daily snapshots, 4 snapshots taken weekly, and 12 taken monthly. In theory, this should give me access to any files I’ve accidentally deleted within the past year.

This script will run rsync to clone the Dropbox folder into snapshot folders which will be overwritten over time, so you will only end up with 7+4+12 copies of your Dropbox folder. Save this code to a file called backup.sh or whatever you want, and make it executable (chmod 755 backup.sh).

backup.sh:

#!/bin/bash
 
# Makes daily snapshots in folders like "daily-4-Thu", "daily-5-Fri"
if [[ "$1" == "daily" ]]
then
        path=daily-`date +%u-%a`
fi
 
# Makes weekly snapshots in folders like "weekly-1" where 1 is the day of the month
if [[ "$1" == "weekly" ]]
then
        path=weekly-`date +%d`
fi
 
# Makes  monthly snapshots in folders like "monthly-04-Apr"
if [[ "$1" == "monthly" ]]
then
        path=monthly-`date +%m-%b`
fi
 
# Run with "go" as the second CLI parameter to actually run the rsync command, otherwise prints the command that would have been run (useful for testing)
if [[ "$2" == "go" ]]
then
        rsync -avz --delete /home/aaron/Dropbox /home/aaron/aaron/Dropbox-Backup/$path
else
        echo rsync -avz --delete /home/aaron/Dropbox /home/aaron/Dropbox-Backup/$path
fi

Add these lines to your crontab to run the backup script at the appropriate intervals. This will run the daily script every night at 1am, the weekly script on the 4th, 12th, 20th and 28th days of the month at 1:30am, and the monthly script on the 1st of the month at 2am.

crontab:

0 1 * * * /home/aaron/backup.sh daily go
30 1 4,12,20,28 * * /home/aaron/backup.sh weekly go
0 2 1 * * /home/aaron/backup.sh monthly go

Hopefully this saves you some headaches down the road when Dropbox decides to play tricks on you.

4 Responses to “How to back up Dropbox automatically – daily, weekly, monthly snapshots”

  1. Kenn says:

    Better yet, run something like rsnapshot on the Linux machine. It uses hard links so you only have to store one full copy plus incrementals rather than 23 full copies. You can back up remote machines with it too.

  2. [...] I recently acquired a 6 TB Seagate NAS drive which I am using for nightly backups of my servers, as well as snapshots of several Dropbox accounts. [...]

  3. Incredible! This is certainly such a good in-depth write-up and yes it appears that you really did the research. I really value the time and effort you have offered to this article. I’m looking forwards for the subsequent post. Thanks

  4. Hello. Fantastic job. I did not expect this. This really is a exceptional articles. Thanks!

  5. Robert Karen says:

    I am also using a Dropbox and same happens with me so it will be great help for me through this post.

logo
logo
Powered by WordPress | Designed by Elegant Themes