Intro

These are my Nextcloud notes I've accumulated over the years.

They are specific to my setup and use.

 

Notes

The current setup uses Nextcloud snap from https://github.com/nextcloud/nextcloud-snap and runs off of a late version Ubuntu-install.

In addition to the packages included in the snap on the above URL, Let's encrypt is also used and can be enabled with nextcloud.occ commands.

 

How to install Nextcloud snap

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-nextcloud-on-ubuntu-20-04

 

Current config (2021-02-25)

<?php
$CONFIG = array (
'apps_paths' =>
array (
0 =>
array (
'path' => '/snap/nextcloud/current/htdocs/apps',
'url' => '/apps',
'writable' => false,
),
1 =>
array (
'path' => '/var/snap/nextcloud/current/nextcloud/extra-apps',
'url' => '/extra-apps',
'writable' => true,
),
),
'supportedDatabases' =>
array (
0 => 'mysql',
),
'memcache.locking' => '\\OC\\Memcache\\Redis',
'memcache.local' => '\\OC\\Memcache\\Redis',
'redis' =>
array (
'host' => '/tmp/sockets/redis.sock',
'port' => 0,
),
'log_type' => 'file',
'logfile' => '/var/snap/nextcloud/current/logs/nextcloud.log',
'logfilemode' => 416,
'passwordsalt' => 'XXX',
'secret' => 'XXX',
'trusted_domains' =>
array (
0 => 'localhost',
1 => 'XXXFQDNXXX',
2 => '192.168.0.14',
),
'datadirectory' => '/var/snap/nextcloud/common/nextcloud/data',
'dbtype' => 'mysql',
'version' => '20.0.7.1',
'overwrite.cli.url' => 'http://localhost',
'dbname' => 'nextcloud',
'dbhost' => 'localhost:/tmp/sockets/mysql.sock',
'dbport' => '',
'dbtableprefix' => 'oc_',
'mysql.utf8mb4' => true,
'dbuser' => 'nextcloud',
'dbpassword' => 'XXX',
'installed' => true,
'instanceid' => 'ocgxt54195ka',
'mail_smtpmode' => 'smtp',
'mail_sendmailmode' => 'smtp',
'mail_from_address' => 'XXX',
'mail_domain' => 'XXXFQDNXXX',
'mail_smtpauthtype' => 'LOGIN',
'mail_smtphost' => 'mailcluster.loopia.se',
'mail_smtpport' => '587',
'maintenance' => false,
'loglevel' => 2,
);

 

Common commands

Most of these commands need to be run with sudo, or to be root.

# snap restart nextcloud.apache

# snap set nextcloud php.memory-limit=512M
# snap set nextcloud php.memory-limit=1024M

# nextcloud.occ maintenance:mode --off
# nextcloud.occ maintenance:mode --on

# nextcloud.occ files:scan --all

# snap connect nextcloud:network-observe

# nextcloud.export -abc
# nextcloud.import

# nextcloud.enable-https

Danger Will Robinson! Experimental! Use on your own risk!
# snap set nextcloud apache.http2=true

 

Locations

Nextclouds writable config file is located here:

/var/snap/nextcloud/current/nextcloud/config/config.php

The logs can be found here:

/var/snap/nextcloud/current/logs/

 

Errors and conditions

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the below command for this to take effect.

# sysctl vm.overcommit_memory=1

WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command below as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

# 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'

 

Backup Nextcloud.snap

Examples for backup can be found below. The first bold line is what I use.

https://github.com/nextcloud/nextcloud-snap/wiki/How-to-backup-your-instance
https://www.reddit.com/r/NextCloud/comments/b5vj74/best_way_to_fully_backup_a_nextcloud_snap/
https://www.addictivetips.com/ubuntu-linux-tips/backup-nextcloud-snap-installation-on-linux/

 

Backup script

The backup script is located in (my private) gitlab repo in scripts-and-stuff/nextcloud/nextcloud_export.sh.

#!/bin/bash

# https://github.com/nextcloud/nextcloud-snap/wiki/How-to-backup-your-instance
# Usage:
# nextcloud.export [OPTIONS]
# Export data suitable for migrating servers. By default this
# includes the Nextcloud database, configuration, and data
# (equivalent to running nextcloud.export -abcd).
#
# Available options:
# -h: Display this help message
# -a: Include the (non-default) apps
# -b: Include the database
# -c: Include the config
# -d: Include the data (can be quite large)

/bin/find /root/nextcloud_backup -type f -name *.bz2 -mtime +10 -delete -print

/snap/bin/nextcloud.export -a -b -c
/usr/bin/mv /var/snap/nextcloud/common/backups/* /root/nextcloud_backup/config/
/usr/bin/tar -cvf /root/nextcloud_backup/nextcloud_config_$(date +%Y-%m-%d_%H%M%S).tar /root/nextcloud_backup/config/*
/usr/bin/rm -rf /root/nextcloud_backup/config/*

/usr/bin/cp -rvp /var/snap/nextcloud/current/certs /root/nextcloud_backup/
/usr/bin/tar -cvf /root/nextcloud_backup/nextcloud_certs_$(date +%Y-%m-%d_%H%M%S).tar /root/nextcloud_backup/certs/
/usr/bin/rm -rf /root/nextcloud_backup/certs/*

cd /root/nextcloud_backup
/usr/bin/bzip2 /root/nextcloud_backup/*.tar

The backup-files are rsynced to lanfear2 and then synced to the Nextcloud.

 

Schedule backups

Become user and then run crontab -e, add the following line to schedule a backup every day at 00:03.

3 0 * * * /home/sorin/git/scripts-and-stuff/nextcloud/nextcloud_export.sh

 

Tips'n'tricks

Sometimes there are file upload conflicts and extra files created. Find those conflicting files with the below commands and delete them after reviewing.

$ cd /home/sorin/Nextcloud
$ find . -type f -name "*conflict*"

 

 

 

 

 

 

 

 

Stop Spam Harvesters, Join Project Honey Pot

 

Get a free SSL certificate!

 

The leading nonprofit defending digital privacy, free speech, and innovation.

 

The Linux Foundation provides a neutral, trusted hub for developers and organizations to code, manage, and scale open technology projects and ecosystems.

 

Kubuntu is an operating system built by a worldwide community of developers, testers, supporters and translators.

 

 43ef5c89 CanonicalUbuntudarktext