1

So i have a nextcloud server in an EC2 instance, i have an EFS mounted to it but im not sure how to make nextcloud save the files on the EFS instead of EC2. Are there any guides or tutorials out there that shows you how to do such a thing?

Any help or ideas is greatly appreciated!

Thanks

Ghaith Haddad
  • 73
  • 1
  • 3
  • 6

1 Answers1

1

The general process is going to be to stop Nextcloud, move your files from your local instance storage to EFS, move the mount point, and then restart Nextcloud.

It will go something like this:

  1. Mount EFS at a temporary directory.

    sudo mkdir /mnt/efs
    sudo mount -t efs fs-12345678:/ /mnt/efs
    
  2. Stop Nextcloud

    Change to the Nextcloud installation directory, then:

    sudo -u php php occ maintenance:mode --on
    
  3. Move Nextcloud data files to EFS

    sudo mv -v /nextcloud/datadirectory/.??* /nextcloud/datadirectory/.?? /mnt/efs
    
  4. Verify the data directory is empty

    sudo ls -al /nextcloud/datadirectory
    
  5. Unmount EFS from temporary directory

    sudo umount /mnt/efs
    
  6. Mount EFS as the Nextcloud data directory

    sudo mount -t efs fs-12345678:/ /nextcloud/datadirectory
    
  7. Set up the permanent mountpoint in /etc/fstab

    fs-12345678:/ /nextcloud/datadirectory efs _netdev 0 0
    
  8. Fix up ownership and permissions of the mountpoint and files if necessary

  9. Restart Nextcloud

    sudo -u php php occ maintenance:mode --off
    

You should change the usernames and directories shown above to match your own installation.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • Thank you Michael for the detailed explanation. Quick question just to make sure i got this right. So i have my EFS persistently mounted to my EC2 instance, and i should technically un-mount it and mount it to nextcloud instead, but then again nextcloud is installed on EC2? – Ghaith Haddad Aug 14 '19 at 16:51
  • What do you mean by "technically un-mount it and mount it to nextcloud instead"? – Michael Hampton Aug 14 '19 at 16:53
  • step 5 says to unmount efs from temp directory and step 6 is to mount efs as the NC data directory – Ghaith Haddad Aug 14 '19 at 16:56
  • correct me if im wrong but dont i have to change the NC config.php file to have it save the data in a certain directory? – Ghaith Haddad Aug 14 '19 at 16:56
  • @user535562 Of course, you have to specify the data directory in config.php. But you have already done that, right? – Michael Hampton Aug 14 '19 at 17:45
  • it was automatically when i installed nextcloud (manually) the first time and it points to the nextcloud/data folder. shouldn't it point to the efs/nextcloud/data folder instead? im simply assuming so – Ghaith Haddad Aug 14 '19 at 18:33
  • @user535562 Where it points is a choice that you make as an administrator. Coming from decades of experience I prefer to mount the remote filesystem at the correct point in the filesystem tree, rather than try to make a different data directory work. – Michael Hampton Aug 14 '19 at 18:36
  • i see. ok i will try the steps you instructed and see what happens, thank you good sir. – Ghaith Haddad Aug 14 '19 at 18:42
  • quick question, for step 8 could you please elaborate more on it as i don't quite get it – Ghaith Haddad Aug 15 '19 at 15:36
  • @GhaithHaddad The data directory and the files within it need to be owned and writable by the user which PHP runs as. – Michael Hampton Aug 15 '19 at 15:52
  • which is www-data right? – Ghaith Haddad Aug 15 '19 at 16:17
  • @GhaithHaddad That depends on your system. I have no way to know that, as you did not provide those details. – Michael Hampton Aug 15 '19 at 17:18
  • if i have a fresh nextcloud installed with no files on it would it be better if i mounted the EFS to my /var/www/html/ folder then installed NC over there? – Ghaith Haddad Aug 15 '19 at 17:19
  • @GhaithHaddad Yes, if your Nextcloud installation is new, then you can just do that. This post was written to cover the case of existing files and data in Nextcloud. – Michael Hampton Aug 15 '19 at 17:20