Introduction
In this guide, we’ll walk you through the step-by-step process of change or replace the hard drive for Nextcloud data storage on your Ubuntu Server. From backing up your data to updating configurations, this article covers everything you need to know to perform a smooth and safe migration.
Steps to be Done to Change or Replace Hard Drive for the Data
Step 1: Backup All Data
To backup all Nextcloud data copy you need to execute following command:
rsync -av /path/to/nextcloud/data /path/to/backup
REMEMBER: If you’re unsure where Nextcloud stores your user data, you can find the location specified in the configuration file, typically located at /var/www/html/config/config.php
.
more /var/www/html/config/config.php
Output:
'datadirectory' => '/opt/data/disk2',
Step 2: Install new Hard Drive to the Server and Reboot it
Install new hard drive in your environment and reboot your server.
Step 3: Check Install Disks to Find Logical Name
To checked install disks in your Ubuntu, you need to execute the following command:
lshw -C disk
root@nextcloud:~# lshw -C disk
*-disk:0
description: SCSI Disk
product: Virtual disk
vendor: VMware
physical id: 0.0.0
bus info: scsi@32:0.0.0
logical name: /dev/sda
version: 2.0
size: 16GiB (17GB)
capabilities: gpt-1.00 partitioned partitioned:gpt
configuration: ansiversion=6 guid=ee8a8a6e-fc7e-47a8-919b-530d08a6097b logicalsectorsize=512 sectorsize=512
*-disk:1
description: SCSI Disk
product: Virtual disk
vendor: VMware
physical id: 0.2.0
bus info: scsi@32:0.2.0
logical name: /dev/sdb -> New Hard Drive
version: 2.0
size: 100GiB (107GB)
capabilities: partitioned partitioned:dos
configuration: ansiversion=6 logicalsectorsize=512 sectorsize=512 signature=3e350404
New hard drive is located under:
logical name: /dev/sdb
More information how to add a new HDD you can find at this link.
Step 4: Create partition on the new HDD
Create a partition, format it and mount it to new location. More information how to do this steps you can find in this link.
Step 5: Stop Nextcloud Application
To shut down the Nextcloud application, you need to stop both the web server and the MySQL service. You can accomplish this by running the following commands:
systemctl stop apache2
systemctl stop mysql
Step 6: Move all data from NextCloud data location to the new disk (temp location)
To copy the data to the new hard drive:
cp -a /opt/data/disk2/. /opt/data/disk3
- /opt/data/disk2 → Old hard drive
- /opt/data/disk3 → New hard drive
It is very important to check if all data are copied. To compare the number of files on two locations you can use the following command:
find /opt/data/disk2 -type f | wc -l
find /opt/data/disk3 -type f | wc -l
Output must be the same!
Step 7: Demount the old NextCloud Hard Drive
To unmount the old hard drive, you need to execute the following command:
sudo umount /opt/data
How to find where is old disk mounted? Execute the following command:
root@nextcloud:/var/www/html/config# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 794M 2.5M 792M 1% /run
/dev/sda2 16G 12G 3.4G 78% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sdb1 98G 54G 40G 58% /opt/data/ -> Drive with old data
tmpfs 794M 4.0K 794M 1% /run/user/1000
Step 8: Edit /etc/fstab
, Remove Old Hard Drive and Reboot the Server
Edit /etc/fstab
and remove line where is the disk mounted.
sudo nano /etc/fstab
Output is something like:
UUID=589bb1bc-1c83-46fe-83e9-ed84053c7cbe / ext4 defaults 0 0
/dev/sdb1 /opt/data/disk2 ext4 defaults 0 1
/swap.img none swap sw 0 0
Step 9: Edit /etc/fstab
, and Mount new Hard Drive
Edit /etc/fstab
and add line to mount new disk to the data location
sudo nano /etc/fstab
I added the following line in the file sudo nano /etc/fstab
file
/dev/sdc1 /opt/data/disk2 ext4 defaults 0 1
I mounted it to the same location so I do not need to change Nextcloud configuration file.
Step 10:Change Ownership of the Data
Change the ownership of the data, executing the following command:
chown -R www-data:www-data /opt/data/disk2
Step 11: Start Nextcloud Application
To start Nextcloud application, execute the following commands:
systemctl start apache2
systemctl start mysql