Moving Nextcloud’s data directory from one to another location 1


I found this an interesting topic on help.nextcloud.com. Popular topic too, but unfortunatly closed, after Forum Moderator JasonBayton (Thank you) provided both a non-supported and the officially supported solution.

I imagine the topic:

Is there a safe and reliable way to move data directory out of web root?

so popular, because many find themselves short of space or wanting to expand, after using Nextcloud even for a short while.

Raspberry Pi model 3 with a 3Tb WD

Nextcloud 11.0.4 with php5 has a 3Tb WD

My first encounter with Nextcloud was couple of weeks ago, when I installed it using Berryboot on one of my Raspberry Pi’s. Liked it so much went ahead and downloaded the NextCloudPi.img from https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/ And booted on the other and latest RPI3. This one was even faster (php7 instead of php5). A very user friendly system that works almost out of the box. With this ready to go image of Nextcloud, there isn’t much to do, just personalize and getting ports forwarded, if like me you want to a fully working cloud. My First RPImodel3 initally installed using Berryboot came with Nextcloud 11.0.4 has a 3Tb WD drive looking like this (right):

The 2nd RPI model 3 was set up in less suitable way, with a self powered, usb adapter to re-use a 2Tb internal drive, looks like this (below/left):

Internal 1.8Tb drive re-used

Nextcloud 12.0.3 PHP7 has a 1.8Tb internal WD with usb adaptor

So when I came across the Nexcloudbox, it seemed a much better solution and I ordered one right away (57euro w*f). Couldn’t wait for it to arrive so downloaded image file and used dd to get it on a 32Gb micro sd card.  I enabled ssh, simply by adding an empty text file named ssh in the /boot folder, as it is now my preferred way to control rpi’s and linux servers/pc’s in general.

A week went by, before delivery, as I was getting acquainted with the Nextcloud server’s web interface, desktop clients in Linux Mint and Ubuntu and the Android Mobile client on my phone, all working wonderfully well, to my growing enthusiasm for the whole of the project. With all sorts of amazing apps that are available, and installed with simple click, in the backend of Nextcloud; External drive app, an email client app and radio app to name a few.

By the time the Nextcloudbox arrived, I’d backed up quite a bit of data to my Nextcloud instances, liking it more by the day and not at all willing to risk breaking my install. Hence the title of this post, and how I went about moving my data directory from my old 2Tb 3,5″ to the new 1Tb 2,5″ installed inside the Nextcloudbox.

First I formatted the drive with Gparted on my Laptop, creating basic dos partition table and a single ext4 format partition. Then connected it to the RPI-old-drive system. I had already created a mount point and added a line to /etc/fstab for the old drive. I just created a second mount point for the new drive. I use UUID whenever in need of mounting permanently in /etc/fstab.

Finding the uuid of a disk is quite simple with the ls command

$ ls -lh /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Oct 9 14:27 034db2d1-e044-4f90-b847-69809ccf92d7 -> ../../sda1
lrwxrwxrwx 1 root root 15 Oct 9 14:27 9a7608bd-5bff-4dfc-ac1d-63a956744162 -> ../../mmcblk0p2
lrwxrwxrwx 1 root root 15 Oct 9 14:27 B60A-B262 -> ../../mmcblk0p1
lrwxrwxrwx 1 root root 10 Oct 9 14:27 d549f07b-1751-40c1-bafb-3ca162605aca -> ../../sdb1

  • Temporarily mounted the new drive,
  • Temporarily stopped cron by adding a # at beginning of the line of www-data’s crontab.
  • Stopped Apache2 webserver.
  • Created a directory with same name ‘/ncdata’ as on the old one and copied all it’s content to the new one.
  • Unmount both drives: sudo umount /dev/sda1 /dev/sdb1
  • Edited fstab, swapping mount points, so the new drive gets mounted at moint point of old drive.
  • Remount both drives with : sudo mount -a
  • Check if mounted correctly with : df  -h
  • Start Apache2 webserver
  • Edit crontab to remove the #
  • Visit webinterface to check if all is working correctly, which it was.

My /etc/fstab :

proc            /proc           proc    defaults          0       0

PARTUUID=09efbd88-01  /boot           vfat    defaults          0       2

PARTUUID=09efbd88-02  /               ext4    defaults,noatime  0       1

# a swapfile is not a swap partition, no line here#   use  dphys-swapfile swap[on|off]  for that

UUID=d549f07b-1751-40c1-bafb-3ca162605aca /media/user/usb1t ext4 rw,users 0 0

UUID=034db2d1-e044-4f90-b847-69809ccf92d7 /media/user/usb2t ext4 rw,users 0 0

NextCloudBox closedNextCloudBox open and up and running

There were and are some other folders in the old drive’s root directory, galleries with photo collections among others. I had already made these available in my Nextcloud instance through the external drives app. All I needed to adjust was one digit, usb2t=>usb1t, in the PATH field of these folders. The (piwigo) photo folders play nicely as slideshows and load reasonably fast and I’m very happy with my own personal cloud service in general, providing close to 3Tb of safe private self-owned and -controlled storage. 😉 I love Nextcloud, in adopting it, I’ll be saying partly goodbye to at least one nice (piwigo) open source and a few commercial (GoogleDrive, Dropbox, AmazonCloud) partners. Thank’s for all the years of of solid services, fare thee well. And Hello Nextclouders, thanks sofar, glad to meet your acquaintance, see you all, soon enough, were #nextclouders meet! OliverV

 

$ df -h
Filesystem Size Used Avail Use% Mounted onNextCloudPi-v0.31.14-is-up-to-date
/dev/root 29G 2.0G 26G 8% /
devtmpfs 460M 0 460M 0% /dev
tmpfs 464M 0 464M 0% /dev/shm
tmpfs 464M 6.3M 458M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 464M 0 464M 0% /sys/fs/cgroup
/dev/mmcblk0p1 42M 21M 21M 52% /boot
/dev/sda1 917G 6.7G 864G 1% /home/user/usb2t
/dev/sdb1 1.8T 7.0G 1.7T 1% /home/user/usb1t
tmpfs 93M 0 93M 0% /run/user/1000

 

$ cat /etc/*-release
PRETTY_NAME=”Raspbian GNU/Linux 9 (stretch)”
NAME=”Raspbian GNU/Linux”
VERSION_ID=”9″
VERSION=”9 (stretch)”
ID=raspbian
ID_LIKE=debian
HOME_URL=”http://www.raspbian.org/”
SUPPORT_URL=”http://www.raspbian.org/RaspbianForums”
BUG_REPORT_URL=”http://www.raspbian.org/RaspbianBugs”

 

$ php –version
PHP 7.0.19-1 (cli) (built: May 11 2017 14:04:47) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.19-1, Copyright (c) 1999-2017, by Zend Technologies

 

$ apache2 -v
Server version: Apache/2.4.25 (Raspbian)
Server built: 2017-09-19T18:58:57

 

Installed(?)& enabled ufw for basic protection, will be taking a look shortly at fail2ban and other, included in the nextcloudpi-config tool.

 

I don’t know if the method used will find approval or will be considered supported, try at your own risk of losing data untill, one will find time to read and comment, thanks in advance, if one does.


One thought on “Moving Nextcloud’s data directory from one to another location

  • Reply
    Excellent Liften

    This website was… how do I say it? Relevant!! Finally I’ve
    found something which helped me. Thanks!

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Deze website gebruikt Akismet om spam te verminderen. Bekijk hoe je reactie-gegevens worden verwerkt.