Skip to content

Commit

Permalink
Merge pull request #468 from haiwen/rewrite_migrate_from_non_docker
Browse files Browse the repository at this point in the history
fix: migrate from non-docker
  • Loading branch information
freeplant authored Mar 4, 2025
2 parents d136aa9 + 804890f commit a4e3337
Showing 1 changed file with 54 additions and 70 deletions.
124 changes: 54 additions & 70 deletions manual/setup/migrate_non_docker_to_docker.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# 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 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 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. 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.

## 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`:
Expand All @@ -39,7 +41,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.

Expand All @@ -49,73 +51,69 @@ 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

## 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:
## Deploy the Seafile Docker

=== "Seafile CE"
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.

```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
```
!!! note "Use *external MySQL service* or the *old MySQL service*"
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.

=== "Seafile Pro"
## Recovery libraries data for Seafile Docker

```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
```
Firstly, you should stop the Seafile server before recovering Seafile libraries data:

Then modify the `.env` according to your configurations.
```sh
docker compose down
```

!!! 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**.
Then recover the data from backuped file:

```sh
cp /backup/data/* /opt/seafile-data/seafile
```

## Create the directory and recovery data for Seafile Docker
## Recover the Database (only for the new MySQL service used in 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:
1. Add a temporary persistent directory, where the database backup files are, to the `seafile-server.yml` for service `db`:

```sh
mkdir -p /opt/seafile-data/seafile
```yml
services:
db:
volumes:
...
- "<your-path-to-database-backup-files>:/tmp_sqls"
...
```

# recover seafile data
cp /backup/data/* /opt/seafile-data/seafile
```
2. Start the database service **Only**:

## Recover the Database (only if not use an existed MySQL)
```sh
docker compose up -d --no-deps db
```

You should start the services Firstly, otherwise you cannot connect to MySQL service (`mariadb` now in docker-compose Seafile):
3. Enter the container and *Mariadb* environment:`

```sh
docker compose up -d
```
```sh
docker exec -it seafile-mysql bash
```

After startuping the MySQL service, you should create the MySQL user (e.g., `seafile`, defined in your `.env` file) and add related permissions:
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`

```
## Note, change the password according to the actual password you use
GRANT ALL PRIVILEGES ON *.* TO 'seafile'@'%' IDENTIFIED BY 'your-password' WITH GRANT OPTION;
5. Finally, exit the container and stop the Mariadb service

## 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'@'%';
```
```sh
docker compose down
```

Then you can follow [here](../administration/backup_recovery.md#restore-the-databases-1) to restore the database data
and remove the temporary persistent directory in `seafile-server.yml` (i.e., undo the step 1)

## Restart the services

Expand All @@ -125,18 +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.
```
By the way, you can shutdown the old MySQL service, if it is not a dependency of other services, .

0 comments on commit a4e3337

Please sign in to comment.