How to encrypt files via CLI (command line)

I have to migrate an existing folder on one Nextcloud instance to another Nextcloud instance. Since it is only one folder (with many subfolders and files) of about 2 GB size, I would like to

  • either download it as a compressed file from the one Nextcloud instance, upload the file to the other instance, decompress and encrypt it there directly on the server via shell

  • or transfer the folder directly from one server to the other over scp and have it decrypted on the one server and encrypted on the other server.

I found a tool to decrypt contents directly on the server via CLI, but no tool to encrypt the contents on the server.

Of course, an alternative would be to download the folder as compressed archive via web front-end from one server, unzip it locally and upload the contents to the other server via web front-end again. However, the upload would take much longer this way.

Is it possible or are there alternative approaches?

I would recommed to use scp directly. Here you will find the pros and cons of encrypting files before transfering it:

The question is: Is this way supported by Nextcloud and, if so, how to do it?

Copying files from one server to another is, in a first step, independent from Nextcloud, because it happens on the file system layer. Nextcloud supports to update its database by execution the "files:scan [options] [--] [<user_id>...]" command.
So the right way to go is

  1. copy the files to the new server
  2. adjust the directory and file access rights
  3. execute the occ command to update the Nextcloud database

Thanks for your quick response! What about the decryption/encryption of the files? How can the files be decrypted and re-encrypted with the new key on the target server in way compatible with Nextcloud?

What about the decryption/encryption of the files? How can the files be decrypted and re-encrypted with the new key on the target server in way compatible with Nextcloud?

Are you really using Nextcloud’s file encryption on your servers? You haven’t mentioned this in your original post!