How to restore nextcloud on freenas from offline backup

cunningorb

Explorer
Joined
Feb 5, 2018
Messages
58
TL;DR - I have offline backup of entire nextcloud server (was running in freenas) and need to restore it on my working installation of nextcloud on freenas but don't know how. Nextcloud manual is written for ubuntu server.

I was running nextcloud in freenas in a hypervisor. I decided freenas should be on bare metal but had to use the same server, so my nextcloud server is down for the count. All I have are the files backed up using freenas snapshots and replications to 2 other locations for redundancy (can't lose my stuff).

The question I have is how do I stand up nextcloud again when the normal backup procedure calls for running the old install and the new install at the same time? My old install will never run again without a miracle or time machine. I have every possible file I could need, all available via the backup storage pools on backup servers (which were not in any way running nextcloud).

Today my situation is, finally have freenas running on bare metal (8 cores @ 3ghz, 20gb ecc ram, hp proliant dl360, 2 nics, 8TB storage pool & 240gb ssd pool). I am running nextcloud in freenas again using @danb35 script to install it. How then do I restore the files and database so my users see it as if nothing happened?

As I see it I can either
1. Figure out how to rsync everything back into place, or

2. Try to recreate everything the way it was manually (apps, configs, etc.) and then login to each individual user and use the desktop client to upload files from replicated backup.
 
Last edited:

cunningorb

Explorer
Joined
Feb 5, 2018
Messages
58
Does anyone have any advice for me? I changed the thread title to hopefully be more precise to my situation and updated my original post. I have nextcloud up and running, I have my old backup pool imported into the freenas server where nextcloud is running. So all the pieces are falling into place I am just at a loss for what to do. I don't know how to rsync things on freenas and I don't know that if I did it that everything would actually work. I don't know how to administrate the sql via ssh. I do know how to connect via ssh. My google-fu has taken me this far, can anyone assist? I appreciate it!

*Edit: would this work? https://forums.freenas.org/index.php?threads/backing-up-freenas-nextcloud-plugin.57749/post-455488
 
Last edited:

cunningorb

Explorer
Joined
Feb 5, 2018
Messages
58
Hello world, maybe a more simple question.
What is the method you guys have used to put nextcloud in maintenance mode on a freenas install in a jail? The nextcloud documentation is written for ubuntu and it is not working for me.
Update where I'm at so far, I used cp command to copy the data folders. After that nextcloud kicks out an HTTP 500 error. I haven't gone any farther or checked logs but I want to do this while nextcloud is in maintenance mode so plan is:
restore snapshot to before the cp command
confirm vanilla NC is working
NC in maintenance mode via occ command (however that works in freenas jail, I still haven't figured it out)
cp command data folder
database restore via cmd on ssh (also don't really know how to do this, sure it's a lark)
config.php restore after checking for configs?
Confirming I completed all restore steps listed in NC documentation on restoration from backup
Turn off NC maintenance mode.
Everything is going to be awesome?
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
I wrote a script to do the backup and restore to a tar.gz file
you have to set the parameters in the NextcloudBR-config file. FYI I have not tried to use the scipt outside of my nextcloud install script.
If you look at the commands in the script you will see how to set the maintenance mode etc...
Code:
su -m www -c 'php /usr/local/www/nextcloud/occ maintenance:mode --on'
 

cunningorb

Explorer
Joined
Feb 5, 2018
Messages
58
I wrote a script to do the backup and restore to a tar.gz file
you have to set the parameters in the NextcloudBR-config file. FYI I have not tried to use the scipt outside of my nextcloud install script.
If you look at the commands in the script you will see how to set the maintenance mode etc...
Code:
su -m www -c 'php /usr/local/www/nextcloud/occ maintenance:mode --on'
Amazing! Your code in this script is commented like a pro coder's should be. Very glad you popped in and I'll give this a go tonight/tomorrow.

So far tonight I am getting
zsh:1: command not found: php
I did have to edit the command as the nextcloud directory is in a different spot on my install. Mine is here: /usr/local/www/apache24/data/nextcloud
 
Last edited:

Heracles

Wizard
Joined
Feb 2, 2018
Messages
1,401
Hi Cunningorb,

Here, I designed, documented and tested my Nextcloud setup up to the level of a corporate solution. I did numerous backups and restores, even with server-side encryption enabled.

So are you using any kind of encryption ? Server side or End-to-End, encryption is to be considered when doing your backup - restore.

What are you using as a database ? Here, I run Nextcloud as a Docker container and use an external MariaDB container for my database. You need a complete dump of your database. Are you using the default SQLite database inside the jail or are you pointing to an external DB ?

You also need a few directory to restore a Nextcloud server : Apps, Config, Root, themes and of course, the Data.

You also need to be sure your database backup was taken at the same time as your data / config backup, even more if you are doing any kind of encryption.

So here, my setup is :
A Nextcloud Docker container on Host A
A MariaDB Docker container on Host B
FreeNAS as a Data server and Host C

Nextcloud itself is using 5 volumes :
/var/www/html/ is Root
/var/www/html/config is Config
/var/www/html/custom_apps is Apps
/var/www/html/themes is Themes
/var/www/html/data is Data

A backup is taken by doing a tar-ball from Root, Config, Apps and Themes, as well as a snapshot os the data.
At the same moment, I dump the SQL database in a separate file.

The dump and tarballs are encrypted and saved in a sub-directory of my Nextcloud dataset in FreeNAS.

FreeNAS does ZFS replication of everything to my DR server.

For me to restore, I need to :
--Identify the backup I wish to restore
--Rollback the dataset to that moment
--Extract the 4 tarballs in 4 Docker volumes that I will use for the new container
--Extract the SQLDump and inject it in a new MariaDB container
--Create a new Nextcloud container using the 4 volumes, mounting the data over NFS and pointing to the database

That procedure will deal with server side encryption properly.

Hope this will help you visualize the restore process of a Nextcloud service,
 

cunningorb

Explorer
Joined
Feb 5, 2018
Messages
58
Hi Cunningorb,

Here, I designed, documented and tested my Nextcloud setup up to the level of a corporate solution. I did numerous backups and restores, even with server-side encryption enabled.

So are you using any kind of encryption ? Server side or End-to-End, encryption is to be considered when doing your backup - restore.

What are you using as a database ? Here, I run Nextcloud as a Docker container and use an external MariaDB container for my database. You need a complete dump of your database. Are you using the default SQLite database inside the jail or are you pointing to an external DB ?

You also need a few directory to restore a Nextcloud server : Apps, Config, Root, themes and of course, the Data.

You also need to be sure your database backup was taken at the same time as your data / config backup, even more if you are doing any kind of encryption.

So here, my setup is :
A Nextcloud Docker container on Host A
A MariaDB Docker container on Host B
FreeNAS as a Data server and Host C

Nextcloud itself is using 5 volumes :
/var/www/html/ is Root
/var/www/html/config is Config
/var/www/html/custom_apps is Apps
/var/www/html/themes is Themes
/var/www/html/data is Data

A backup is taken by doing a tar-ball from Root, Config, Apps and Themes, as well as a snapshot os the data.
At the same moment, I dump the SQL database in a separate file.

The dump and tarballs are encrypted and saved in a sub-directory of my Nextcloud dataset in FreeNAS.

FreeNAS does ZFS replication of everything to my DR server.

For me to restore, I need to :
--Identify the backup I wish to restore
--Rollback the dataset to that moment
--Extract the 4 tarballs in 4 Docker volumes that I will use for the new container
--Extract the SQLDump and inject it in a new MariaDB container
--Create a new Nextcloud container using the 4 volumes, mounting the data over NFS and pointing to the database

That procedure will deal with server side encryption properly.

Hope this will help you visualize the restore process of a Nextcloud service,
Awesome Heracles!
On my end I opted for a non-encrypted setup as a start thinking that would be a level of difficulty higher than I wanted.
I've got my install for nextcloud directly in a freenas jail using @danb35 script to do the install.
My sql was never dumped unfortunately. Not sure how that's going to affect the restore. I have a snapshot image of all NC data directories and database right at the time it went down.
I brought this on myself because I wanted to take freenas off the hypervisor and move it to bare metal but on the same server. This could have been thought through better but I'm stuck with the way I did it.
Your post definitely helped and I am starting to see how I should be performing backups in the future. I doubt I will only rely on snapshots in the future as it is not a viable restoration from failure in every scenario.
 

Heracles

Wizard
Joined
Feb 2, 2018
Messages
1,401
Hi again,

Glad that helps you understand your situation better.

The fact that you did not dump your database manually may end up problematic. Luckily for you, your data are not encrypted, to the data themselves will be mostly re-accessible and re-usable.

The database contains a lot of stuff :
--All the contacts
--All the calendars
--All the accounts, password, second factor authentication keys, recovery codes, ...
--Infos about thumbnails, file inventory
--and more...

If restoring the snapshots is enough for your database to come back online with all its content, you should be good.

If your database is lost, you can create a new Nextcloud instance, create accounts and move your files and folders to their new destination. Be sure to adjust file ownership and attribute ownership to your Nextcloud web server's ID. Once you did that, you can use the OCC command to force a re-scan of every files in every account. That will re-build and update a major section of the database. You can do something similar for the thumbnails.

If your database does not come back online from what you have, know that is content (calendars, contacts, accounts, passwords, keys, etc.) is lost.

As for not doing encryption, you were right. You must master your setup perfectly without encryption and be able to do full backup - restore before even thinking about encryption. Even then, start by working on a Dev instance of Nextcloud on which you are ready to loose and destroy everything.

Good luck with your recovery,
 

cunningorb

Explorer
Joined
Feb 5, 2018
Messages
58
Update:
I ended up resolving this by just using the desktop client to upload files to each user's directory. Since I had all the files and nothing was encrypted this was the clearest method without any roadblocks. Lesson learned that I will never run nextcloud without a recovery friendly backup again. Thanks everyone for the advice and I hope this helps others to make sure their nextcloud instances installed in a freenas jail are properly configured.

I will be looking next into the script method of backup/recovery proposed by @NasKar linked here: https://github.com/NasKar2/freenas-iocage-nextcloud/blob/master/NextcloudBR.sh
 

Heracles

Wizard
Joined
Feb 2, 2018
Messages
1,401
Hey Cunningorb,

I checked that script and I notice that it includes the backup of your files as data. This is a two edged sword.

It can be very good if your volume of data is low and you do not already have a backup mechanism for these files.

But it can also be problematic if you have a large volume of data. To create a full copy of everything everytime you do a backup will take all your space in no time. It is also useless if you have a plan for these files.

Here, I already have a significant volume of data and expect to only grow. Also, I use ZFS snapshots and ZFS replication to a DR NAS. For these reasons, I do not backup my data with a script like that.

On the other hand, I do have a similar script that will backup the database and the critical folders. Because the volume is low, I do database backups as often as every 15 minutes to keep up with my snapshot. These 15 minutes backups I do not save for more than 1 day. The daily backup is to one that I save for the long run.

Should I be using a script like that, I would increase my data size by 100% every 15 minutes....

Be sure this backup is designed for your needs before going too far with it.

Have fun with your setup,
 
Top