Backup Discourse in DO droplet to NAS device

Hi, I am looking for a way to run automated backups of my new Discourse forum (set up in a Digital ocean droplet) to the NAS device on my home network. How can this be accomplished?

I am not a coder and would not know where to begin with trying to make a plugin for this purpose.

The easiest way is to run some kind of automated job (cron job), depending on the NAS you have, you can run some basic Linux commands, like rsync.

You need a way to connect the NAS and the Droplet, once you find that way, I think a plugin would be an overkill for example. You just need something like the code below, to run on your NAS, in a cron job

rsync -avz --progress -e "ssh -i ~/.ssh/id-rsa" /folder/in/the/nas

The ability to run something like this, would depend, as I said above, in which NAS you have.


Thanks Mario. I have an old Netgear ReadyNAS ultra 6 running OS6, which I believe may support this approach (will investigate).

I guess part of the problem for me is in identifying which files/folder(s) to back up - presume just the database? (and I presume all posted images/attachments etc will be embedded within that?)

What path would I use to find the database? Is the database even a stored as a file within the Discourse directory? I poked around in /var/discourse and did not spot anything much that looked like a database file, to my untrained eye.

You want to turn on daily backups and get

1 Like

Thanks Jay - that seems to be the ticket!
Is it fair to assume that if I have set ‘include uploads with backups’ there is really nothing else I need to keep backed up, if at some point I needed to start again from scratch on another server?

(assuming 3rd any party plugins I have been using won’t suddenly become unavailable for download again)

Also, is there a way to automatically clean up the daily backups directory so that, say, no more than the last 7 days worth of daily backups are kept on the server?

Yes, there are settings in the Administration Dashboard, I don’t remember the names right now. The script I sent you earlier already uses the default path where the backups are stored.

But, with rsync in the NAS and that command, you can tweak it, so it also erases the old backups from the NAS, you’re all set up.

1 Like

Thanks Mariano
On the ReadyNAS forum there was a suggestion that using chron on readyNAS is possible but not ideal, and that the built in ‘systemd timers’ was better. Not sure if that allows anything as fancy as remote directory cleanups though.

Am currently struggling with ‘Permission denied (publickey)’ errors whenever I attempt to connect from ReadyNas to my Discourse server - even though I have added the ReadyNAS public key to the list of SSH users on Digital ocean.

Will report back here if I make any progress, for anyone else trying this.

The cleanup is made directly by Discourse in the droplet, but, rsync has a zillion options, so you can customize the process of copying the backups to your liking.

Make sure you restart the SSH server, sometimes it fixes some public key issues.

Thanks Mariano
Just power cycled the server, and still getting:

Permission denied (publickey).
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(235) [Receiver=3.1.3]

No doubt the problem is with me, trying to log in as wrong user or something - though I have tried logging in from ReadyNAS using the name I gave that public key when adding it to Digital Ocean, as well as ‘root’. Neither seem to work.

Have you already log in in the server with a key? Like when you installed Discourse, or rebuild the application?

It might be (although it shouldn’t) that the SSH in the server has Public Authentication disabled, or maybe the NAS is using the wrong key to log in.

Remember to change to the right key name and path in this part of the command "ssh -i ~/.ssh/id-rsa"

*** EDIT ***
Thanks Mariano. Got it working in the end.

In a nutshell, for anyone else trying this;

  1. Enable SSH on ReadyNAS

  2. Use PuTTy to access Digital Ocean server and type

nano /root/.ssh/authorized_keys

  1. in the editor, copy-paste in the public key text used by ReadyNAS, appending this at the end of the /root/.ssh/authorized_keys file (be careful to not overwrite any keys already present).

  2. In the ReadyNAS backup dialog settings, I used::

Name: Backup via Rsync over remote SSH (drop down selection)
Host: (or server IP address)
Port: 22
Path: /var/discourse/shared/standalone/backups/default
Login: root

(Noting that if you followed the instructions for setting up ReadyNAS for SSH access correctly, no SSH passphrase will be associated with its public/private SSH key pair. This is rather important, as the ReadyNAS backup dialog does not provide for a passphrase)

At first this process did not work fully for me - using the ‘Test’ button in the ReadyNAS backup dialog with these settings did result in successful connection, but then initiating a backup generated error ‘Disk quota exceeded (122)’
But then a couple of hours later, with no further obvious intervention on my part, when the backup process initiated itself again on its auto designated hour, this time it just worked as it should.

Possibly my previous efforts at achieving a connection and testing using different settings were having some residual effect that impeded things, or perhaps being simultaneously logged in to the server from my PC as root via PuTTY at the same time as root via FileZilla (both using default key for root) and then trying to log in as root via ReadyNAS device backup utility (using ReadyNAS’s public key that had been added to root) was problematic.