From 659382fef569c2dd9ddac74eec5eb5f16c18a36c Mon Sep 17 00:00:00 2001 From: Junxiang Huang Date: Mon, 3 Mar 2025 18:11:52 +0800 Subject: [PATCH 1/2] fix: migrate from non-docker --- manual/setup/migrate_non_docker_to_docker.md | 143 ++++++++++++------- 1 file changed, 92 insertions(+), 51 deletions(-) diff --git a/manual/setup/migrate_non_docker_to_docker.md b/manual/setup/migrate_non_docker_to_docker.md index f137e81e..c9def782 100644 --- a/manual/setup/migrate_non_docker_to_docker.md +++ b/manual/setup/migrate_non_docker_to_docker.md @@ -1,24 +1,27 @@ # Migrate from non-docker Seafile deployment to docker -!!! note "For Seafile cluster" - This document is writting to about the single node, you have to do the following opeartions (except migtating database) in **all nodes** +!!! note + - This document is writting to about the single node, you have to do the following opeartions (except migtating database) in **all nodes** if you are using *Seafile Cluster* + - Normally, we only recommend that you perform the migration operation **on two different machines** according to the solution in this document. If you decide to perform the operation on the same machine, **please pay attention to the corresponding tips in the document**. -The recommended steps to migrate from non-docker deployment to docker deployment are: +The recommended steps to migrate from non-docker deployment to docker deployment on two different machines are: -1. Shutdown Seafile and native Nginx, Memcached -2. Backup Seafile data (database also neet to backup if you are not use an existed MySQL database to deploy non-Docker version Seafile) -3. Create the directory needed for Seafile Docker image to run, and recover the data. (If you are use an existed MySQL database to deploy non-Docker version Seafile, the data from database also need to recover) -4. Download the `.yml` files and `.env`. -5. Start Seafile Docker +1. Upgrade your Seafile server to the latest version. +2. Shutdown the Seafile, Nginx and Memcached according to your situations. +3. Backup MySQL databse and Seafile libraries data. +4. Recover the MySQL database and Seafile libraries in the new machine. +5. Download the `.yml` files and `.env`, and modify it according to your old Seafile configurations +6. Start Seafile Docker +7. Shutdown the old MySQL (or Mariadb) according to your situations. -## Before Migration +## Upgrade your Seafile server -Upgrade the version of the binary package to [latest version](../upgrade/upgrade_notes_for_12.0.x.md), and ensure that the system is running normally. +You have to upgrade the version of the binary package to [latest version](../upgrade/upgrade_notes_for_12.0.x.md) before the migration, and ensure that the system is running normally. !!! tip If you running a very old version of Seafile, you can following the [FAQ item](https://cloud.seatable.io/dtable/external-links/7b976c85f504491cbe8e/?tid=0000&vid=0000&row-id=VYQI9DJfRmCv5NggcX4f0Q) to migrate to the latest version -## Stop Services +## Stop basic Services (except MySQL) ### Stop Seafile server Run the following commands in `/opt/seafile/seafile-server-latest`: @@ -39,7 +42,7 @@ su seafile ./seahub.sh stop ``` -### Stop Nginx, cached server (e.g., *Memcached*), ElasticSearch +### Stop Nginx, cache server (e.g., *Memcached*), ElasticSearch You have to stop the above services to avoid losing data before migrating. @@ -49,15 +52,85 @@ systemctl stop memcached && systemctl disable memcached docker stop es && docker remove es ``` -If you are not using an existed MySQL, you have to shutdown MySQL service too. - -## Backup Seafile +## Backup MySQL database and Seafile server Please follow [here](../administration/backup_recovery.md#backup-and-restore-for-binary-package-based-deployment) to backup: -- Backing up Databases (only if you are not using an existed database to deploy non-Docker version Seafile) +- Backing up MySQL Databases - Backing up Seafile library data +!!! note "Use *external MySQL service* or the *old MySQL service*" + You can skip the step *Backing up MySQL Databases* now for this situation, however, you have to configure the external MySQL server configuration information by following [here](./setup_with_an_existing_mysql_server.md) **after downloading `.yml` and `.env` section**. + + +## Create the directory and recovery data for Seafile Docker + +In Docker-base Seafile, the default working directory for Seafile is `/opt/seafile-data` (you can modify them in the `.env` file). Here, you have to create this directory, and recovery from backuped file: + +```sh +mkdir -p /opt/seafile-data/seafile + +# recover seafile data +cp /backup/data/* /opt/seafile-data/seafile +``` + +## Recover the Database (only for the new MySQL service used in Seafile docker) + +1. Pull *Mariadb* image + + !!! tip + By default, Seafile Docker will use *Mariadb* as the database server and version **10.11** from Seafile 10 Docker. You can specify a new version tag or image according to your situation, but donot forget to modify the `.env` on the next section. + + ```sh + docker pull mariadb:10.11 + ``` + +2. Start the *Mariadb* service with the persistent directory `/opt/seafile-mysql/db`, plase replace `` to your `root` user password and `` to the database backup directory: + + ```sh + docker run -d --rm \ + --name seafile-mariadb \ + -e MYSQL_ROOT_PASSWORD= \ + -e MYSQL_LOG_CONSOLE=true \ + -e MARIADB_AUTO_UPGRADE=1 \ + -v "/opt/seafile-mysql/db:/var/lib/mysql" \ + -v ":/tmp_sqls" \ + mariadb:10.11 + ``` + +3. Enter the container and Mariadb environment:` + + ```sh + docker exec -it seafile-mariadb bash + mariadb -p + ``` + +4. Execute the following SQL sentences, please replace `` to the password of the `seafile` user in the database: + + !!! tip "Default database properties used in Seafile" + You can modify the database configuration (e.g., the user used in Seafile server and relative database name in the following statement), and donot forget to modify in `.env` on the next section, please refer [here](./setup_pro_by_docker.md#downloading-and-modifying-env) for further details. + + + ```sql + CREATE DATABASE `seafile_db` CHARSET UTF8; + CREATE DATABASE `ccnet_db` CHARSET UTF8; + CREATE DATABASE `seahub_db` CHARSET UTF8; + + CREATE USER 'seafile'@'%' IDENTIFIED BY ''; + + GRANT ALL PRIVILEGES ON `ccnet_db`.* to 'seafile'@'%'; + GRANT ALL PRIVILEGES ON `seafile_db`.* to 'seafile'@'%'; + GRANT ALL PRIVILEGES ON `seahub_db`.* to 'seafile'@'%'; + ``` + +5. Then you can follow [here](../administration/backup_recovery.md#restore-the-databases-1) to restore the database data. Your database backup files should be in the directory `/tmp_sqls` + +6. Finally, exit the container and stop the Mariadb service + + ```sh + docker stop seafile-mariadb + ``` + ## Download the docker-compose files You have to download the latest docker-compose files (i.e., series of `.yml` and its configuration file `.env`) in order to startup the relative services: @@ -78,45 +151,11 @@ You have to download the latest docker-compose files (i.e., series of `.yml` and wget https://manual.seafile.com/12.0/repo/docker/caddy.yml ``` -Then modify the `.env` according to your configurations. +Then modify the `.env` according to your configurations, you can refer [here](./setup_pro_by_docker.md#downloading-and-modifying-env) for further details. !!! warning "Important" **Do not** use the `.env` in the non-Docker Seafile server as the `.env` in Docker-base Seafile server directly, which misses some key variables in running Docker-base Seafile. Otherwise the Seafile server may **not work properly**. - -## Create the directory and recovery data for Seafile Docker - -In Docker-base Seafile, the default working directory for Seafile is `/opt/seafile-data` (you can modify them in the `.env` file). Here, you have to create this directory, and recovery from backuped file: - -```sh -mkdir -p /opt/seafile-data/seafile - -# recover seafile data -cp /backup/data/* /opt/seafile-data/seafile -``` - -## Recover the Database (only if not use an existed MySQL) - -You should start the services Firstly, otherwise you cannot connect to MySQL service (`mariadb` now in docker-compose Seafile): - -```sh -docker compose up -d -``` - -After startuping the MySQL service, you should create the MySQL user (e.g., `seafile`, defined in your `.env` file) and add related permissions: - -``` -## Note, change the password according to the actual password you use -GRANT ALL PRIVILEGES ON *.* TO 'seafile'@'%' IDENTIFIED BY 'your-password' WITH GRANT OPTION; - -## Grant seafile user can connect the database from any IP address -GRANT ALL PRIVILEGES ON `ccnet_db`.* to 'seafile'@'%'; -GRANT ALL PRIVILEGES ON `seafile_db`.* to 'seafile'@'%'; -GRANT ALL PRIVILEGES ON `seahub_db`.* to 'seafile'@'%'; -``` - -Then you can follow [here](../administration/backup_recovery.md#restore-the-databases-1) to restore the database data - ## Restart the services Finally, the migration is complete. You can restart the Seafile server of Docker-base by restarting the service: @@ -140,3 +179,5 @@ docker compose up -d Done. ``` + +If your old MySQL service are not a dependency of other services, you can shutdown it. From 804890feb0ccf2fa0a3eaf483ca49bbaefaa7297 Mon Sep 17 00:00:00 2001 From: Junxiang Huang Date: Tue, 4 Mar 2025 10:33:48 +0800 Subject: [PATCH 2/2] opt:adjusting migration strategy --- manual/setup/migrate_non_docker_to_docker.md | 133 ++++++------------- 1 file changed, 38 insertions(+), 95 deletions(-) diff --git a/manual/setup/migrate_non_docker_to_docker.md b/manual/setup/migrate_non_docker_to_docker.md index c9def782..1dff35c8 100644 --- a/manual/setup/migrate_non_docker_to_docker.md +++ b/manual/setup/migrate_non_docker_to_docker.md @@ -1,7 +1,7 @@ # Migrate from non-docker Seafile deployment to docker !!! note - - This document is writting to about the single node, you have to do the following opeartions (except migtating database) in **all nodes** if you are using *Seafile Cluster* + - This document is written to about the single node, you have to do the following opeartions (except migtating database) in **all nodes** if you are using *Seafile Cluster* - Normally, we only recommend that you perform the migration operation **on two different machines** according to the solution in this document. If you decide to perform the operation on the same machine, **please pay attention to the corresponding tips in the document**. The recommended steps to migrate from non-docker deployment to docker deployment on two different machines are: @@ -9,10 +9,9 @@ The recommended steps to migrate from non-docker deployment to docker deployment 1. Upgrade your Seafile server to the latest version. 2. Shutdown the Seafile, Nginx and Memcached according to your situations. 3. Backup MySQL databse and Seafile libraries data. -4. Recover the MySQL database and Seafile libraries in the new machine. -5. Download the `.yml` files and `.env`, and modify it according to your old Seafile configurations -6. Start Seafile Docker -7. Shutdown the old MySQL (or Mariadb) according to your situations. +4. Deploy the Seafile Docker in the new machine. +5. Recover the Seafile libraries and MySQL database in the new machine. +6. Start Seafile Docker and shutdown the old MySQL (or Mariadb) according to your situations. ## Upgrade your Seafile server @@ -56,105 +55,65 @@ docker stop es && docker remove es Please follow [here](../administration/backup_recovery.md#backup-and-restore-for-binary-package-based-deployment) to backup: -- Backing up MySQL Databases +- Backing up MySQL databases - Backing up Seafile library data + +## Deploy the Seafile Docker + +You can follow [here](./overview.md#single-node-deployment) to deploy Seafile with Docker, please use your old configurations when modifying `.env`, and make sure the Seafile server is running normally after deployment. + !!! note "Use *external MySQL service* or the *old MySQL service*" - You can skip the step *Backing up MySQL Databases* now for this situation, however, you have to configure the external MySQL server configuration information by following [here](./setup_with_an_existing_mysql_server.md) **after downloading `.yml` and `.env` section**. + This document is written to migrate from non-Docker version to Docker version Seafile between two different machines. We suggest using the Docker-compose *Mariadb* service (version 10.11 by default) as the database service in after-migration Seafile. If you would like to use an existed MySQL service, always in which situation you try to do migrate operation on the same host or the old MySQL service is the dependency of other services, you have to follow [here](./setup_with_an_existing_mysql_server.md) to deploy Seafile. +## Recovery libraries data for Seafile Docker -## Create the directory and recovery data for Seafile Docker - -In Docker-base Seafile, the default working directory for Seafile is `/opt/seafile-data` (you can modify them in the `.env` file). Here, you have to create this directory, and recovery from backuped file: +Firstly, you should stop the Seafile server before recovering Seafile libraries data: ```sh -mkdir -p /opt/seafile-data/seafile +docker compose down +``` -# recover seafile data +Then recover the data from backuped file: + +```sh cp /backup/data/* /opt/seafile-data/seafile ``` ## Recover the Database (only for the new MySQL service used in Seafile docker) -1. Pull *Mariadb* image +1. Add a temporary persistent directory, where the database backup files are, to the `seafile-server.yml` for service `db`: - !!! tip - By default, Seafile Docker will use *Mariadb* as the database server and version **10.11** from Seafile 10 Docker. You can specify a new version tag or image according to your situation, but donot forget to modify the `.env` on the next section. + ```yml + services: + db: + volumes: + ... + - ":/tmp_sqls" + ... + ``` + +2. Start the database service **Only**: ```sh - docker pull mariadb:10.11 + docker compose up -d --no-deps db ``` -2. Start the *Mariadb* service with the persistent directory `/opt/seafile-mysql/db`, plase replace `` to your `root` user password and `` to the database backup directory: +3. Enter the container and *Mariadb* environment:` ```sh - docker run -d --rm \ - --name seafile-mariadb \ - -e MYSQL_ROOT_PASSWORD= \ - -e MYSQL_LOG_CONSOLE=true \ - -e MARIADB_AUTO_UPGRADE=1 \ - -v "/opt/seafile-mysql/db:/var/lib/mysql" \ - -v ":/tmp_sqls" \ - mariadb:10.11 + docker exec -it seafile-mysql bash ``` -3. Enter the container and Mariadb environment:` +4. Follow [here](../administration/backup_recovery.md#restore-the-databases-1) to recover the database data. Your database backup files should be in the directory `/tmp_sqls` + +5. Finally, exit the container and stop the Mariadb service ```sh - docker exec -it seafile-mariadb bash - mariadb -p + docker compose down ``` -4. Execute the following SQL sentences, please replace `` to the password of the `seafile` user in the database: - - !!! tip "Default database properties used in Seafile" - You can modify the database configuration (e.g., the user used in Seafile server and relative database name in the following statement), and donot forget to modify in `.env` on the next section, please refer [here](./setup_pro_by_docker.md#downloading-and-modifying-env) for further details. - - - ```sql - CREATE DATABASE `seafile_db` CHARSET UTF8; - CREATE DATABASE `ccnet_db` CHARSET UTF8; - CREATE DATABASE `seahub_db` CHARSET UTF8; - - CREATE USER 'seafile'@'%' IDENTIFIED BY ''; - - GRANT ALL PRIVILEGES ON `ccnet_db`.* to 'seafile'@'%'; - GRANT ALL PRIVILEGES ON `seafile_db`.* to 'seafile'@'%'; - GRANT ALL PRIVILEGES ON `seahub_db`.* to 'seafile'@'%'; - ``` - -5. Then you can follow [here](../administration/backup_recovery.md#restore-the-databases-1) to restore the database data. Your database backup files should be in the directory `/tmp_sqls` - -6. Finally, exit the container and stop the Mariadb service - - ```sh - docker stop seafile-mariadb - ``` - -## Download the docker-compose files - -You have to download the latest docker-compose files (i.e., series of `.yml` and its configuration file `.env`) in order to startup the relative services: - -=== "Seafile CE" - - ```sh - wget -O .env https://manual.seafile.com/12.0/repo/docker/ce/env - wget https://manual.seafile.com/12.0/repo/docker/ce/seafile-server.yml - wget https://manual.seafile.com/12.0/repo/docker/caddy.yml - ``` - -=== "Seafile Pro" - - ```sh - wget -O .env https://manual.seafile.com/12.0/repo/docker/pro/env - wget https://manual.seafile.com/12.0/repo/docker/pro/seafile-server.yml - wget https://manual.seafile.com/12.0/repo/docker/caddy.yml - ``` - -Then modify the `.env` according to your configurations, you can refer [here](./setup_pro_by_docker.md#downloading-and-modifying-env) for further details. - -!!! warning "Important" - **Do not** use the `.env` in the non-Docker Seafile server as the `.env` in Docker-base Seafile server directly, which misses some key variables in running Docker-base Seafile. Otherwise the Seafile server may **not work properly**. + and remove the temporary persistent directory in `seafile-server.yml` (i.e., undo the step 1) ## Restart the services @@ -164,20 +123,4 @@ Finally, the migration is complete. You can restart the Seafile server of Docker docker compose up -d ``` -!!! success - After staring the services, you can use `docker logs -f seafile` to follow the logs output from *Seafile* to check the status of the server. When the service is running normally, you will get the following message: - - ``` - Starting seafile server, please wait ... - Seafile server started - - Done. - - Starting seahub at port 8000 ... - - Seahub is started - - Done. - ``` - -If your old MySQL service are not a dependency of other services, you can shutdown it. +By the way, you can shutdown the old MySQL service, if it is not a dependency of other services, .