2019-05-10 07:03:01 +02:00
# Harbor upgrade and migration guide
2016-06-03 12:01:07 +02:00
2019-07-29 14:37:16 +02:00
This guide only covers upgrade and migration to version >= v1.8.0
2019-05-10 07:03:01 +02:00
When upgrading your existing Harbor instance to a newer version, you may need to migrate the data in your database and the settings in `harbor.cfg` .
Since the migration may alter the database schema and the settings of `harbor.cfg` , you should **always** back up your data before any migration.
2016-05-09 08:11:34 +02:00
2018-04-16 13:33:42 +02:00
**NOTE:**
2018-08-01 09:05:47 +02:00
2018-12-02 08:45:51 +01:00
- Again, you must back up your data before any data migration.
- This guide only covers the migration from v1.6.0 to current version, if you are upgrading from earlier versions please
refer to the migration guide in release branch to upgrade to v1.6.0 and follow this guide to do the migration to later version.
- From v1.6.0 on, Harbor will automatically try to do the migrate the DB schema when it starts, so if you are upgrading from v1.6.0
or above it's not necessary to call the migrator tool to migrate the schema.
- For the change in Database schema please refer to [change log ](../tools/migration/db/changelog.md ).
2016-06-28 10:49:08 +02:00
2019-05-10 07:03:01 +02:00
- Since v1.8.0, the configuration of Harbor has changed to `.yml` file, the migrator will transform the configuration
file from `harbor.cfg` to `harbor.yml` . The command will be a little different to perform this migration, please make sure
you follow the steps below.
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:
2017-04-24 10:44:02 +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.
2018-12-05 19:48:35 +01:00
```
2017-08-07 08:38:10 +02:00
mv harbor /my_backup_dir/harbor
2016-07-13 09:42:47 +02:00
```
2019-07-29 14:37:16 +02:00
Back up database (by default in directory `/data/database` )
2018-12-05 19:48:35 +01:00
```
cp -r /data/database /my_backup_dir/
```
2016-07-13 09:42:47 +02:00
2018-10-07 23:41:37 +02:00
3. Get the latest Harbor release package from Github:
2018-08-14 12:47:39 +02:00
https://github.com/goharbor/harbor/releases
2017-04-24 10:44:02 +02:00
2018-04-16 13:33:42 +02:00
4. Before upgrading Harbor, perform migration first. The migration tool is delivered as a docker image, so you should pull the image from docker hub. Replace [tag] with the release version of Harbor (e.g. v1.5.0) in the below command:
2018-12-05 19:48:35 +01:00
```
docker pull goharbor/harbor-migrator:[tag]
```
2016-07-12 11:58:15 +02:00
2019-05-10 07:03:01 +02:00
5. Upgrade from `harbor.cfg` to `harbor.yml`
**NOTE:** You can find the ${harbor_yml} in the extracted installer you got in step `3` , after the migration the file `harbor.yml`
in that path will be updated with the values from ${harbor_cfg}
2016-07-12 11:58:15 +02:00
```
2019-08-27 09:36:11 +02:00
docker run -it --rm -v ${harbor_cfg}:/harbor-migration/harbor-cfg/harbor.yml -v ${harbor_yml}:/harbor-migration/harbor-cfg-out/harbor.yml goharbor/harbor-migrator:[tag] --cfg up
2016-07-12 11:58:15 +02:00
```
2019-02-22 09:34:26 +01:00
**NOTE:** The schema upgrade and data migration of Database is performed by core when Harbor starts, if the migration fails,
please check the log of core to debug.
2016-06-03 12:01:07 +02:00
2018-12-05 19:48:35 +01:00
6. Under the directory `./harbor` , run the `./install.sh` script to install the new Harbor instance. If you choose to install Harbor with components like Notary, Clair, and chartmuseum, refer to [Installation & Configuration Guide ](../docs/installation_guide.md ) for more information.
2018-01-08 10:40:47 +01:00
2017-04-24 10:44:02 +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:
2018-12-02 08:45:51 +01:00
**NOTE:** Roll back doesn't support upgrade across v1.5.0, like from v1.2.0 to v1.7.0. This is because Harbor changes DB to PostgreSQL from v1.7.0, the migrator cannot roll back data to MariaDB.
2018-08-01 09:05:47 +02:00
2016-07-13 09:42:47 +02:00
1. Stop and remove the current Harbor service if it is still running.
2017-04-24 10:44:02 +02:00
```
2017-01-04 11:45:26 +01:00
cd harbor
2016-07-13 09:42:47 +02:00
docker-compose down
```
2018-04-16 13:33:42 +02:00
2018-12-02 08:45:51 +01:00
2. Remove current Harbor instance.
2017-04-24 10:44:02 +02:00
```
2016-07-13 09:42:47 +02:00
rm -rf harbor
```
2018-12-02 08:45:51 +01:00
3. Restore the older version package of Harbor.
2016-07-13 09:42:47 +02:00
```sh
2017-08-07 08:38:10 +02:00
mv /my_backup_dir/harbor harbor
2016-07-13 09:42:47 +02:00
```
2018-12-02 08:45:51 +01:00
2018-12-05 19:48:35 +01:00
4. Restore database, copy the data files from backup directory to you data volume, by default `/data/database` .
2016-07-13 09:42:47 +02:00
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
```