How to backup, restore and migrate


My gogs version is :

Gogs version

(the version number is the same as the latest).
I unziped the backup file,the sessions dir are included.

Thank you very much for your help and patience.


Thanks! I think you can file an issue on GitHub as a record, because from the code backup should only include “attachments” and “avatars” subdirs under “data” directory.


Hello @all.

I’m new to Gogs, also to git. So my question may be somehow strange. But I’ve got a curious problem. I’ve setup Gogs on Win 7 Pro 64 bit. It’s running as a service on this Windows box. Then I’ve wrote a simple batch file to get a backup of Gogs configs and also the repositories. The problem: The batch works fine when I’m logged on to the system. But running exactly the same batch from task scheduler, it looks like that the command gogs.exe backup will not create the backup in non-interactive mode.

First I thought it may caused by the user. But I’ve testet this with several users with the same result…

Does anybody here got the same experience? Or does anybody know any hints to solve the problem?



PS: The batch looks like this one

@echo off
cd \gogs
d:\gogs\gogs.exe backup
xcopy gogs-backup-*.zip \\server\development\backup\gogs\ /c /v /y /j
del /f /q gogs-backup-*.zip
cd \


Sorry, forgot most important information: I’m running Gogs in version


[root@switch-subversion /home/git]# su - git -c "/opt/gogs/gogs restore"
2017/09/19 10:56:33 [ INFO] Restore backup from:
2017/09/19 10:56:40 [FATAL] Fail to import ‘custom’: rename /tmp/gogs-backup/custom /opt/gogs/custom: invalid cross-device link


invalid cross-device link
mkdir /opt/gogs/tmp
chown git:git /opt/gogs/tmp

[FATAL] Fail to extract ‘’: open 省略: permission denied
chmod u+w -R /opt/gogs-repositories/

chown git:git /opt/gogs
mkdir /opt/gogs/tmp
chown git:git /opt/gogs/tmp
mv /opt/gogs/custom.bak /root/recycle_bin/
chmod u+w -R /opt/gogs-repositories/
su - git -c “/opt/gogs/gogs restore --config=/opt/gogs/custom/conf/app.ini --tempdir=/opt/gogs/tmp”



su - git -c "/opt/gogs/gogs backup -h"
gogs backup - Backup files and database

gogs backup [command options] [arguments…]

Backup dumps and compresses all related files and database into zip file,
which can be used for migrating Gogs to another server. The output format is meant to be
portable among all supported database engines.

–config value, -c value Custom configuration file path (default: “custom/conf/app.ini”)
–verbose, -v Show process details
–tempdir value, -t value Temporary directory path (default: “/tmp”)
–target value Target directory path to save backup archive (default: “./”)
–archive-name value Name of backup archive (default: “”)
–database-only Only dump database
–exclude-repos Exclude repositories

su - git -c “/opt/gogs/gogs backup --tempdir /opt/gogs/tmp --target /opt/gogs_bak/”

su - git -c "/opt/gogs/gogs restore -h"
gogs restore - Restore files and database from backup

gogs restore [command options] [arguments…]

Restore imports all related files and database from a backup archive.
The backup version must lower or equal to current Gogs version. You can also import
backup from other database engines, which is useful for database migrating.

If corresponding files or database tables are not presented in the archive, they will
be skipped and remain unchanged.

–config value, -c value Custom configuration file path (default: “custom/conf/app.ini”)
–verbose, -v Show process details
–tempdir value, -t value Temporary directory path (default: “/tmp”)
–from value Path to backup archive
–database-only Only import database
–exclude-repos Exclude repositories


I’ve done a successful backup, but now trying to restore it and getting this.

2 things:

  • I’m performing the backup on one instance, and restoring it on another (new, empty) instance
  • both instances are running in Docker containers.

a25ff52a1650:/app/gogs$ ./gogs restore --from /data/gogs
a25ff52a1650:/app/gogs$ ./gogs restore --from /data/
2017/09/19 19:37:01 [ INFO] Restore backup from: /data/
2017/09/19 19:37:27 [FATAL] Fail to import database: fail to insert strcut: database disk image is malformed