---
# System prepended metadata

title: CVAT 備份方法

---

# CVAT 備份方法
```
export CVAT_HOST=192.168.50.15
```
# 版本切換
## 切換到指定 tag
```
git checkout -b v2.2.0
```

## 切換到指定位置
```
git checkout 79ce99acc59e8558d9a7589c41050a258dd3c909
```

# 備份
https://opencv.github.io/cvat/docs/administration/advanced/backup_guide/

## 備份資料庫
```
docker exec -it cvat_db pg_dumpall > cvat.db.dump
```

## 還原資料庫
```
docker compose down

 docker exec -i cvat_db psql -q -d postgres < cvat.db.dump
```
## 備份 volumes
```
docker-compose stop

mkdir backup
docker run --rm --name temp_backup --volumes-from cvat_db -v $(pwd)/backup:/backup ubuntu tar -czvf /backup/cvat_db.tar.gz /var/lib/postgresql/data
docker run --rm --name temp_backup --volumes-from cvat_server -v $(pwd)/backup:/backup ubuntu tar -czvf /backup/cvat_data.tar.gz /home/django/data
# [optional]
docker run --rm --name temp_backup --volumes-from cvat_elasticsearch -v $(pwd)/backup:/backup ubuntu tar -czvf /backup/cvat_events.tar.gz /usr/share/elasticsearch/data

```

## 還原備份 volumes
```
cd <path_to_backup_folder>
docker run --rm --name temp_backup --volumes-from cvat_db -v $(pwd):/backup ubuntu bash -c "cd /var/lib/postgresql/data && tar -xvf /backup/cvat_db.tar.gz --strip 4"
docker run --rm --name temp_backup --volumes-from cvat_server -v $(pwd):/backup ubuntu bash -c "cd /home/django/data && tar -xvf /backup/cvat_data.tar.gz --strip 3"
# [optional]
docker run --rm --name temp_backup --volumes-from cvat_elasticsearch -v $(pwd):/backup ubuntu bash -c "cd /usr/share/elasticsearch/data && tar -xvf /backup/cvat_events.tar.gz --strip 4"

```

# 清除快取
```
docker exec -it cvat_server bash -c 'rm -r data/*/*/export_cache/'
docker exec -it cvat_server bash -c 'rm -r data/cache/'
```