備份和移動 Weblate¶
專案層級備份¶
在 4.14 版被加入.
專案會從 Weblate 備份所有翻譯內容(專案、組件、翻譯、字串評論、建議或檢查)。這適合用在轉移專案到另一個 Weblate 翻譯平臺。
You can perform a project backup in Operations ↓ Backups. The backup can be restored when creating a project (see 新增翻譯專案和組件).
目前備份資料不包含存取控制與歷史資訊。
The comments and suggestions are backed up with the username of the user who did create them. Upon import it is assigned to a matching user. If there is no user with such username, it is assigned to anonymous user.
儲存在伺服器上所產生的備份將以 PROJECT_BACKUP_KEEP_DAYS 與 PROJECT_BACKUP_KEEP_COUNT 引數設定(預設將儲存近 3 個備份檔案 30 天)。
Import validation of uploaded project backups can be tuned using
PROJECT_BACKUP_IMPORT_MAX_MEMBERS,
PROJECT_BACKUP_IMPORT_MAX_TOTAL_UNCOMPRESSED_SIZE,
PROJECT_BACKUP_IMPORT_MAX_COMPRESSED_ENTRY_SIZE,
PROJECT_BACKUP_IMPORT_MIN_RATIO_SIZE, and
PROJECT_BACKUP_IMPORT_MAX_COMPRESSED_ENTRY_RATIO.
Use the generated file to import project when 新增翻譯專案和組件 or in import_projectbackup.
備註
Restoring of the backup might fail if the restoring server has different set
of 語言定義 or different configuration of
SIMPLIFY_LANGUAGES. The restore will tell you which language
codes could not be processed and you can then add missing language
definitions manually.
使用 BorgBackup 自動備份¶
Weblate 內建了對使用 BorgBackup 建立服務備份的支援。 Borg 建立了節省空間的加密備份,可以安全地儲存在雲中。可以從管理介面中的 Backups 選項卡上控制備份。
在 4.4.1 版的變更: PostgreSQL databases are included in the automated backups.
使用 Borg 的備份是遞增的, Weblate 配置為保留後面的備份:
近 14 日的每日備份
近 8 週的每週備份
近 6 個月的每月備份
Borg 加密金鑰¶
BorgBackup 建立加密的備份,如果沒有密碼,您將無法恢復它們。密碼是在新增新的備份服務時產生的,您應該複製它並將其儲存在一個安全的地方。
如果您在使用 Weblate 支援備份儲存,請同樣備份您的私有 SSH 金鑰,因為它用來存取您的備份。
也參考
自訂備份¶
資料庫備份可透過
DATABASE_BACKUP設定。自訂建立備份可使用
BORG_EXTRA_ARGS設定值。
Weblate 支援備份儲存¶
備份您的 Weblate 實例最簡單方式是在 weblate.org 購買 備份服務 。這是您如何讓它執行起來的方式:
在 https://weblate.org/support/#backup 購買 備份服務。
在管理介面輸入得到的金鑰,請參閱 整合支援。
Weblate 將連線到雲端服務,並取得備份的存取資訊。
從 Backups 標籤開啟新的備份配置。
備份您的 Borg 憑證以至可從憑證恢復您的備份,參閱: Borg 加密金鑰 。
提示
為了安全起見,有開啟所有東西的手動步驟。沒有您的同意,就不會有資料傳送到透過註冊步驟得到的備份儲存庫。
使用用戶的備份儲存¶
也可以使用自己的儲存來備份。 SSH 可以用於在遠端目的地儲存備份,目標伺服器需要安裝 BorgBackup。
也參考
General 在 Borg 說明文件中
本機檔案系統¶
推薦去指定本地備份的絕對路徑,例如 /path/to/backup。該目錄必須可由執行 weblate 的使用者寫入(請參閱 檔案系統權限)。在目錄不存在的情況下,Weblate 會嘗試新增它,但需要適當的權限才能這麼做。
提示
在 Docker 中執行 Weblate時,請確保備份位置揭露為來自 Weblate 容器的一個儲存區。否則,備份檔案將在其所在的容器重啟時被 Docker 丟棄。
One option is to place backups into an existing volume, for example
/app/data/borgbackup. This is an existing volume in the container.
您也可以在 Docker 的編寫檔案中為備份目的新增一個新的容器,例如使用 /borgbackup:
services:
weblate:
volumes:
- /home/weblate/data:/app/data
- /home/weblate/borgbackup:/borgbackup
The directory where backups will be stored has to be owned by UID 1000, otherwise Weblate won’t be able to write the backups there.
遠端備份¶
要建立遠端備份,您必須將 BorgBackup 安裝到另一個伺服器上,確保它可接受透過 SSH 金鑰的連線:
準備一個您的備份將用來存放的伺服器。
將其安裝 SSH 服務(在大部分的 Linux 發行版本中您將能預設的取得)。
安裝 BorgBackup 在伺服器中。大部分的 Linux 發行版本擁有可取得的套件(參閱 Installation)。
選擇一個現有的使用者或建立新的使用者將於備份使用。
Add Weblate SSH key to the user's .ssh/authorized_keys file, so that Weblate can SSH to the server without a password (see Weblate SSH 金鑰).
Create a user-writable directory where Weblate can remotely set up the Borg backup repository, for example in the home directory (i.e.
/home/borg/backups).Configure the backup location in Weblate as
user@host:/home/borg/backupsorssh://user@host:port/home/borg/backups.Once enabled, the backups will be triggered automatically daily. You can also manually trigger a backup from the Weblate UI or using backup.
提示
Weblate 支援備份儲存 為您提供自動化遠端備份,無需費力。
從 BorgBackup 恢復備份¶
恢復功能會存取您的備份儲存庫,並準備備份密碼。
用
borg list REPOSITORY列出伺服器上的所有備份。使用
borg extract REPOSITORY::ARCHIVE將所需備份恢復到目前目錄。從放置在 Weblate 資料目錄下
backup目錄中的 SQL 備份中恢復資料庫(請參閱 下載的資料用於備份)。將 Weblate 配置 (
backups/settings.py,請參閱 下載的資料用於備份 )複製到正確的位置,請參閱 調整配置。當使用 Docker 容器時,設定檔已經包含在容器中,您應該恢復原始的環境變數。
environment.yml檔案或許能幫助您(參閱 下載的資料用於備份)。將整個儲存的資料目錄複製到
DATA_DIR所配置的位置。When using Docker container place the data into the data volume, see Docker 容器 volumes.
請確認檔案是否擁有正確的擁有權或權限,參閱 檔案系統權限。
Borg 工作階段可能看上去是這個樣子的:
$ borg list /tmp/xxx
Enter passphrase for key /tmp/xxx:
2019-09-26T14:56:08 Thu, 2019-09-26 14:56:08 [de0e0f13643635d5090e9896bdaceb92a023050749ad3f3350e788f1a65576a5]
$ borg extract /tmp/xxx::2019-09-26T14:56:08
Enter passphrase for key /tmp/xxx:
Restoring Docker based setup¶
The following steps assume the official Docker Compose setup using the bundled PostgreSQL and Valkey services, see 使用 Docker 安裝. If your deployment uses an external database or a customized Compose file, adapt the database and volume steps to that environment.
Start with a Docker Compose checkout matching the restored deployment. Restore
your original Compose overrides, secrets, and environment variables. The
environment.yml file from 下載的資料用於備份 can help with this, but
it is not imported automatically.
Restore the backup archive using 從 BorgBackup 恢復備份 or unpack your manual backup so that the Weblate data directory and
backups/database.sqlare available.停止可以寫入資料庫或資料儲存區的服務:
docker compose stop weblate cache
重新建立 PostgreSQL 儲存區。
docker compose stop database docker compose rm -v database docker volume remove weblate-docker_postgres-data
The volume name depends on the Compose project name and can differ from
weblate-docker_postgres-data. Check your setup before removing any volume.啟動資料庫服務:
docker compose up -d database
恢復資料庫傾印:
cat backups/database.sql | docker compose exec -T database psql --username weblate --dbname weblate
Check that the database name matches
POSTGRES_DBand the user matchesPOSTGRES_USERin your Compose configuration.Restore the Weblate data directory to the Docker data volume mounted as
/app/data, see Docker 容器 volumes. Files in this volume have to be owned by UID 1000, see 檔案系統權限.Start the remaining services and follow the logs:
docker compose up -d docker compose logs -f
The Weblate container performs database migrations on startup. If you are also upgrading Weblate, follow 升級 Docker 容器.
Refresh the repositories after the restore:
docker compose exec --user weblate weblate weblate updategit --all
手動備份¶
Depending on what you want to save, back up the type of data Weblate stores in each respective place.
提示
如果您正進行手動備份,您也許想要關閉Weblate 關於缺乏備份的警告,方法是新增 weblate.I028 到 settings.py 中的 SILENCED_SYSTEM_CHECKS;對於Docker,則是 WEBLATE_SILENCED_SYSTEM_CHECKS。
SILENCED_SYSTEM_CHECKS.append("weblate.I028")
資料庫¶
實際儲存位置依賴於資料庫的設定。
提示
資料庫是最重要的儲存。定期對資料庫進行備份。沒有資料庫,所有的翻譯都會消失。
原生資料庫備份¶
The recommended approach is to save a dump of the database using database-native tools such as pg_dump. It usually performs better than Django backup, and it restores complete tables with all their data.
You can restore this backup in a newer Weblate release, it will perform all the
necessary migrations when running in migrate. Please consult
升級 Weblate on more detailed info on how to upgrade between versions.
Django 資料庫備份¶
另外,可以使用 Django 的 dumpdata 指令備份您的資料庫。那種方式是不依托資料庫的,並且可以用於先要變更資料庫後端的情況。
Prior to restoring the database you need to be running exactly the same Weblate
version the backup was made on. This is necessary as the database structure does
change between releases and you would end up corrupting the data in some way.
After installing the same version, run all database migrations using
migrate.
之後,一些條目將已經在資料庫中建立,您也會在資料庫備份中看到它們。推薦的方法是使用管理 shell 手動刪除這些條目 (見 呼叫管理指令):
weblate shell
>>> from weblate.auth.models import User
>>> User.objects.get(username='anonymous').delete()
檔案¶
如果您有足夠的備份空間,只需備份整個 DATA_DIR。這是一個安全帶,即使它包含一些您不想要的檔案。下面的部分詳細描述了應該備份和可以略過的內容。
下載的資料用於備份¶
在 4.7 版的變更: 環境設定匯出到檔案 environment.yml ,協助在恢復 Docker 環境設定時使用。
儲存在 DATA_DIR /backups 中。
Weblate 這裡備份各種資料,可以包括這些檔案用於更完整的備份。檔案每日更新(需要執行 Celery beat 伺服器,請參閱 使用 Celery 的背景工作 )。目前,這包括:
Weblate 設定為
settings.py(還有擴充套件版,在settings-expanded.py)。PostgreSQL 資料庫備份為
database.sql。環境設定匯出檔案
environment.yml。
資料庫備份預設儲存為純文字,但也可以透過 DATABASE_BACKUP 來進行壓縮或整個略過。
To restore the database backup, load it using database tools, for example:
psql --file=database.sql weblate
版本控制儲存庫¶
儲存在 DATA_DIR /vcs 中。
The version control repositories contain a copy of your upstream repositories with Weblate changes. If you have 提交時一併推送 enabled for all your translation components, all Weblate changes are included upstream. No need to back up the repositories on the Weblate side as they can be cloned again from the upstream location with no data loss.
SSH 與 GPG 金鑰¶
儲存在 DATA_DIR /ssh 和 DATA_DIR /home 中。
如果正在使用 Weblate 產生的 SSH 或 GPG 金鑰,您應該備份這些位置。否則將遺失私有金鑰,並且您將不得不重新產生新的金鑰。
Generated SSH wrapper scripts are stored in CACHE_DIR and do not
need to be backed up.
User uploaded files¶
儲存在 DATA_DIR /media 中。
您應當備份所有使用者上傳的檔案(例如 Screenshots and visual context )。
Celery 工作¶
Celery 工作佇列可能會包含一些資訊,但通常無需進行備份。您最多只會遺失尚未被翻譯記憶庫處理的更新。無論如何,建議在恢復時執行全文或儲存庫更新,這樣就不會有丟失這些內容的問題。
也參考
適用於手動備份的命令列¶
使用 cron 作業,您可以設定一條每天執行的 Bash 指令,例如:
$ tar -Jcf ~/backup/weblate-backup-$(date -u +%Y-%m-%d_%H%M%S).xz backups vcs ssh home media fonts secret
您可以根據需要調整資料夾和檔案的清單。為了避免儲存翻譯記憶庫(在備份資料夾中),您可以使用:
$ tar -Jcf ~/backup/weblate-backup-$(date -u +%Y-%m-%d_%H%M%S).xz backups/database.sql backups/settings.py vcs ssh home media fonts secret
恢復手動備份¶
將已經備份的所有資料恢復。
使用
updategit更新所有儲存庫。weblate updategit --all
移動 Weblate 安裝¶
按照上面備份與恢復說明,將您的安裝遷移到不同系統。