Linux | 通过OCC命令管理Nextcloud

Nextcloud只能上传文件而非文件夹,对于有大批量文件上传需求其效率是极低的,通过查看存放文件的目录我们可以知道Next cloud是源文件存储(多用户使用具有一定的隐私安全),这样我们是不是可以直接把文件放到服务器相应的文件夹上呢?但放上去后我们会发现登录Nextcloud文件索引并没有更新,这是因为Nextcloud会把文件索引存放在数据库的oc_filecache表中,所以直接上传文件数据库的信息是不会更新的。



其安装根目录下有一个 occ 文件

[root@nas nextcloud]# ls
3rdparty  AUTHORS  console.php  core      data        index.php  occ           ocs           public.php  resources   settings    themes   version.php
apps      config   COPYING      cron.php  index.html  lib        ocm-provider  ocs-provider  remote.php  robots.txt  status.php  updater


vim occ
#!/usr/bin/env php
 * Copyright (c) 2013 Thomas Mü ller <>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.

//$argv = $_SERVER['argv'];
require_once __DIR__ . '/console.php';



sudo -u nginx php occ
Nextcloud 15.0.0

  command [options] [arguments]

  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --no-warnings     Skip global warnings, show command output only
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

 Available commands:
  check                               check dependencies of the server environment
  help                                Displays help for a command
  list                                Lists commands
  status                              show some status information
  upgrade                             run upgrade routines after installation of a new release. The release has to be installed before.
  activity:send-mails                 Sends the activity notification mails
  app:check-code                      check code to be compliant
  app:disable                         disable an app
  app:enable                          enable an app
  app:getpath                         Get an absolute path to the app directory
  app:install                         install an app
  app:list                            List all available apps
  app:remove                          remove an app
  app:update                          update an app or all apps
  background:ajax                     Use ajax to run background jobs
  background:cron                     Use cron to run background jobs
  background:webcron                  Use webcron to run background jobs

  config:app:delete                   Delete an app config value
  config:app:get                      Get an app config value
  config:app:set                      Set an app config value
  config:import                       Import a list of configs
  config:list                         List all configs
  config:system:delete                Delete a system config value
  config:system:get                   Get a system config value
  config:system:set                   Set a system config value

  dav:create-addressbook              Create a dav addressbook
  dav:create-calendar                 Create a dav calendar
  dav:remove-invalid-shares           Remove invalid dav shares
  dav:sync-birthday-calendar          Synchronizes the birthday calendar
  dav:sync-system-addressbook         Synchronizes users to the system addressbook

  db:add-missing-indices              Add missing indices to the database tables
  db:convert-filecache-bigint         Convert the ID columns of the filecache to BigInt
  db:convert-mysql-charset            Convert charset of MySQL/MariaDB to use utf8mb4
  db:convert-type                     Convert the Nextcloud database to the newly configured one

  encryption:change-key-storage-root  Change key storage root
  encryption:decrypt-all              Disable server-side encryption and decrypt all files
  encryption:disable                  Disable encryption
  encryption:enable                   Enable encryption
  encryption:encrypt-all              Encrypt all files for all users
  encryption:list-modules             List all available encryption modules
  encryption:set-default-module       Set the encryption default module
  encryption:show-key-storage-root    Show current key storage root
  encryption:status                   Lists the current status of encryption

  federation:sync-addressbooks        Synchronizes addressbooks of all federated clouds
  files:cleanup                       cleanup filecache
  files:scan                          rescan filesystem
  files:scan-app-data                 rescan the AppData folder
  files:transfer-ownership            All files and folders are moved to another user - shares are moved as well.
  group:add                           Add a group
  group:adduser                       add a user to a group
  group:delete                        Remove a group
  group:list                          list configured groups
  group:removeuser                    remove a user from a group
  integrity:check-app                 Check integrity of an app using a signature.
  integrity:check-core                Check integrity of core code using a signature.
  integrity:sign-app                  Signs an app using a private key.
  integrity:sign-core                 Sign core using a private key.
  l10n:createjs                       Create javascript translation files for a given app
  log:file                            manipulate logging backend
  log:manage                          manage logging configuration
  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:theme:update            Apply custom theme changes
  maintenance:update:htaccess         Updates the .htaccess file
  migrations:execute                  Execute a single migration version manually.
  migrations:migrate                  Execute a migration to a specified version or the latest available version.
  migrations:status                   View the status of a set of migrations.
  notification:generate               Generate a notification for the given user
  security:certificates               list trusted certificates
  security:certificates:import        import trusted certificate
  security:certificates:remove        remove trusted certificate
  sharing:cleanup-remote-storages     Cleanup shared storage entries that have no matching entry in the shares_external table
  trashbin:cleanup                    Remove deleted files
  trashbin:expire                     Expires the users trashbin
  twofactorauth:cleanup               Clean up the two-factor user-provider association of an uninstalled/removed provider  
  twofactorauth:disable               Disable two-factor authentication for a user
  twofactorauth:enable                Enable two-factor authentication for a user
  twofactorauth:enforce               Enabled/disable enforced two-factor authentication
  twofactorauth:state                 Get the two-factor authentication (2FA) state of a user
  update:check                        Check for server and app updates
  user:add                            adds a user
  user:delete                         deletes the specified user
  user:disable                        disables the specified user
  user:enable                         enables the specified user
  user:info                           show user info
  user:lastseen                       shows when the user was logged in last time
  user:list                           list configured users
  user:report                         shows how many users have access
  user:resetpassword                  Resets the password of the named user
  user:setting                        Read and modify user settings
  versions:cleanup                    Delete versions
  versions:expire                     Expires the users file versions


  files:cleanup                       #清除文件缓存
  files:scan                          #重新扫描文件系统
  files:scan-app-data                 #重新扫描应用数据目录
  files:transfer-ownership            #转移所有文件到新的用户目录


[root@nas nextcloud]# sudo -u nginx php occ files:scan -h

  files:scan [options] [--] [<user_id>]...

  user_id                will rescan all files of the given user(s)

      --output[=OUTPUT]  Output format (plain, json or json_pretty, default is plain) [default: "plain"]
  -p, --path=PATH        limit rescan to this path, eg. --path="/alice/files/Music", the user_id is determined by the path and the user_id parameter and --all are ignored
      --all              will rescan all files of all known users
      --unscanned        only scan files which are marked as not fully scanned
      --shallow          do not scan folders recursively
      --home-only        only scan the home storage, ignoring any mounted external storage or share
  -h, --help             Display this help message
  -q, --quiet            Do not output any message
  -V, --version          Display this application version
      --ansi             Force ANSI output
      --no-ansi          Disable ANSI output
  -n, --no-interaction   Do not ask any interactive question
      --no-warnings      Skip global warnings, show command output only
  -v|vv|vvv, --verbose   Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

  rescan filesystem


[root@nas nextcloud]# sudo -u nginx php occ files:scan --path="/admin/files/Videos"
Starting scan for user 1 out of 1 (admin)
| Folders | Files | Elapsed time |
| 450     | 2597  | 00:00:56     |


1 + 8 =