# Migration Nextcloud Pelican --> Nextcloud test

1. Upgrade nextcloud on Pelican
2. Deploy a new Nextcloud instance (FS) with OpenStack (same NC release + MariaDB **10.5.11**)
  > minimum 100GB for DB host, storepelican available with NFS
  > add `'proxy' => 'proxy.sipr.ucl.ac.be:889',` in the NC config
3. Halt NC on Pelican and 
  - rsync the mysql folder from DB container
  - rsync the Nextcloud data folder from storepelican to a test folder (still on storepelican)
4. Halt mariadb in the DB VM and rsync the mysql folder above
  > check ownership (mysql:mysql) on the folder before starting mariadb
5. Halt apache in the NC VM and update the NC config
  - overwrite 'passwordsalt' and 'secret' in the config from pelican
  - add `putenv('LDAPTLS_CACERT=/etc/ssl/certs/cacism3.pem');`
    > check the existence of `/etc/ssl/certs/cacism3.pem` on the NC VM
  - overwrite 'datadirectory'
    > check ownership (apache:apache) on the full datadirectory folder before starting apache
6. Check the instance
  - `sudo -u apache php occ status`
  - `sudo -u apache php occ ldap:show-config`
  - `sudo -u apache php occ ldap:test-config ""`
  - go to "https://nextcloud.test.cism.ucl.ac.be" as admin, then as a user

# Make Nextcloud lighter and cleaner

1. Nextcloud data relief
  - clean the files
    > `sudo -u apache php occ files:cleanup`
  - remove remnants users with `01_delete_remnants.sh`
    > `sudo -u apache php occ ldap:show-remnants`
  - clean trash
    > `sudo -u apache php occ trashbin:clean --all-users`
  - remove the old users
    > based on CISM LDAP status (inactive account since 2 years)
    - (&(objectClass=person)(expirationDate>=202301010000+0100))
    - (&(&(objectClass=person)(expirationDate>=202301010000+0100))(uid=%uid))
  - remove new remnants users (after LDAP filters changes)
    > change the LDAPinterval (default: 51min for 50 users test) `'ldapUserCleanupInterval' => 5,`
  - remove the external mounts with `02_delete_all_external.sh`
    > take a while (~3h)
  - remove the guests users
    > `sudo -u apache php occ user:list | grep "Guest"`
    > `sudo -u apache php occ user:list | grep "@"`
2. Nextcloud data relief
  - remove the cache in the DB (unofficial)
    > oc_filecache (> 54789 MB)
    > `sudo -u apache php occ files:scan -vvv --all`
  - ?? remove the shared files and folders ??
3. Start the instance and check it
4. Halt NC host and:
  - rsync the mysql folder from DB host
  - rsync the Nextcloud folder from NC host
  - rsync the NC data folder from NC host

# Migration files --> S3

1. Disable cron:  `mv /etc/cron.d/nextcloud /var/www/html/nextcloud/etc_cron.d_nextcloud`
2. Apply `nextcloud-S3-local-S3-migration`
3. Check the instance
4. Enable cron

> !!! S3 migration: external mounts lost & shared files lost !!!

# Nextcloud improved + S3

1. Deploy a new Nextcloud instance (S3) with OpenStack (same NC release + MariaDB **10.5.11**)
  > minimum 200GB for DB host, minimum 200GB for NC
2. Halt NC on Vagrant host and
  - rsync the mysql folder
  - rsync the Nextcloud folder
  - rsync the NC data folder
3. Start the new instance and check it
