This repository contains my Python scripts for backing up and restoring the Git repositories hosted on my self-hosted Gitea server.
These scripts can be used to back up repositories in any self-hosted Gitea server.
For more information about these Python scripts, feel free to take a look at my blog post.
-
Navigate to
/scripts/repos.pyto place mappings of your Gitea repository name with their SSH URLs in theREPO_URL_DICTdictionary. -
In the root directory, create a
.envfile and add in the following:GITEA_USERNAME="[insert username here]" GITEA_PASSWORD="[insert password here]" GITEA_BASE_URL="[The Gitea API URL, with the prefix 'https://']" GITEA_ACCESS_TOKEN="[insert access token here]" SSH_KEY_PATH="[the path to the SSH key you want to use]"The
GITEA_USERNAMEandGITEA_PASSWORDcorresponds to the username and password, respectively, of the Gitea account you use in your self-hosted Gitea server. TheGITEA_BASE_URLis the URL of the homepage for your self-hosted Gitea server. TheGITEA_ACCESS_TOKENwill contain your Gitea API token. You can find more information on how to obtain the API token in the Gitea API Documentation. -
Run
make installto install the dependencies.
- Run
make backupto backup the Gitea repositiories associated with user identified byGITEA_USERNAME, as set in.env. Depending on how large the repositories are, the script may take quite some time to complete. When the script is finished, it will output a/backupdirectory in the root directory of this repository.
These steps assume that the repositories to be backed up are in the
created /backup directory.
-
Run
make createto create empty Gitea repositories, corresponding to the name of each repository in/backup. -
Run
make restoreto upload the local Git repositories in/backupto their associated empty repositories (which we created inmake create). Depending on how large the repositories are, the script may take quite some time to complete.
In addition, there is a provided make delete function to delete
the repositories, held locally in /backup, from the Gitea server.
I made this script to delete unaccessible repositories (that I already backed up in /backup), before following steps laid out in the above Restoring section (in order to restore accessible versions of said repositories).
The scripts can take quite a long time to run, which could
delay the detection of a possible prolem until late in the backup process.
Furhtermore, it could be the case that the values set in .env are outdated or do not currently work.
To detect these issues, there is a test version of the repositories dictionary in /script/repos.py.
That way, you can:
-
Place a few small sized repositories,
-
Set the testing flag to true, and
-
Run steps defined in Usage to determine if you are able to back-up and restore successfully,
before doing any actual backups.