# Back-ups uploaden naar Dropbox met crontab en dropboxd

**URL:** <https://meta.discourse.org/t/upload-backups-to-dropbox-with-crontab-and-dropboxd/176982>\
**Category:** Sysadmins\
**Tags:** how-to\
**Created:** [22 januari 2021 om 20:59 UTC](https://meta.discourse.org/t/upload-backups-to-dropbox-with-crontab-and-dropboxd/176982 "2021-01-22T20:59:47Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Ivan\_Rapekas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ivan_rapekas/32/248924_2.png) [@Ivan\_Rapekas](https://meta.discourse.org/u/Ivan_Rapekas)\
**Post date:** [22 januari 2021 om 20:59 UTC](https://meta.discourse.org/t/upload-backups-to-dropbox-with-crontab-and-dropboxd/176982/1 "2021-01-22T20:59:47Z")

</div>

Dropbox has an advantage - it syncs a new backup as soon as it appears in the system. The deal is to put new backup to your local Dropbox folder (with a cron script provided).

**Before you proceed** you have to know:

1. You may use Dropbox to store files as much as your plan allows.
2. You may connect up to 3 devices to Dropbox at free plan (for Android devices this limitation can be bypassed, by the way).
3. When you will run dropbox to your linux server, then you need to synchronizethe only one folder. Or as Dropbox a two-way solution, it may populate your server with all data from the cloud. This can eat space on your server.
4. You have to create an additional rsync script to sync between Discourse backup folder and local Dropbox backup folder. This requires **double space** for backups. Earlier Dropbox allowed symlinks but currently this feature is not available.
5. To access your backups you don’t need root grants, but I run dropbox daemon as root in this guide (probably unsafe, welcome to improve)

**First** you need to setup backups in Discourse at `/admin/site_settings/category/backups` (my custom values in brackets)

maximum backups (3) - this manages how many files will retain in Dropbox  
 backup frequency (1) - everyday  
 backup time of day (3:30 UTC) - default  
 backup gzip compression level (6) - choose between compress speed (1) or less size (9), but in case of VPS your host provider my restart your server in case of long high CPU utilization

**Second** connect your server to Dropbox with shell commands ( **important** : because I run the service as root, I am _logged as root_ at this step - so you may try your regular user):

```plaintext
cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
# directory .dropbox-dist will be created
# run dropbox daemon
sh ~/.dropbox-dist/dropboxd

```

When you first use Dropbox at your server you will see **a uniq weblink**. You need to copy and paste it to web browser and follow the instructions. After that a directory Dropbox will be created in your home folder. Official Dropbox recommends to download [Python script](https://www.dropbox.com/download?dl=packages/dropbox.py) to manage your daemon. I don’t use it.

Commands to manage the daemon:

```plaintext
dropbox status
dropbox start
dropbox stop

```

> **Check your autostart script has been created (click to expand hidden text):**
>
> ```plaintext
> #cat /etc/systemd/system/dropbox.service
> 
> [Unit]
> Description=Dropbox Service
> After=network.target
> 
> [Service]
> ExecStart=/bin/sh -c '/usr/local/bin/dropbox start'
> ExecStop=/bin/sh -c '/usr/local/bin/dropbox stop'
> PIDFile=/root/.dropbox/dropbox.pid
> User=root
> Group=root
> Type=forking
> Restart=on-failure
> RestartSec=5
> StartLimitInterval=60s
> StartLimitBurst=3
> 
> [Install]
> WantedBy=multi-user.target
> 
> ```

 ![discourse-dropbox](https://global.discourse-cdn.com/meta/original/3X/d/d/dd5ea3dc2beea5ed5673630e8433fcc45642c50e.png)

> Discourse provides backup files and it manages their number and the frequency.  
> Crontab rsync task copies new backup to local Dropbox folder.  
> After that Dropbox uploads new file to the cloud.  
> When next night Discourse removes old backup file, rsync removes it from Dropbox as well.

**Third** create dropbox folder for backup copies:

```plaintext
mkdir ~/Dropbox/backups

```

**Fourth** prepare folder for reverse-sync (unsync unnecessary folders)  
For example, your Dropbox folder has subfolders and a file:

```plaintext
backups
books
stuff
logo.png

```

You need to exclude all except `backups`. Actually the command adds items to exclude list:

```plaintext
dropbox exclude add "Dropbox/books/"
dropbox exclude add "Dropbox/stuff/"
dropbox exclude add "Dropbox/logo.png"

```

If you suddenly added `backups` to exclude list, you can return it to synchronization, removing the item from the list:

```plaintext
dropbox exclude remove "Dropbox/backups/"

```

Current status of certain backup can be checked by the command:

```plaintext
dropbox filestatus Dropbox/backups/niti-2021-01-21-033726-v20201218000001.tar.gz

```

**Fifth** prepare script for local sync and clearing cache`/root/rsync.dropbox`:

```plaintext
#!/bin/sh
rsync -avh --stats --progress --delete /var/discourse/shared/standalone/backups/default/ /root/Dropbox/backups/
rm -rf /root/Dropbox/.dropbox.cache/

```

**Sixth** add command to crontab at 8AM local time: `crontab -e`

```plaintext
0 8 * * * /bin/bash /root/rsync.dropbox

```

There is a timewindow between 3AM UTC and my local 8AM - it should be enough to backup completion before it begin synchronizing with Dropbox.

**P.S.**  
I did not check this configuration half a year or even more. Now I realized that the command `dropbox status` has returned:

```plaintext
You're using an old version of Dropbox. Please update to the latest version to continue using Dropbox.

```

The syncronization still works, therefore I will not upgrade it. Last time symlink support was lost.

---

_[View the full topic](https://meta.discourse.org/t/upload-backups-to-dropbox-with-crontab-and-dropboxd/176982)._
