How can I recover my gitea #10604

Closed
opened 2025-11-02 09:12:24 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @matrixoneken on GitHub (Apr 7, 2023).

Feature Description

I have a gitea on machine 1. But the machin 1 is down.
I need to re-install the gitea on other machine with docker and sqlite3

I have backup of the old gitea on machine 1, the backup is made by "gitea dump"

I want to use the backup to recover the files with following command
rsync -a repos/* /home/software/gitea/data/git/repositories
rsync -a data/* /home/software/gitea/data/gitea
"/home/software/gitea/data/git/repositories " and "/home/software/gitea/data/gitea" is the volumn path of the gitea container

I also enter the docker container and run
"/usr/local/bin/gitea -c '/data/gitea/conf/app.ini' admin regenerate hooks"
but I get error as following:
Failed to run app with [/usr/local/bin/gitea -c /data/gitea/conf/app.ini admin regenerate hooks]: SyncRepositoryHook: unable to pre-remove old hook file '/data/git/repositories/pazhouadmin/test.git/hooks/pre-receive' prior to rewriting: remove /data/git/repositories/pazhouadmin/test.git/hooks/pre-receive: permission denied
the "test.git" id the project in old gitea on machine 1

I restart the gitea container and following error :
61:mustInit() [F] code.gitea.io/gitea/services/auth/source/oauth2.Init failed: Error while loading or creating JWT key: open /data/gitea/jwt/private.pem: permission denied

Can some one help how to restore the old gitea in the new machine. Thank you!

Screenshots

No response

Originally created by @matrixoneken on GitHub (Apr 7, 2023). ### Feature Description I have a gitea on machine 1. But the machin 1 is down. I need to re-install the gitea on other machine with docker and sqlite3 I have backup of the old gitea on machine 1, the backup is made by "gitea dump" I want to use the backup to recover the files with following command rsync -a repos/* /home/software/gitea/data/git/repositories rsync -a data/* /home/software/gitea/data/gitea "/home/software/gitea/data/git/repositories " and "/home/software/gitea/data/gitea" is the volumn path of the gitea container I also enter the docker container and run "/usr/local/bin/gitea -c '/data/gitea/conf/app.ini' admin regenerate hooks" but I get error as following: **Failed to run app with [/usr/local/bin/gitea -c /data/gitea/conf/app.ini admin regenerate hooks]: SyncRepositoryHook: unable to pre-remove old hook file '/data/git/repositories/pazhouadmin/test.git/hooks/pre-receive' prior to rewriting: remove /data/git/repositories/pazhouadmin/test.git/hooks/pre-receive: permission denied** the "test.git" id the project in old gitea on machine 1 I restart the gitea container and following error : **61:mustInit() [F] code.gitea.io/gitea/services/auth/source/oauth2.Init failed: Error while loading or creating JWT key: open /data/gitea/jwt/private.pem: permission denied** Can some one help how to restore the old gitea in the new machine. Thank you! ### Screenshots _No response_
GiteaMirror added the type/question label 2025-11-02 09:12:24 -06:00
Author
Owner

@lunny commented on GitHub (Apr 7, 2023):

Looks like it's permission configuration problems. You need to check the folder permissions.

@lunny commented on GitHub (Apr 7, 2023): Looks like it's permission configuration problems. You need to check the folder permissions.
Author
Owner

@matrixoneken commented on GitHub (Apr 7, 2023):

@lunny thank you, I chmod 777 to path which call permission denied, and now the gitea container can be run.
But I can not recover my "test" project. When I click the project URL , I get a 500 page and the log of the gitea container show
router: completed GET /pazhouadmin/test for 10.10.21.246:55195, 500 Internal Server Error in 21.8ms @ repo/view.go:703(repo.Home)
Can some one help me how to recover my old project in the new gitea. Thank you !

@matrixoneken commented on GitHub (Apr 7, 2023): @lunny thank you, I chmod 777 to path which call permission denied, and now the gitea container can be run. But I can not recover my "test" project. When I click the project URL , I get a 500 page and the log of the gitea container show **router: completed GET /pazhouadmin/test for 10.10.21.246:55195, 500 Internal Server Error in 21.8ms @ repo/view.go:703(repo.Home)** Can some one help me how to recover my old project in the new gitea. Thank you !
Author
Owner

@lunny commented on GitHub (Apr 7, 2023):

Please change the configuration of the new gitea server RUN_MODE=dev and then you will get the error reason.

@lunny commented on GitHub (Apr 7, 2023): Please change the configuration of the new gitea server `RUN_MODE=dev` and then you will get the error reason.
Author
Owner

@delvh commented on GitHub (Apr 7, 2023):

In addition, why use rsync instead of gitea restore?
That's probably why you got file permission problem:
As far as I know, rsync simply copies the owner UID, so your previous gitea user ID.
This works fine as long as the default user is 1000 on both machines, but will fail otherwise, for example with an additional git user that may have any ID.
So, in your case you probably need a chown -R $GITEA_USER:$GITEA_USER as well.

@delvh commented on GitHub (Apr 7, 2023): In addition, why use `rsync` instead of `gitea restore`? That's probably why you got file permission problem: As far as I know, rsync simply copies the owner UID, so your previous gitea user ID. This works fine as long as the default user is `1000` on both machines, but will fail otherwise, for example with an additional git user that may have any ID. So, in your case you probably need a `chown -R $GITEA_USER:$GITEA_USER` as well.
Author
Owner

@matrixoneken commented on GitHub (Apr 7, 2023):

@delvh thank you for answering. I restore my gitea basing the document
https://docs.gitea.io/en-us/backup-and-restore/#using-docker-restore
In above document, it uses the "mv" as following. But when I used mv, I get error:"the directory is not empty". When I use rsync and I can move the backup file into the gitea directory

unzip gitea-dump-1610949662.zip
cd gitea-dump-1610949662
mv data/
/data/gitea
mv repos/
/data/git/repositories/**

@delvh can you tell me how to use gitea restore, I can not find the document about this. Thank you

@matrixoneken commented on GitHub (Apr 7, 2023): @delvh thank you for answering. I restore my gitea basing the document https://docs.gitea.io/en-us/backup-and-restore/#using-docker-restore In above document, it uses the "mv" as following. But when I used mv, I get error:"**the directory is not empty**". When I use rsync and I can move the backup file into the gitea directory **unzip gitea-dump-1610949662.zip cd gitea-dump-1610949662 mv data/* /data/gitea mv repos/* /data/git/repositories/** @delvh can you tell me how to use gitea restore, I can not find the document about this. Thank you
Author
Owner

@matrixoneken commented on GitHub (Apr 7, 2023):

I have solved the problem with following step

 # cp the dump file into gitea container
 docker cp gitea-dump-202304071610.zip  gitea:/tmp

#  enter the   gitea container
 docker exec -u root -it -w /tmp  gitea /bin/bash
 
 unzip gitea-dump-202304071610.zip

# restore the old file
cp -rf data/* /data/gitea
cp -rf repos/*  /data/git/repositories/

# must chown otherwise the gitea container can no be restarted
chown -R git:git /data

#  exit the gitea container
exit

# enter gitea  container with git user
docker exec -u git -it  gitea /bin/bash

# this command must be run by git user. But  I don't know the use about the command. Can some tell me?
/usr/local/bin/gitea -c '/data/gitea/conf/app.ini' admin regenerate hooks

# exit the gitea container
exit

# restart gitea container
docker restart gitea

Then everything is OK

@matrixoneken commented on GitHub (Apr 7, 2023): I have solved the problem with following step ```bash # cp the dump file into gitea container docker cp gitea-dump-202304071610.zip gitea:/tmp # enter the gitea container docker exec -u root -it -w /tmp gitea /bin/bash unzip gitea-dump-202304071610.zip # restore the old file cp -rf data/* /data/gitea cp -rf repos/* /data/git/repositories/ # must chown otherwise the gitea container can no be restarted chown -R git:git /data # exit the gitea container exit # enter gitea container with git user docker exec -u git -it gitea /bin/bash # this command must be run by git user. But I don't know the use about the command. Can some tell me? /usr/local/bin/gitea -c '/data/gitea/conf/app.ini' admin regenerate hooks # exit the gitea container exit # restart gitea container docker restart gitea ``` Then everything is OK
Author
Owner

@delvh commented on GitHub (Apr 7, 2023):

this command must be run by git user. But I don't know the use about the command. Can some tell me?
/usr/local/bin/gitea -c '/data/gitea/conf/app.ini' admin regenerate hooks

That command makes sure that whenever a push is received, Gitea is notified that this push was received.
Otherwise the files are updated on the filesystem, but Gitea isn't notified that they are updated.

@delvh commented on GitHub (Apr 7, 2023): > this command must be run by git user. But I don't know the use about the command. Can some tell me? /usr/local/bin/gitea -c '/data/gitea/conf/app.ini' admin regenerate hooks That command makes sure that whenever a push is received, Gitea is notified that this push was received. Otherwise the files are updated on the filesystem, but Gitea isn't notified that they are updated.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#10604