Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gogs restore in Docker failure - GOGS_CUSTOM /data/gogs is moved #7684

Open
1 task done
vallon opened this issue Mar 13, 2024 · 2 comments
Open
1 task done

gogs restore in Docker failure - GOGS_CUSTOM /data/gogs is moved #7684

vallon opened this issue Mar 13, 2024 · 2 comments
Labels
💊 bug Something isn't working

Comments

@vallon
Copy link

vallon commented Mar 13, 2024

Gogs version

v0.13.0

Git version

  • Server: n/a
  • Client: n/a

Operating system

Docker v0.13.0

Database

sqlite3

Describe the bug

I've had some trouble migrating from a non-Docker installation of gogs to a dockerized version. I dumped the old gogs version 0.11.91.0811, and then tried to load into the docker container with:

source /app/gogs/docker/s6/gogs/setup # creates log symlinks
gosu $USER mkdir /data/tmp # same vol as /data so rename works
gosu $USER /app/gogs/gogs restore --verbose --from /restore/gogs-backup.zip --config /restore/app.ini --tempdir /data/tmp

But, after this, I end up with:

/data/git/...
/data/gogs/ (empty)
/data/gogs.bak/data/gogs.db
/data/gogs.bak/conf
/data/gogs.bak/log/...

It appears to be:

  1. ENV GOGS_CUSTOM /data/gogs
    sets GOGS_CUSTOM=/data/gogs
  2. func CustomDir() string {
    computes conf.CustomDir() to be getenv("GOGS_CUSTOM") with fallback to WorkDir()/"custom".
  3. conf.CustomDir() is "/data/gogs"
  4. if osutil.IsDir(conf.CustomDir()) {
    tries to restore "$archivedir/custom" directory by renaming the old $GOGS_CUSTOM to $GOGS_CUSTOM.bak, then moving the archive/custom dir to $GOGS_CUSTOM.

That has renamed /data/gogs/data/gogs.db to /data/gogs.bak/data/gogs.db.

To reproduce

It seems what is required:

  • gogs restore in Docker (where GOGS_CUSTOM=/data/gogs)
  • backup archive contains a "custom" dir (v0.11.91.0811 backup fails if there is no custom dir)
  • database.type = sqlite3; database.path = data/gogs.db

Expected behavior

database should be in correct place after restore.

Since I am starting with a fresh /data directory, my workaround is to mv /data/gogs.bak/* /data/gogs/.

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@vallon vallon added the 💊 bug Something isn't working label Mar 13, 2024
@vallon
Copy link
Author

vallon commented Mar 14, 2024

Reproduced with latest gogs:

Build docker:

git clone https://github.com/gogs/gogs
cd gogs
docker build --tag gogs7684:latest .

Startup gogs on data0:

docker run --rm \
    --volume $PWD/data0:/data \
    --volume $PWD/backup0:/backup \
    --env RUN_CROND=true \
    --env BACKUP_INTERVAL=1h \
    gogs7684

Configure:

  • Database type = SQLite3
  • Application URL = $EXTERNALURL
  • Admin Username = gogs
  • Admin Password = gogs
  • Install
  • Create a repo for reference: "myrepo", Init this repo

Wait for backup at :00, or adjust cron crontab -u git -e. Backup in backup0/gogs-backup-*.zip. Kill container.

Run new container, restore:

docker run \
    --rm \
    --volume $PWD/data1:/data \
    --volume $PWD/backup0:/restore \
    gogs7684 sh -c '
        source /app/gogs/docker/s6/gogs/setup # symlinks
        gosu $USER mkdir /data/tmp  # mv across filesystems
        gosu $USER /app/gogs/gogs restore --from /restore/gogs-backup-*.zip --tempdir /data/tmp
        find /data/gogs /data/gogs.bak
    '

This shows:

/data/gogs
/data/gogs/conf
/data/gogs/conf/app.ini
/data/gogs/log
/data/gogs/log/gogs.log
/data/gogs/log/xorm.log
/data/gogs/log/gorm.log
/data/gogs.bak
/data/gogs.bak/data
/data/gogs.bak/data/gogs.db
/data/gogs.bak/conf
/data/gogs.bak/log
/data/gogs.bak/log/xorm.log
/data/gogs.bak/log/gorm.log

The database was moved to /data/gogs.bak/data/gogs.db.

@vallon
Copy link
Author

vallon commented Mar 14, 2024

The "gogs backup" explicitly excluded the data directory from the backup. It seems the simplest fix would be that after the restore of $GOGS_CUSTOM, if $GOGS_CUSTOM.bak/data exists, then move it back to $GOGS_CUSTOM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💊 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant