Gogs数据备份、恢复

Catalogue
  1. 1. Backup
  2. 2. Database
  3. 3. Restore
  4. 4. Custom config file
  5. 5. 参考资料

Other than pack up gogs-repositories, custom and database separately, Gogs provides two commands for unified process of backup, restore and even migrate to another database engine.

Backup

Go to the directory where your Gogs binary is located, and execute following command:

./gogs backup

Without any flags, backup command will pack up all gogs-repositories, custom and database into a single zip archive (e.g. gogs-backup-xxx.zip) under current directory.

It could be a bad idea if your gogs-repositories contains GB of raw data, in that case, you can apply –exclude-repos flag:

./gogs backup --exclude-repos
If your custom/conf/app.ini is somewhere unusual, make sure you specify it via –config flag like always:

./gogs backup --config=my/custom/conf/app.ini

Database

If you’re only interested in backup database, or want to migrate from one database engine (e.g. SQLite3) to another engine (e.g. MySQL), –database-only is your friend:

./gogs backup --database-only

The backup format of database are portable JSON files, each file corresponds to a database table, you can do whatever you want with those files.

Restore

The restore command also has flags to indicate only restore database or everything in backup archive:

./gogs restore --database-only --from="gogs-backup-xxx.zip"

If a table that is not presented in backup archive, whatever in current database table will remain unchanged.

Custom config file

There are 3 steps to determine which custom/conf/app.ini command uses:

Use the one you specified vis flag --config.
Use the one stored in backup archive.
Use the one in $(pwd)/custom/conf/app.ini.
If all 3 steps failed, sorry, impossible to perform restore process.

参考资料

-How to backup, restore and migrate