harbor/migration/README.md

79 lines
3.1 KiB
Markdown
Raw Normal View History

2016-07-12 11:58:15 +02:00
# Harbor upgrade and database migration guide
2016-06-03 12:01:07 +02:00
2016-07-12 11:58:15 +02:00
When upgrading your existing Habor instance to a newer version, you may need to migrate the data in your database. Refer to [change log](changelog.md) to find out whether there is any change in the database. If there is, you should go through the database migration process. Since the migration may alter the database schema, you should **always** back up your data before any migration.
2016-05-09 08:11:34 +02:00
2016-07-12 11:58:15 +02:00
*If your install Harbor for the first time, or the database version is the same as that of the lastest version, you do not need any database migration.*
2016-05-09 08:11:34 +02:00
2016-06-28 10:49:08 +02:00
2016-07-12 11:58:15 +02:00
**NOTE:** You must backup your data before any data migration.
2016-06-28 10:49:08 +02:00
2016-07-12 11:58:15 +02:00
### Upgrading Harbor and migrating data
1. Log in to the machine that Harbor runs on, back up Harbor's configuration files.
```sh
mkdir -p /tmp/harbor/config
cp -r Deploy/config /tmp/harbor/config
cp Deploy/harbor.cfg /tmp/harbor
2016-05-09 08:11:34 +02:00
```
2016-07-12 11:58:15 +02:00
2. Next, stop existing Harbor service if it is still running:
2016-06-03 12:01:07 +02:00
```
2016-07-12 11:58:15 +02:00
cd ../../Deploy/
2016-06-03 12:01:07 +02:00
docker-compose down
```
2016-07-12 11:58:15 +02:00
3. Get the lastest source code from Github:
```sh
$ git clone https://github.com/vmware/harbor
```
4. Before upgrading Harbor, perform data migration first.
The directory **migration/** contains the tool for migration. The first step is to update values of `db_username`, `db_password`, `db_port`, `db_name` in **migration.cfg** so that they match your system's configuration.
5. The migration tool is delivered as a container, so you should build the image from its Dockerfile:
```
cd migration/harbor-migration
docker build -t migrate-tool .
```
6. Back up database to a directory such as `/path/to/backup`. You need to create the directory if it does not exist.
2016-06-03 12:01:07 +02:00
```
2016-06-03 12:30:59 +02:00
docker run -ti --rm -v /data/database:/var/lib/mysql -v /path/to/backup:/harbor-migration/backup migrate-tool backup
2016-06-03 12:01:07 +02:00
```
2016-07-12 11:58:15 +02:00
7. Upgrade database schema and migrate data:
2016-06-03 12:01:07 +02:00
2016-07-12 11:58:15 +02:00
```
docker run -ti --rm -v /data/database:/var/lib/mysql migrate-tool up head
```
2016-06-03 12:01:07 +02:00
2016-07-12 11:58:15 +02:00
8. Change to `Deploy/` directory, configure Harbor by updating the file `harbor.cfg`, you may need to refer to the configuration files you backed up during step 1. Refer to [Installation & Configuration Guide ](../docs/installation_guide.md) for more info.
2016-06-03 12:01:07 +02:00
2016-07-12 11:58:15 +02:00
9. If HTTPS has been enabled for Harbor before, restore the `nginx.conf` and key/certificate files from the backup files in Step 1. Refer to [Configuring Harbor with HTTPS Access](../docs/configure_https.md) for more info.
2016-06-03 12:01:07 +02:00
2016-07-12 11:58:15 +02:00
10. Run the `./prepare` script to generate necessary config files.
11. Rebuild Harbor and restart the registry service
2016-06-03 12:01:07 +02:00
```
2016-07-12 11:58:15 +02:00
docker-compose up --build -d
2016-06-03 12:01:07 +02:00
```
2016-07-12 11:58:15 +02:00
### Migration tool reference
- Use `help` command to show instructions of the migration tool:
2016-05-09 08:11:34 +02:00
2016-07-12 11:58:15 +02:00
```docker run --rm migrate-tool help```
2016-05-13 12:05:27 +02:00
2016-07-12 11:58:15 +02:00
- Use `test` command to test mysql connection:
2016-05-13 12:05:27 +02:00
2016-06-03 12:30:59 +02:00
```docker run --rm -v /data/database:/var/lib/mysql migrate-tool test```
2016-05-09 08:11:34 +02:00
2016-07-12 11:58:15 +02:00
- Restore database from backup file in `/path/to/backup`
2016-05-09 08:11:34 +02:00
```
2016-06-03 12:30:59 +02:00
docker run -ti --rm -v /data/database:/var/lib/mysql -v /path/to/backup:/harbor-migration/backup migrate-tool restore
2016-05-09 08:11:34 +02:00
```