mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
6.4 KiB
159 lines
6.4 KiB
7 years ago
|
---
|
||
|
date: "2017-01-01T16:00:00+02:00"
|
||
2 years ago
|
title: "Backup and Restore"
|
||
7 years ago
|
slug: "backup-and-restore"
|
||
1 year ago
|
sidebar_position: 11
|
||
4 years ago
|
toc: false
|
||
7 years ago
|
draft: false
|
||
2 years ago
|
aliases:
|
||
|
- /en-us/backup-and-restore
|
||
7 years ago
|
menu:
|
||
|
sidebar:
|
||
2 years ago
|
parent: "administration"
|
||
7 years ago
|
name: "Backup and Restore"
|
||
1 year ago
|
sidebar_position: 11
|
||
7 years ago
|
identifier: "backup-and-restore"
|
||
|
---
|
||
|
|
||
|
# Backup and Restore
|
||
|
|
||
3 years ago
|
Gitea currently has a `dump` command that will save the installation to a ZIP file. This
|
||
7 years ago
|
file can be unpacked and used to restore an instance.
|
||
7 years ago
|
|
||
3 years ago
|
## Backup Consistency
|
||
|
|
||
|
To ensure the consistency of the Gitea instance, it must be shutdown during backup.
|
||
|
|
||
|
Gitea consists of a database, files and git repositories, all of which change when it is used. For instance, when a migration is in progress, a transaction is created in the database while the git repository is being copied over. If the backup happens in the middle of the migration, the git repository may be incomplete although the database claims otherwise because it was dumped afterwards. The only way to avoid such race conditions is by stopping the Gitea instance during the backups.
|
||
|
|
||
7 years ago
|
## Backup Command (`dump`)
|
||
|
|
||
6 years ago
|
Switch to the user running Gitea: `su git`. Run `./gitea dump -c /path/to/app.ini` in the Gitea installation
|
||
7 years ago
|
directory. There should be some output similar to the following:
|
||
7 years ago
|
|
||
6 years ago
|
```none
|
||
7 years ago
|
2016/12/27 22:32:09 Creating tmp work dir: /tmp/gitea-dump-417443001
|
||
|
2016/12/27 22:32:09 Dumping local repositories.../home/git/gitea-repositories
|
||
|
2016/12/27 22:32:22 Dumping database...
|
||
|
2016/12/27 22:32:22 Packing dump files...
|
||
|
2016/12/27 22:32:34 Removing tmp work dir: /tmp/gitea-dump-417443001
|
||
|
2016/12/27 22:32:34 Finish dumping in file gitea-dump-1482906742.zip
|
||
|
```
|
||
|
|
||
7 years ago
|
Inside the `gitea-dump-1482906742.zip` file, will be the following:
|
||
7 years ago
|
|
||
1 year ago
|
- `app.ini` - Optional copy of configuration file if originally stored outside the default `custom/` directory
|
||
4 years ago
|
- `custom` - All config or customization files in `custom/`.
|
||
1 year ago
|
- `data` - Data directory (APP_DATA_PATH), except sessions if you are using file session. This directory includes `attachments`, `avatars`, `lfs`, `indexers`, SQLite file if you are using SQLite.
|
||
4 years ago
|
- `gitea-db.sql` - SQL dump of database
|
||
|
- `gitea-repo.zip` - Complete copy of the repository directory.
|
||
|
- `log/` - Various logs. They are not needed for a recovery or migration.
|
||
7 years ago
|
|
||
7 years ago
|
Intermediate backup files are created in a temporary directory specified either with the
|
||
|
`--tempdir` command-line parameter or the `TMPDIR` environment variable.
|
||
7 years ago
|
|
||
3 years ago
|
## Backup the database
|
||
|
|
||
|
The SQL dump created by `gitea dump` uses XORM and Gitea admins may prefer to use the native the MySQL and PostgreSQL dump tools instead. There are still open issues when using XORM for dumping the database that may cause problems when attempting to restore it.
|
||
|
|
||
|
```sh
|
||
|
# mysql
|
||
|
mysqldump -u$USER -p$PASS --database $DATABASE > gitea-db.sql
|
||
|
# postgres
|
||
2 years ago
|
pg_dump -U $USER $DATABASE > gitea-db.sql
|
||
3 years ago
|
```
|
||
|
|
||
6 years ago
|
### Using Docker (`dump`)
|
||
6 years ago
|
|
||
6 years ago
|
There are a few caveats for using the `dump` command with Docker.
|
||
|
|
||
|
The command has to be executed with the `RUN_USER = <OS_USERNAME>` specified in `gitea/conf/app.ini`; and, for the zipping of the backup folder to occur without permission error the command `docker exec` must be executed inside of the `--tempdir`.
|
||
|
|
||
|
Example:
|
||
|
|
||
6 years ago
|
```none
|
||
2 years ago
|
docker exec -u <OS_USERNAME> -it -w <--tempdir> $(docker ps -qf 'name=^<NAME_OF_DOCKER_CONTAINER>$') bash -c '/usr/local/bin/gitea dump -c </path/to/app.ini>'
|
||
6 years ago
|
```
|
||
6 years ago
|
|
||
4 years ago
|
\*Note: `--tempdir` refers to the temporary directory of the docker environment used by Gitea; if you have not specified a custom `--tempdir`, then Gitea uses `/tmp` or the `TMPDIR` environment variable of the docker container. For `--tempdir` adjust your `docker exec` command options accordingly.
|
||
6 years ago
|
|
||
|
The result should be a file, stored in the `--tempdir` specified, along the lines of: `gitea-dump-1482906742.zip`
|
||
|
|
||
7 years ago
|
## Restore Command (`restore`)
|
||
|
|
||
7 years ago
|
There is currently no support for a recovery command. It is a manual process that mostly
|
||
|
involves moving files to their correct locations and restoring a database dump.
|
||
|
|
||
|
Example:
|
||
6 years ago
|
|
||
4 years ago
|
```sh
|
||
4 years ago
|
unzip gitea-dump-1610949662.zip
|
||
|
cd gitea-dump-1610949662
|
||
|
mv data/conf/app.ini /etc/gitea/conf/app.ini
|
||
|
mv data/* /var/lib/gitea/data/
|
||
|
mv log/* /var/lib/gitea/log/
|
||
|
mv repos/* /var/lib/gitea/repositories/
|
||
|
chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea
|
||
|
|
||
|
# mysql
|
||
5 years ago
|
mysql --default-character-set=utf8mb4 -u$USER -p$PASS $DATABASE <gitea-db.sql
|
||
4 years ago
|
# sqlite3
|
||
|
sqlite3 $DATABASE_PATH <gitea-db.sql
|
||
|
# postgres
|
||
|
psql -U $USER -d $DATABASE < gitea-db.sql
|
||
|
|
||
7 years ago
|
service gitea restart
|
||
|
```
|
||
5 years ago
|
|
||
3 years ago
|
Repository Git Hooks should be regenerated if installation method is changed (eg. binary -> Docker), or if Gitea is installed to a different directory than the previous installation.
|
||
5 years ago
|
|
||
|
With Gitea running, and from the directory Gitea's binary is located, execute: `./gitea admin regenerate hooks`
|
||
|
|
||
3 years ago
|
This ensures that application and configuration file paths in repository Git Hooks are consistent and applicable to the current installation. If these paths are not updated, repository `push` actions will fail.
|
||
3 years ago
|
|
||
|
### Using Docker (`restore`)
|
||
|
|
||
|
There is also no support for a recovery command in a Docker-based gitea instance. The restore process contains the same steps as described in the previous section but with different paths.
|
||
|
|
||
|
Example:
|
||
|
|
||
|
```sh
|
||
|
# open bash session in container
|
||
|
docker exec --user git -it 2a83b293548e bash
|
||
|
# unzip your backup file within the container
|
||
|
unzip gitea-dump-1610949662.zip
|
||
|
cd gitea-dump-1610949662
|
||
|
# restore the gitea data
|
||
|
mv data/* /data/gitea
|
||
|
# restore the repositories itself
|
||
|
mv repos/* /data/git/repositories/
|
||
|
# adjust file permissions
|
||
|
chown -R git:git /data
|
||
|
# Regenerate Git Hooks
|
||
|
/usr/local/bin/gitea -c '/data/gitea/conf/app.ini' admin regenerate hooks
|
||
|
```
|
||
|
|
||
|
The default user in the gitea container is `git` (1000:1000). Please replace `2a83b293548e` with your gitea container id or name.
|
||
|
|
||
|
### Using Docker-rootless (`restore`)
|
||
|
|
||
|
The restore workflow in Docker-rootless containers differs only in the directories to be used:
|
||
|
|
||
|
```sh
|
||
|
# open bash session in container
|
||
|
docker exec --user git -it 2a83b293548e bash
|
||
|
# unzip your backup file within the container
|
||
|
unzip gitea-dump-1610949662.zip
|
||
|
cd gitea-dump-1610949662
|
||
|
# restore the app.ini
|
||
|
mv data/conf/app.ini /etc/gitea/app.ini
|
||
|
# restore the gitea data
|
||
|
mv data/* /var/lib/gitea
|
||
|
# restore the repositories itself
|
||
|
mv repos/* /var/lib/gitea/git/repositories
|
||
|
# adjust file permissions
|
||
|
chown -R git:git /etc/gitea/app.ini /var/lib/gitea
|
||
|
# Regenerate Git Hooks
|
||
|
/usr/local/bin/gitea -c '/etc/gitea/app.ini' admin regenerate hooks
|
||
|
```
|