Nextcloud
πNextcloud client advanced settings
I use Cloudflare as a proxy in front of my Nextcloud instance. The maximum upload size for my zone is 200 MB
. For that reason, I need to set some custom values in the Nextcloud Client config file so it knows to chunk
the files correctly, otherwise the upload/download fails.
πLinux
vi ~/.config/Nextcloud/nextcloud.cfg
Add the following under the last entry in the [General]
section.
chunkSize=50000000
minChunkSize=5000000
maxChunkSize=200000000
targetChunkUploadDuration=6000
Exit the client and re-open it to apply the changes.
πMacOS
vi ~/Library/Preferences/Nextcloud/nextcloud.cfg
Add the following under the last entry in the [General]
section.
chunkSize=50000000
minChunkSize=5000000
maxChunkSize=200000000
targetChunkUploadDuration=6000
Exit the client and re-open it to apply the changes.
πRestore Nextcloud from a backup
πBackground
The scenario is that the container(s) running Nextcloud on TrueNAS were deleted, or corrupted beyond repair. In that case we will need to restore the Nextcloud directory backup and the PostgreSQL database dump to a clean install. This guide assumes you have a backup of the Nextcloud install directory, along with a databse dump.
πHow to backup Nextcloud
πBackup install directory
πEnable maintenance mode
- Shell into the
nextcloud
container. - Once the prompt loads type
runuser
and press enter. - Enable maintenance mode by executing the following command
runuser -u www-data -- php occ maintenance:mode --on
- You can confirm maintenance mode was enabled by trying to go to your Nextcloud instance in your browser.
πCreate a backup of the Nextcloud install directory
- Go to the TrueNAS shell
System Settings
βShell
- Change directory to where you have Nextcloud installed
cd /mnt/pool_name/nextcloud
- The next command will create a backup of the entire install directory while preserving timestamps
rsync -Aavx install/ nextcloud-dirbkp/
- Once the command finishes running type
ls -l
to confirm there is a directory callednextcloud-dirbkp
πCreate a backup of the Nextcloud database
- Shell into the
nextcloud-postgres
container. - Once the prompt loads type
runuser
and press enter. - The following command will dump the nextcloud databse
pg_dump nextcloud -h localhost -U oc_admin -f nextcloud-sqlbkp.bak
- Type
ls -l
to confirm that you see the filenextcloud-sqlbkp.bak
- We now need to copy the backup to a directory outside of the container. The directory
postgres_backups/
is mapped outside of the container by defaultcp nextcloud-sqlbkp.bak postgres_backups
Now that we have the backup copied, we need to move it to a location that won't be deleted after the container is removed.
- Go to the TrueNAS shell and execute the following
cp /mnt/pool_name/ix-applications/releases/nextcloud/volumes/ix_volumes/ix-postgres_backups/nextcloud-sqlbkp.bak /mnt/pool_name/nextcloud/
You now have a backup of your Nextcloud installation and databse.
πHow to restore Nextcloud Backup
πCreate new Nextcloud containers
- Delete any existing Nextcloud containers
- Use the following parameters from the container configuration.
- Application Name: `nextcloud`
- Certificate Configuration: `Select one if you have it`
- Nextcloud host: `Set domain if you have it. 123.example.com`
- Storage: Select `Enable Host Path for Nextcloud Data Volume` and set the path
Leave everything else set to the default.
We need to login to the install one time before we can restore our data. The default login is admin/changeme
πRestore Nextcloud data
- Shell into the
nextcloud
container. - Once the prompt loads type
runuser
and press enter. - Enable maintenance mode by executing the following command
runuser -u www-data -- php occ maintenance:mode --on
- You can confirm maintenance mode was enabled by trying to go to your Nextcloud instance in your browser.
- Go to the TrueNAS shell and change directory to where you have Nextcloud installed
cd /mnt/pool_name/nextcloud
- Execute the following to copy our backup data over the new install
rsync -Aavx nextcloud-dirbkp/ install/
- Shell into the
nextcloud-postgres
container. Once the prompt loads typerunuser
and press enter. - Before we can restore the database dump, we need to drop and re-create all tables
psql -h localhost -U oc_admin -d template1 -c "DROP DATABASE \"nextcloud\";"
thenpsql -h localhost -U oc_admin -d template1 -c "CREATE DATABASE \"nextcloud\";"
- Go to the TrueNAS shell and copy the postgres dump to the mounted
postgres_backups
directory in the containercp /mnt/pool_name/nextcloud/nextcloud-sqlbkp.bak /mnt/pool_name/ix-applications/releases/nextcloud/volumes/ix_volumes/ix-postgres_backups/
- Shell into the
nextcloud-postgres
container. Once the prompt loads typerunuser
and press enter. cd
to the backup directorycd postgres_backups/
. Typels
to confirm that you seenextcloud-sqlbkp.bak
- Restore the database backup
psql -h localhost -U oc_admin -d nextcloud -f nextcloud-sqlbkp.bak
stop
thenstart
the Nextcloud containers. If you see anInternal Server Error
page when you try to load Nextcloud in your browser, it's likely due to the fact hat theoc_admin
password needs to be updated. To verify this, shell into thenextcloud
container. Once the prompt loads typerunuser
and press enter.- Execute
runuser -u www-data -- php occ
. If the first few lines sayFATAL: password authentication failed for user "oc_admin" in /var/www/html/lib/private/DB/Connection.php:139
then that means we need to update the password. If it says something else...good luck. - While we're in the
nextcloud
container we need to get the updated password. Runcat config/config.php | grep dbpassword
and note the password somehwhere. - Shell into the
nextcloud-postgres
container. Once the prompt loads typerunuser
and press enter. - Execute the following command replacing
DBPASSWORD
with the password from the previous steppsql -h localhost -U oc_admin -d template1 -c "ALTER user oc_admin password 'DBPASSWORD'";
. If successful, you should see the outputALTER ROLE
stop
thenstart
the Nextcloud containers.- If that fixed the issue, you should now see the Nextcloud maintenance page in your browser instead of
Internal Server Error
- Shell into the
nextcloud
container. Once the prompt loads typerunuser
and press enter. - Disable maintenance mode by executing the following command
runuser -u www-data -- php occ maintenance:mode --off
- The last step is to run
runuser -u www-data -- php occ maintenance:data-fingerprint
in thenextcloud
container that announces to clients a backup was restored. - You should now be able to login and everything should be right where you left it. Restart any desktop clients if syncing does not start automatically.
πBackground jobs via. cron
By default, background jobs use AJAX which only executes when a user loads a web page. My personal instance is a single user instance, and I rarely use the web interface. This meant that my background jobs hadn't run in ~3 month. To enable cron which will run every 5 minutes, we can schedule it via the TrueNAS interface.
- Navigate to
System Settings
->Advanced
->Add
Cron job. - Add a cron job with the following details:
Description: Nextcloud background jobs
Command: docker exec --user www-data `docker ps | grep "nextcloud_nextcloud" | awk '{ print $1; }'` php /var/www/html/cron.php
Run As User: root
Schedule:
Hide Standard Output - X
Hide Standard Error
Enabled - X
Navigate to https://host_here/settings/admin
and verify it says Last job was run x minutes ago.
(x < 5)
πCommon issues
When trying to delete a file in the browser or from a client, you may see an error 423 LOCKED
or UNABLE TO DELETE
. This happens because something in the database causes a file lock to not be released. Luckily it's an easy fix.
- Shell into the
nextcloud
container. - Once the prompt loads type
runuser
and press enter. - Enable maintenance mode by executing the following command
runuser -u www-data -- php occ maintenance:mode --on
- Shell into the
nextcloud-postgres
container. Once the prompt loads typerunuser
and press enter. - This step is optional, but you can type
\dt
to see all the tables. - Before we delete the locks, let's see them
SELECT * FROM oc_file_locks WHERE lock = 1;
. You should see some results printed to the screen, if you don't then there are no locks. - If you do see locks or just want to try to delete the anyway execute
DELETE FROM oc_file_locks WHERE lock = 1;
- Shell into the
nextcloud
container. Once the prompt loads typerunuser
and press enter. - Disable maintenance mode by executing the following command
runuser -u www-data -- php occ maintenance:mode --off
- You should now be able to delete any files that you were not able to delete before.
πIssues and fixes
These issues were found in https://host_here/settings/admin/overview
Error
Missing index "preferences_app_key" in table "oc_preferences".
Missing index "mounts_class_index" in table "oc_mounts".
Fix
runuser -u www-data -- php occ db:add-missing-indices
Error
one columns in the database are missing a conversion to big int
Fix
runuser -u www-data -- php occ db:convert-filecache-bigint
Error
Your installation has no default phone region set.
Fix - add below dbpassword
in /mnt/eternatus/nextcloud/install/config/config.php
using TrueNAS Shell.
'default_phone_region' => 'US'
Restart container