Introduction
In this article, we’ll walk through various maintenance tasks that can be performed with occ
command. I will present you practical examples to disable or enable maintenance mode, optimize your Nextcloud instance, optimizing the database and more.
Whether you’re looking to manage file caching or configure system-wide updates, the occ
command is an essential tool for every Nextcloud administrator.
Nextcloud’s occ
command (origins from “ownCloud Console”) is Nextcloud’s command-line interface. You can perform many common server operations with occ
, such as installing and upgrading Nextcloud, manage users, encryption, passwords, LDAP setting, and more.
Prerequisites for Nextcloud Maintenance with occ
Command
occ
is in the nextcloud/
directory; for example /var/www/nextcloud
on Ubuntu Linux. occ
is a PHP script. You must run it as your HTTP user to ensure that the correct permissions are maintained on your Nextcloud files and directories.
Practical Examples of occ
Command for Maintenance Tasks
Before executing occ
command, you need to navigate to the Nextcloud directory. In my case, it is in the
cd /var/www/html/nextcloud
Check Nextcloud System Status
To check system status, you can execute the following command in your Nextxloud directory:
sudo -u www-data php occ status
Output is something like:
root@nextcloud:/var/www/html/nextcloud# sudo -u www-data php occ status
- installed: true
- version: 30.0.3.2
- versionstring: 30.0.3
- edition:
- maintenance: false
- needsDbUpgrade: false
- productname: Nextcloud
- extendedSupport: false
Scan the Files and Optimize the File Cache
sudo -u www-data php occ files:scan --all
Enable or Disable Maintenance Mode
To disable maintenance mode, you can execute the following command:
# Enable Maintenance Mode
sudo -u www-data php occ maintenance:mode --on
# Disable Maintenance Mode
sudo -u www-data php occ maintenance:mode --off
Listing Installed Apps
To list all installed application on your Nextcloud Server, you can execute:
sudo -u www-data php occ app:list
In my case, there are a lot of installed application:
Enabled:
- activity: 3.0.0
- admin_audit: 1.20.0
- app_api: 4.0.3
- audioplayer: 3.4.1
- bruteforcesettings: 3.0.0
- cloud_federation_api: 1.13.0
- comments: 1.20.1
- contactsinteraction: 1.11.0
- cospend: 2.0.0
- dashboard: 7.10.0
- dav: 1.31.1
- federatedfilesharing: 1.20.0
- files: 2.2.0
- files_accesscontrol: 1.20.1
- files_downloadlimit: 3.0.0
- files_pdfviewer: 3.0.0
- files_reminders: 1.3.0
- files_sharing: 1.22.0
- files_trashbin: 1.20.1
- files_versions: 1.23.0
- firstrunwizard: 3.0.0
- geoblocker: 0.5.15
- groupfolders: 18.0.7
- groupquota: 0.2.1
- login_notes: 1.6.1
- logreader: 3.0.0
- lookup_server_connector: 1.18.0
- memories: 7.4.1
- nextcloud_announcements: 2.0.0
- notes: 4.11.0
- notifications: 3.0.0
- oauth2: 1.18.1
- password_policy: 2.0.0
- photos: 3.0.2
- privacy: 2.0.0
- provisioning_api: 1.20.0
- quota_warning: 1.20.0
- related_resources: 1.5.0
- serverinfo: 2.0.0
- settings: 1.13.0
- sharebymail: 1.20.0
- spreed: 20.1.0
- suspicious_login: 8.0.0
- text: 4.1.0
- theming: 2.5.0
- twofactor_backupcodes: 1.19.0
- updatenotification: 1.20.0
- user_status: 1.10.0
- viewer: 3.0.0
- webhook_listeners: 1.1.0-dev
- workflowengine: 2.12.0
Disabled:
- circles: 30.0.0 (installed 25.0.0)
- encryption: 2.18.0
- federation: 1.20.0 (installed 1.18.0)
- files_external: 1.22.0
- recommendations: 3.0.0 (installed 1.3.0)
- support: 2.0.0 (installed 1.7.0)
- survey_client: 2.0.0 (installed 1.16.0)
- systemtags: 1.20.0 (installed 1.18.0)
- twofactor_nextcloud_notification: 4.0.0
- twofactor_totp: 12.0.0-dev
- user_ldap: 1.21.0
- weather_status: 1.10.0 (installed 1.9.0)
- workflow_media_converter: 1.11.7 (installed 1.11.7)
Database Maintenance After Nextcloud Upgrade
After upgrading my Nextcloud environment, I am running the following occ
command to optimize Database:
IMPORTANT: Create a backup of DB before running this command!
mysqldump -u root -p nextcloud > backup.sql
Add missing primary keys:
sudo -u www-data php occ db:add-missing-primary-keys
sudo -u www-data php occ db:add-missing-indices
sudo -u www-data php occ db:convert-filecache-bigint
Output:
root@nextcloud:/var/www/html$ sudo -u www-data php occ db:add-missing-primary-keys
Done.
Other Useful occ
Commands Examples
Running occ
with no options lists all commands and options, like this example on Ubuntu:
sudo -u www-data php occ
Example of output:
maintenance
maintenance:data-fingerprint update the systems data-fingerprint after a backup is restored
maintenance:mimetype:update-db Update database mimetypes and update filecache
maintenance:mimetype:update-js Update mimetypelist.js
maintenance:mode set maintenance mode
maintenance:repair repair this installation
maintenance:repair-share-owner repair invalid share-owner entries in the database
maintenance:theme:update Apply custom theme changes
maintenance:update:htaccess Updates the .htaccess file
Please check other Nextcloud topics on my blog.