Add git backup to remote repository (closes #996)#1018
Add git backup to remote repository (closes #996)#1018EduardSchwarzkopf wants to merge 57 commits into
Conversation
|
I let Co-Pilot running a review as well. Lets see what the AI is finding :) - Actually for me it looks already good for first version. |
There was a problem hiding this comment.
Pull request overview
Adds an automated Git-based backup system that periodically commits wiki content and (optionally) pushes it to a configured SSH remote, plus admin endpoints and UI to view status and trigger manual pushes.
Changes:
- Introduces
internal/backup(git repo init/commit/push, scheduler, status, gitignore management) and wires it into the server. - Adds admin-only API routes for backup status and manual push triggers.
- Adds a frontend “Backup Settings” page + Zustand store + API client for status/push.
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/leafwiki-ui/src/stores/backup.ts | Zustand store for backup status + push trigger state |
| ui/leafwiki-ui/src/lib/api/backup.ts | Frontend API client for backup status + push |
| ui/leafwiki-ui/src/features/router/router.tsx | Adds /settings/backup route |
| ui/leafwiki-ui/src/features/backup/useToolbarActions.ts | Clears toolbar buttons on Backup Settings mount |
| ui/leafwiki-ui/src/features/backup/BackupSettings.tsx | Backup Settings UI incl. status polling + manual push |
| ui/leafwiki-ui/src/components/UserToolbar.tsx | Adds “Backup Settings” link for admins |
| readme.md | Documents git backup feature + config + usage |
| internal/wiki/wiki.go | Allows optionally registering backup routes |
| internal/wiki/backup/routes.go | Admin API endpoints for backup status + manual trigger |
| internal/backup/status.go | Status tracking for last backup + error |
| internal/backup/scheduler.go | Background scheduler + manual trigger channel |
| internal/backup/scheduler_test.go | Tests for scheduler behavior |
| internal/backup/repo.go | Git repository init/commit/push implementation |
| internal/backup/repo_test.go | Tests for repo init + commit behavior |
| internal/backup/gitignore.go | Writes .gitignore into the repo root |
| internal/backup/gitignore_test.go | Tests .gitignore creation/non-overwrite |
| internal/backup/config.go | Backup config (paths, author, remote, SSH, interval) |
| cmd/leafwiki/main.go | CLI/env wiring, scheduler startup, routes registration |
| .env.example | Documents git backup environment variables |
| go.mod | Adds go-git and other deps |
| go.sum | Updates checksums for new deps |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Could you go through the Co-Pilot mentions. |
|
oh wow, I'm impressed by the findings. I will check them out. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Yes, I’m often shocked too :) |
|
Let me know when you are done. |
|
absolutely fine. Should I update the versions in the README from v0.10.0 to v,0.11.0 for the backup and reverse proxy features?
|
|
alright, i have updated the code. I hope i got everything. Let me know if there is still some things missing. |
|
thanks! It would be could if you could create a separate PR with the flag documentation of the proxy settings. I would keep the Git configuration still in this PR, to be ready for the v0.11.0 release. I will checkout the branch and let it run on my system and test it a bit manually before merging it. Hopefully soon ;) If you are interested to support more let me know! One issue I'm facing at the moment, as the flags are growing not sure if it makes sense to keep them like that. If you are interested to do a proposal and implementing it. Let me know! But we still need to consider how it could be started in a few seconds without providing a huge configuration file. Maybe like Paperless-ngx? https://docs.paperless-ngx.com/configuration/ They allow a configuration file & flags. Maybe this is the way to go. |
Alright, will remove this from my PR then and provide a new PR.
Sadly i do not have that much time to be an active maintainer, but I might provide more support in the future, when i see the need for a new feature/fix :D
Yes, I see the point, having this managed via a config or .env file is fine for the moment. Long term, I'd suggest moving this into a settings page, so the user can manage this via UI? |
Perfect, thanks!
Happy to hear ;)
Here I need to think a bit deeper, because as a K8s admin, I hate having my configuration not managed via GitOps. So it depends, but I need to think about it. |
100%, considering the point that the setup itself requires some sort of technical knowledge, I'd 100% second your idea with a configuration file. Maybe to have the pluses of both worlds, the app can provide a small overview of enabled features and their values, similar to Firefox's about:config`. Another benefit of this is that it also provides a bit of a sanity check. |
What: Automated git backup to a remote repository via SSH with configurable schedule.
Why: Addresses the feature request in #996 — users wanted an optional way to auto-commit page saves and push them to a remote git repository for backup purposes, similar to Otterwiki's experimental repository management feature.
Changes:
internal/backup/package — Git repository operations, scheduled backup runner, configuration, status tracking, and gitignore handlingGET /api/admin/backup/statusandPOST /api/admin/backup/pushendpointsdocs/docker-backup.mdaddedConfiguration
CLI Flags
--git-backupfalse--git-backup-remote""--git-backup-branchmain--git-backup-author-nameLeafWiki Backup--git-backup-author-emailbackup@leafwiki.local--git-backup-interval60--git-backup-ssh-key-path""--git-backup-ssh-key""--git-backup-ssh-known-hosts""Environment Variables
LEAFWIKI_GIT_BACKUPLEAFWIKI_GIT_BACKUP_REMOTELEAFWIKI_GIT_BACKUP_BRANCHLEAFWIKI_GIT_BACKUP_AUTHOR_NAMELEAFWIKI_GIT_BACKUP_AUTHOR_EMAILLEAFWIKI_GIT_BACKUP_INTERVALLEAFWIKI_GIT_BACKUP_SSH_KEY_PATHLEAFWIKI_GIT_BACKUP_SSH_KEYLEAFWIKI_GIT_BACKUP_SSH_KNOWN_HOSTSExample usage
./leafwiki \ --git-backup=true \ --git-backup-remote=git@github.com:user/leafwiki-backup.git \ --git-backup-branch=main \ --git-backup-author-name="LeafWiki Backup" \ --git-backup-author-email=backup@leafwiki.local \ --git-backup-interval=60 \ --git-backup-ssh-key-path=/path/to/id_rsaOr via environment variables:
Admin API
When git backup is enabled, two admin-only REST endpoints are available:
/api/admin/backup/status/api/admin/backup/pushRestoring from backup
To restore your wiki from a git backup:
git logto view backup history andgit checkout <commit>to restoreNote: Only
root/andassets/are backed up. The SQLite database is not included.