Nextcloud
2024-10-24
Migrating
Backup: Run these commands on old server machine
Assumes Nextcloud instance is installed on DietPi
sudo systemctl stop nginx.service
Put Nextcloud into maintenance mode:
cd /var/www/nextcloud
sudo -u www-data php occ maintenance:mode --on
Backup the directories:
DATE=$(date '+%Y%m%d')
sudo rsync -aAX /etc/nginx /home/dietpi/nginx-backup_$DATE
sudo rsync -aAX /var/www/nextcloud /home/dietpi/nextcloud-dir-backup_$DATE
sudo rsync -aAX /mnt/dietpi_userdata/nextcloud_data /home/dietpi/nextcloud-data-backup_$DATE
Dump the MariaDB database:
sudo mysqldump --single-transaction --default-character-set=utf8mb4 -h localhost -u <username> -p <password> nextcloud > /home/dietpi/nextcloud-db-backup_$DATE.sql
Rsync the files over to the new server machine:
sudo rsync -aAX \
/home/dietpi/nginx-backup_$DATE \
/home/dietpi/nextcloud-dir-backup_$DATE \
/home/dietpi/nextcloud-data-backup_$DATE \
/home/dietpi/nextcloud-db-backup_$DATE.sql \
dietpi@<new server ip>:/home/dietpi
Restore: Run these commands on new server machine
Assuming the web server is stopped.
Move the nextcloud-dir and nextcloud-data directories to their correct locations. First ensure the default directories are removed.
sudo rm -rf /etc/nginx
sudo rm -rf /var/www/nextcloud
sudo rm -rf /mnt/dietpi_userdata/nextcloud_data
sudo mv nginx_$DATE /etc/nginx
sudo mv nextcloud-dir-backup_$DATE /var/www/nextcloud
sudo mv nextcloud-data-backup_$DATE /mnt/dietpi_userdata/nextcloud_data
sudo chown -R dietpi:dietpi /mnt/dietpi_userdata/nextcloud_data
sudo chown -R root:root /etc/nginx
Create the nextcloud database in MariaDB:
sudo mysql -h localhost -u root -p <password> -e "DROP DATABASE nextcloud"
sudo mysql -h localhost -u root -p <password> -e "CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"
sudo mysql -h localhost -u root -p <password> nextcloud < /home/dietpi/nextcloud-db-backup_$DATE.sql
Take Nextcloud out of maintenance mode:
You may have to change the ‘oc_admin’ database user password for occ commands to work.
sudo -u www-data php occ maintenance:mode --off
Restart the services:
sudo systemctl restart nginx mariadb redis-server php8.2-fpm