2016-07-12 11:58:15 +02:00
# Harbor upgrade and database migration guide
2016-06-03 12:01:07 +02:00
2016-09-22 08:49:46 +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 ](../migration/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
2017-01-23 14:17:06 +01:00
1. Log in to the host that Harbor runs on, stop and remove existing Harbor instance if it is still running:
2016-06-03 12:01:07 +02:00
```
2017-01-04 11:45:26 +01:00
cd harbor
2016-06-03 12:01:07 +02:00
docker-compose down
```
2016-07-12 11:58:15 +02:00
2017-01-23 14:17:06 +01:00
2. Back up Harbor's current files so that you can roll back to the current version when it is necessary.
2016-07-12 11:58:15 +02:00
```sh
2017-01-04 11:45:26 +01:00
cd ..
2016-07-13 09:42:47 +02:00
mv harbor /tmp/harbor
```
2017-01-23 14:17:06 +01:00
3. Get the lastest Harbor release package from Github:
2017-01-04 11:45:26 +01:00
https://github.com/vmware/harbor/releases
2016-07-12 11:58:15 +02:00
2016-11-07 13:13:20 +01:00
4. Before upgrading Harbor, perform database migration first. The migration tool is delivered as a docker image, so you should pull the image from docker hub:
2016-07-12 11:58:15 +02:00
```
2016-11-07 13:13:20 +01:00
docker pull vmware/harbor-db-migrator
2016-07-12 11:58:15 +02:00
```
2016-11-07 13:13:20 +01:00
5. Back up database to a directory such as `/path/to/backup` . You need to create the directory if it does not exist. Also, note that the username and password to access the db are provided via environment variable "DB_USR" and "DB_PWD"
2016-06-03 12:01:07 +02:00
```
2016-11-07 13:13:20 +01:00
docker run -ti --rm -e DB_USR=root -e DB_PWD=xxxx -v /data/database:/var/lib/mysql -v /path/to/backup:/harbor-migration/backup vmware/harbor-db-migrator backup
2016-06-03 12:01:07 +02:00
```
2016-11-07 13:13:20 +01:00
6. Upgrade database schema and migrate data:
2016-06-03 12:01:07 +02:00
2016-07-12 11:58:15 +02:00
```
2016-11-07 13:13:20 +01:00
docker run -ti --rm -e DB_USR=root -e DB_PWD=xxxx -v /data/database:/var/lib/mysql vmware/harbor-db-migrator up head
2016-07-12 11:58:15 +02:00
```
2016-06-03 12:01:07 +02:00
2017-01-23 14:17:06 +01:00
7. Unzip the new Harbor package and change to `./harbor` as the working directory. Configure Harbor by modifying the file `harbor.cfg` ,
you may need to refer to the configuration files you've backed up during step 2.
2017-01-23 14:24:25 +01:00
Refer to [Installation & Configuration Guide ](../docs/installation_guide.md ) for more information.
2017-01-23 14:17:06 +01:00
Since the content and format of `harbor.cfg` may have been changed in the new release, **DO NOT directly copy `harbor.cfg` from previous version of Harbor.**
2016-06-03 12:01:07 +02:00
2017-01-23 14:24:25 +01:00
8. Under the directory `./harbor` , run the `./install.sh` script to install the new Harbor instance.
2016-07-12 11:58:15 +02:00
2016-07-13 09:42:47 +02:00
### Roll back from an upgrade
For any reason, if you want to roll back to the previous version of Harbor, follow the below steps:
1. Stop and remove the current Harbor service if it is still running.
```
2017-01-04 11:45:26 +01:00
cd harbor
2016-07-13 09:42:47 +02:00
docker-compose down
```
2. Restore database from backup file in `/path/to/backup` .
```
2016-11-07 13:13:20 +01:00
docker run -ti --rm -e DB_USR=root -e DB_PWD=xxxx -v /data/database:/var/lib/mysql -v /path/to/backup:/harbor-migration/backup vmware/harbor-db-migrator restore
2016-07-13 09:42:47 +02:00
```
2017-01-23 14:17:06 +01:00
3. Remove current Harbor instance.
2016-07-13 09:42:47 +02:00
```
rm -rf harbor
```
2017-01-04 11:45:26 +01:00
4. Restore the older version package of Harbor.
2016-07-13 09:42:47 +02:00
```sh
mv /tmp/harbor harbor
```
2017-01-23 14:17:06 +01:00
5. Restart Harbor service using the previous configuration.
If previous version of Harbor was installed by a release build:
2016-07-13 09:42:47 +02:00
```sh
2017-01-04 11:45:26 +01:00
cd harbor
2017-01-23 14:17:06 +01:00
./install.sh
2016-07-13 09:42:47 +02:00
```
2017-01-23 14:17:06 +01:00
2017-01-23 14:24:25 +01:00
If your previous version of Harbor was installed from source code:
2017-01-04 11:45:26 +01:00
```sh
cd harbor
2017-01-23 14:17:06 +01:00
docker-compose up --build -d
2017-01-04 11:45:26 +01:00
```
2016-07-13 09:42:47 +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-11-07 13:13:20 +01:00
```docker run --rm -e DB_USR=root -e DB_PWD=xxxx vmware/harbor-db-migrator 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-11-07 13:13:20 +01:00
```docker run --rm -e DB_USR=root -e DB_PWD=xxxx -v /data/database:/var/lib/mysql vmware/harbor-db-migrator test```
2016-05-09 08:11:34 +02:00