techne/nextcloud.org

78 lines
2.5 KiB
Org Mode
Raw Normal View History

2024-09-21 04:17:26 +02:00
#+title: Nextcloud
#+setupfile: ../org-templates/page.org
** Migrating
*** Backup: Run these commands on old server machine
#+begin_quote
Assumes Nextcloud instance is installed on DietPi
#+end_quote
#+begin_src shell
sudo systemctl stop nginx.service
#+end_src
Put Nextcloud into maintenance mode:
#+begin_src shell
cd /var/www/nextcloud
sudo -u www-data php occ maintenance:mode --on
#+end_src
Backup the directories:
#+begin_src shell
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
#+end_src
Dump the MariaDB database:
#+begin_src shell
sudo mysqldump --single-transaction --default-character-set=utf8mb4 -h localhost -u <username> -p <password> nextcloud > /home/dietpi/nextcloud-db-backup_$DATE.sql
#+end_src
Rsync the files over to the new server machine:
#+begin_src shell
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
#+end_src
*** 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.
#+begin_src shell
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
#+end_src
Create the nextcloud database in MariaDB:
#+begin_src shell
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
#+end_src
Take Nextcloud out of maintenance mode:
#+begin_quote
You may have to change the 'oc_admin' database user password for occ commands to work.
#+end_quote
#+begin_src shell
sudo -u www-data php occ maintenance:mode --off
#+end_src
Restart the services:
#+begin_src shell
sudo systemctl restart nginx mariadb redis-server php8.2-fpm
#+end_src