Compare commits

...

143 Commits

Author SHA1 Message Date
github-actions[bot] a2be03751f chore: release 1.4.0 2026-03-12 18:23:42 +00:00
Charles GTE 7df9df1605 feat : test coverage for utils functions #35
feat : test coverage for utils functions
2026-03-12 19:21:09 +01:00
charlesgauthereau df5b16a153 fix: docker-compose.yml 2026-03-12 19:16:12 +01:00
charlesgauthereau 824a5d52a3 feat: add test for util functions and start working on database providers tests procedures 2026-03-12 18:56:07 +01:00
charlesgauthereau 1496208db4 Merge branch 'main' into dev 2026-03-09 16:46:00 +01:00
charlesgauthereau 454e1b442f Merge remote-tracking branch 'origin/main' 2026-03-09 16:45:52 +01:00
github-actions[bot] 54bca7452a chore: release 1.3.0 2026-03-09 15:43:44 +00:00
Charles GTE a96cef6cb5 feat: helm chart (#34)
* fix: docker.yml

* feat: add helm chart config

* fix: helm config

* feat: add .github workflow for helm chart

---------

Co-authored-by: charlesgauthereau <charles.gauthereau@soluce-technologies.com>
2026-03-09 16:41:14 +01:00
charlesgauthereau fd9f183166 Merge branch 'main' into dev 2026-03-08 22:02:36 +01:00
charlesgauthereau 94fb2535ec Merge remote-tracking branch 'origin/main' 2026-03-08 21:59:02 +01:00
github-actions[bot] 189ad866de chore: release 1.2.5 2026-03-08 20:50:53 +00:00
Charles GTE 55bbd4e724 fix: new-workflow-ci (#32)
* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* fix: docker.yml

* fix: docker.yml

* fix: docker.yml

* fix: docker.yml

* fix: docker.yml

* fix: docker.yml

---------

Co-authored-by: charlesgauthereau <charles.gauthereau@soluce-technologies.com>
2026-03-08 21:48:13 +01:00
charlesgauthereau 7fabc9c98c Merge remote-tracking branch 'origin/main' 2026-03-08 21:47:15 +01:00
github-actions[bot] 4f67a57681 chore: release 1.2.4 2026-03-08 20:20:58 +00:00
Charles GTE 45a1118f64 fix: docker build (#31)
* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* fix: docker.yml

* fix: docker.yml

* fix: docker.yml

* fix: docker.yml

* fix: docker.yml

---------

Co-authored-by: charlesgauthereau <charles.gauthereau@soluce-technologies.com>
2026-03-08 21:18:27 +01:00
charlesgauthereau 063b2e1c2c Merge remote-tracking branch 'origin/main' 2026-03-08 21:12:09 +01:00
github-actions[bot] f2275d5aca chore: release 1.2.3 2026-03-08 20:00:47 +00:00
Charles GTE b136140b55 fix: new-workflow-ci (#30)
* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* fix: docker.yml

* fix: docker.yml

* fix: docker.yml

* fix: docker.yml

---------

Co-authored-by: charlesgauthereau <charles.gauthereau@soluce-technologies.com>
2026-03-08 20:58:19 +01:00
charlesgauthereau 924177a4fe Merge remote-tracking branch 'origin/main' 2026-03-08 20:52:36 +01:00
github-actions[bot] 773077f66b chore: release 1.2.2 2026-03-08 19:48:25 +00:00
Charles GTE 46ff086cf9 fix: new-workflow-ci (#29)
* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* fix: docker.yml

* fix: docker.yml

---------

Co-authored-by: charlesgauthereau <charles.gauthereau@soluce-technologies.com>
2026-03-08 20:47:41 +01:00
charlesgauthereau 678df8e2bc fix: docker.yml 2026-03-08 20:46:47 +01:00
github-actions[bot] f563c187db chore: release 1.2.1 2026-03-08 19:43:01 +00:00
Charles GTE df0dffa47b fix: new-workflow-ci (#28)
* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

---------

Co-authored-by: charlesgauthereau <charles.gauthereau@soluce-technologies.com>
2026-03-08 20:42:16 +01:00
github-actions[bot] 864396422b chore: release 1.2.0 2026-03-08 19:38:10 +00:00
Charles GTE e280c1d2f8 fix: workflow (#27)
* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

---------

Co-authored-by: charlesgauthereau <charles.gauthereau@soluce-technologies.com>
2026-03-08 20:31:41 +01:00
Charles GTE 91a9d0654b feat: new workflow CI (#26)
* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

* feat: new workflow CI

---------

Co-authored-by: charlesgauthereau <charles.gauthereau@soluce-technologies.com>
2026-03-08 20:28:26 +01:00
Charles GTE bc857a4c18 feat: new workflow CI
* feat: new workflow CI

* feat: new workflow CI

---------

Co-authored-by: charlesgauthereau <charles.gauthereau@soluce-technologies.com>
2026-03-08 20:24:26 +01:00
Charles GTE 2454915866 feat: new workflow CI (#24)
Co-authored-by: charlesgauthereau <charles.gauthereau@soluce-technologies.com>
2026-03-08 20:22:45 +01:00
Charles GTE a4a7a9a2c4 feat: new workflow CI
feat: new workflow CI
2026-03-08 20:12:43 +01:00
charlesgauthereau 997ba2afa2 feat: new workflow CI 2026-03-08 20:12:00 +01:00
charlesgauthereau 7e0c7c0688 Merge branch 'main' into dev
# Conflicts:
#	docker-compose.yml
2026-03-08 19:48:00 +01:00
Charles GTE f973bc1f52 fix: refactoring for backup and restore service
* fix: docker-compose.yml

* fix: refactoring for backup and restore service

* fix: cargo update

* fix: refactoring of the backup and restore services

---------

Co-authored-by: charlesgauthereau <charles.gauthereau@soluce-technologies.com>
2026-03-08 19:47:04 +01:00
charlesgauthereau b9b9fcf6ee Merge branch 'main' into dev 2026-03-08 10:02:34 +01:00
charlesgauthereau 0224605c59 fix: docker-compose.yml 2026-03-08 10:02:17 +01:00
Charles GTE 6ea9fdf8bc Merge pull request #21 from Portabase/dev
chore: add coderabbitai config file
2026-03-05 11:21:45 +01:00
Charles GTE ad68be8a5a fix: coderrabbit.yaml 2026-03-05 11:19:47 +01:00
Charles GTE 434c131afb chore: add coderabbitai config file 2026-03-05 11:10:20 +01:00
Charles GTE 675ac5976d Merge pull request #20 from Portabase/dev
chore: add trailing newlines to README.md
2026-03-05 10:59:26 +01:00
Charles GTE 70543fe032 fix: README.md 2026-03-05 10:45:55 +01:00
Charles GTE 77f90308b4 Update README.md 2026-03-02 08:46:32 +01:00
charlesgauthereau 63cb254abd chore: Cargo.lock 2026-02-24 08:45:50 +01:00
charlesgauthereau 7738745def chore(release): 1.1.6 2026-02-24 08:45:26 +01:00
charlesgauthereau 82659f681c feat: add local test db for sqlite 2026-02-23 22:44:57 +01:00
charlesgauthereau eee3bebd50 feat: add local test db for sqlite 2026-02-23 22:43:44 +01:00
charlesgauthereau 58dd0259f9 chore(release): 1.1.6-rc.1 2026-02-23 21:55:47 +01:00
Charles GTE 5b7453208b Merge pull request #16 from Portabase/feat/sqlite
feat/sqlite
2026-02-23 21:54:04 +01:00
charlesgauthereau 35933aae52 fix: refactoring config check on startup agent. 2026-02-23 21:47:18 +01:00
charlesgauthereau 178628cb1c feat: add sqlite support, first working version 2026-02-22 21:46:16 +01:00
charlesgauthereau 3fc60e3f40 fix: s3 provider port config. 2026-02-19 21:16:13 +01:00
charlesgauthereau e62de95827 chore(release): 1.1.5 2026-02-19 21:15:55 +01:00
Charles GTE fc3612fa3f Merge pull request #14 from Portabase/dev
fix: s3 provider port config.
2026-02-19 21:15:19 +01:00
charlesgauthereau 18fe211ad1 fix: s3 provider port config. 2026-02-19 21:14:35 +01:00
charlesgauthereau 74ada01232 chore: Cargo.lock 2026-02-19 16:10:37 +01:00
charlesgauthereau 4fef360c06 chore(release): 1.1.4 2026-02-19 16:10:17 +01:00
charlesgauthereau 2647941008 fix: tus.rs 2026-02-19 16:09:43 +01:00
Charles GTE b4bdc89888 Merge pull request #13 from Portabase/fix/error-handling
fix/error-handling
2026-02-18 19:28:33 +01:00
charlesgauthereau 829e5bade3 fix: tus.rs 2026-02-18 17:28:59 +01:00
charlesgauthereau fc9a4ef8fb chore(release): 1.1.4-rc.1 2026-02-18 17:28:27 +01:00
charlesgauthereau 3c5734ed4e fix: tus.rs 2026-02-18 17:27:24 +01:00
charlesgauthereau 4b77896ecb fix: Cargo.lock 2026-02-16 11:30:38 +01:00
charlesgauthereau 40c4a4e2bb chore(release): 1.1.3 2026-02-16 11:30:16 +01:00
charlesgauthereau 8a05b93ff3 chore(release): 1.1.3-rc.1 2026-02-16 10:56:37 +01:00
charlesgauthereau c186932a79 fix: failed backup 2026-02-16 09:19:31 +01:00
charlesgauthereau bf74173cac chore(release): 1.1.2 2026-02-16 09:19:17 +01:00
charlesgauthereau 3dcebf4fcc fix: failed backup 2026-02-16 09:00:43 +01:00
charlesgauthereau 4de2b81b33 chore(release): 1.1.2-rc.2 2026-02-16 09:00:26 +01:00
charlesgauthereau b06f9d8186 fix: failed backup 2026-02-16 09:00:18 +01:00
charlesgauthereau f5a2182723 fix: blocking for mysql database 2026-02-16 08:43:27 +01:00
charlesgauthereau e8a96980f1 chore(release): 1.1.2-rc.1 2026-02-16 08:43:13 +01:00
charlesgauthereau a64792bcc6 fix: blocking for mysql database 2026-02-16 08:41:44 +01:00
charlesgauthereau 2d4542be5f chore: Cargo.lock 2026-02-16 08:21:32 +01:00
charlesgauthereau 4a00ed574d chore(release): 1.1.1 2026-02-16 08:21:10 +01:00
Charles GTE fd220598fc Merge pull request #12 from Portabase/fix/s3-region
fix/s3-region
2026-02-16 08:19:11 +01:00
charlesgauthereau d8b239a123 fix: s3 region to us-east-1 2026-02-16 08:18:14 +01:00
Charles GTE ebf0526366 Update README.md 2026-02-15 11:52:35 +01:00
Charles GTE 6461c1523b Merge pull request #11 from Portabase/dev
dev
2026-02-15 11:51:51 +01:00
charlesgauthereau 2809373de1 feat: README.md and docker-compose.yml 2026-02-15 11:50:16 +01:00
charlesgauthereau 5349e1fef9 chore(release): 1.1.0 2026-02-13 14:37:18 +01:00
charlesgauthereau 2bcb393d60 feat: Adding AES GCM encryption. 2026-02-13 14:36:54 +01:00
Charles GTE 406273796e Merge pull request #10 from Portabase/dev
dev
2026-02-13 14:36:19 +01:00
charlesgauthereau cb35347cb6 chore(release): 1.1.0-rc.2 2026-02-12 20:24:21 +01:00
Charles GTE b92138fd84 Merge pull request #9 from Portabase/fix/large-backup-v2
fix/large-backup-v2
2026-02-12 20:22:23 +01:00
charlesgauthereau f4c54836f1 feat: Adding AES GCM encryption. 2026-02-12 20:21:07 +01:00
charlesgauthereau e678cf4b06 feat: Adding AES GCM encryption. 2026-02-12 19:49:17 +01:00
charlesgauthereau 3c599e94de feat: Adding AES GCM encryption. 2026-02-12 19:16:52 +01:00
charlesgauthereau 6bbc856f62 feat: Adding AES GCM encryption. 2026-02-12 18:45:38 +01:00
charlesgauthereau 417212c9e8 chore(release): 1.1.0-rc.1 2026-02-10 20:12:05 +01:00
charlesgauthereau 552f1b8813 chore(release): 1.1.0-rc.1 2026-02-10 20:09:08 +01:00
charlesgauthereau e2d7c4747e feat: Ready for Testing. 2026-02-10 20:08:00 +01:00
charlesgauthereau 08b5124a5a feat: added the is_locked check for database. 2026-02-10 19:59:13 +01:00
charlesgauthereau cc0de33a62 fix: working integrating google drive 2026-02-08 20:42:30 +01:00
charlesgauthereau ce00959feb fix: working on restore. 2026-02-08 16:54:45 +01:00
charlesgauthereau cfef9b047b fix: working on metadata update between server and agent. 2026-02-07 23:31:32 +01:00
charlesgauthereau caf6127f7a fix: start working on s3 provider 2026-02-05 22:46:00 +01:00
charlesgauthereau b71f29eb21 fix: fix upload_futures 2026-02-05 08:57:15 +01:00
charlesgauthereau 2988cb297b fix: Working on multiple providers methods 2026-02-04 23:04:31 +01:00
charlesgauthereau 5019e9585b fix: adding the metadata into tasks and also updated them is cron of storages changed 2026-02-04 21:37:53 +01:00
charlesgauthereau 027751febb chore(release): 1.0.5-rc.2 2026-02-01 19:51:46 +01:00
charlesgauthereau f6f378d584 chore(release): 1.0.5-rc.1 2026-02-01 18:21:55 +01:00
charlesgauthereau 66c0b04759 fix: for testing 2026-02-01 18:20:49 +01:00
charlesgauthereau c348253015 fix: refactoring for big backup files. 2026-02-01 15:49:33 +01:00
charlesgauthereau e83e44a39e chore: Cargo.lock 2026-01-28 23:32:08 +01:00
charlesgauthereau 92d64c0b4b chore(release): 1.0.4 2026-01-28 23:31:34 +01:00
Charles GTE abd39e2db1 Merge pull request #8 from Portabase/fix/docker-image
Fix/docker image
2026-01-28 23:31:10 +01:00
charlesgauthereau 48a4ef6cc2 fix: Dockerfile 2026-01-28 23:30:37 +01:00
charlesgauthereau 358bffd675 chore(release): 1.0.4-rc.20 2026-01-28 23:21:30 +01:00
charlesgauthereau 25e08a2b94 chore(release): 1.0.4-rc.19 2026-01-28 23:12:20 +01:00
charlesgauthereau dc563d3cfd chore(release): 1.0.4-rc.18 2026-01-28 23:01:22 +01:00
charlesgauthereau 92ad1cbfb4 chore(release): 1.0.4-rc.17 2026-01-28 22:59:35 +01:00
charlesgauthereau 82d5306dd4 chore(release): 1.0.4-rc.16 2026-01-28 22:46:27 +01:00
charlesgauthereau 52714cda21 chore(release): 1.0.4-rc.15 2026-01-28 22:25:53 +01:00
charlesgauthereau fa46d1bbc4 chore(release): 1.0.4-rc.14 2026-01-28 22:15:26 +01:00
charlesgauthereau 5535b4b22f chore(release): 1.0.4-rc.13 2026-01-28 22:02:31 +01:00
charlesgauthereau 0e86a813b5 chore(release): 1.0.4-rc.12 2026-01-28 22:00:27 +01:00
charlesgauthereau ecdb4a067d chore(release): 1.0.4-rc.11 2026-01-28 21:48:08 +01:00
charlesgauthereau 8078d733e4 chore(release): 1.0.4-rc.10 2026-01-28 21:40:05 +01:00
charlesgauthereau 06c4a05cbe chore(release): 1.0.4-rc.9 2026-01-28 21:38:58 +01:00
charlesgauthereau 6985260a8e chore(release): 1.0.4-rc.8 2026-01-28 21:24:24 +01:00
charlesgauthereau 313693f50b chore(release): 1.0.4-rc.7 2026-01-28 21:20:53 +01:00
charlesgauthereau 2e7ccb7897 chore(release): 1.0.4-rc.6 2026-01-28 21:12:45 +01:00
charlesgauthereau 11cba862ab chore(release): 1.0.4-rc.5 2026-01-28 21:03:56 +01:00
charlesgauthereau 7b40ce6d83 chore(release): 1.0.4-rc.4 2026-01-28 20:49:05 +01:00
charlesgauthereau e6b0653e48 chore(release): 1.0.4-rc.3 2026-01-28 20:42:54 +01:00
charlesgauthereau a215c95b5e chore(release): 1.0.4-rc.2 2026-01-28 20:38:22 +01:00
charlesgauthereau 6fb3b8bb37 chore(release): 1.0.4-rc.1 2026-01-28 19:47:21 +01:00
charlesgauthereau aedb6a0ebc fix: Dockerfile 2026-01-28 19:46:14 +01:00
charlesgauthereau 97c770becf fix: Dockerfile 2026-01-28 17:21:30 +01:00
charlesgauthereau 73279f5b76 chore(release): 1.0.3 2026-01-28 17:21:17 +01:00
Charles GTE 8f7b0523a4 Merge pull request #7 from Portabase/fix/pipeline
fix/pipeline
2026-01-28 17:19:33 +01:00
charlesgauthereau 321d9a5ca9 fix: Dockerfile 2026-01-28 17:18:56 +01:00
charlesgauthereau a23571bcb2 chore(release): 1.0.3-rc.16 2026-01-28 17:11:23 +01:00
charlesgauthereau ab22b44c18 chore(release): 1.0.3-rc.15 2026-01-28 16:08:59 +01:00
charlesgauthereau fcac5bd0da chore(release): 1.0.3-rc.14 2026-01-28 16:05:46 +01:00
charlesgauthereau 2b8628899d fix: Dockerfile 2026-01-28 16:05:45 +01:00
charlesgauthereau 2e11ba2fd4 chore(release): 1.0.3-rc.13 2026-01-28 15:51:35 +01:00
charlesgauthereau 7d424a78f1 chore(release): 1.0.3-rc.12 2026-01-28 15:30:38 +01:00
charlesgauthereau 6089e19412 fix: Dockerfile 2026-01-28 15:30:21 +01:00
charlesgauthereau 952c70de61 chore(release): 1.0.3-rc.11 2026-01-28 15:19:47 +01:00
charlesgauthereau 99c42206c1 chore(release): 1.0.3-rc.10 2026-01-28 14:53:04 +01:00
charlesgauthereau 09b1869833 fix: assets 2026-01-28 14:53:01 +01:00
Charles GTE b2f8d56efb Merge pull request #5 from Portabase/fix/mongodb-production-docker
fix: mongo docker configuration.
2026-01-28 14:51:56 +01:00
charlesgauthereau ddffae0d23 chore(release): 1.0.3-rc.9 2026-01-28 14:51:22 +01:00
143 changed files with 7049 additions and 1247 deletions
+23
View File
@@ -0,0 +1,23 @@
reviews:
auto_review:
enabled: true
ignore_usernames: ["dependabot[bot]"]
labels: ["!wip", "!draft"]
auto_apply_labels: true
suggested_reviewers: true
auto_assign_reviewers: true
issue_enrichment:
auto_enrich:
enabled: true
labeling:
auto_apply_labels: true
labeling_instructions:
- label: bug
instructions: "Error, crash, or incorrect behavior reports"
- label: enhancement
instructions: "Feature requests or improvements"
- label: documentation
instructions: "Docs updates or missing documentation"
- label: good first issue
instructions: "Beginner-friendly tasks suitable for new contributors"
+73
View File
@@ -0,0 +1,73 @@
name: Discord Notification
on:
workflow_call:
inputs:
release_tag:
required: true
type: string
discord_title:
required: true
type: string
discord_color:
required: true
type: number
discord_footer:
required: true
type: string
secrets:
DISCORD_WEBHOOK:
required: true
GH_TOKEN:
required: true
jobs:
notify-discord:
runs-on: ubuntu-latest
steps:
- name: Send Discord Notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
RELEASE_INFO=$(gh release view "${{ inputs.release_tag }}" -R ${{ github.repository }} --json name,url,body,author)
RELEASE_TITLE=$(echo "$RELEASE_INFO" | jq -r .name)
if [ -z "$RELEASE_TITLE" ] || [ "$RELEASE_TITLE" = "null" ]; then RELEASE_TITLE="${{ inputs.release_tag }}"; fi
RELEASE_URL=$(echo "$RELEASE_INFO" | jq -r .url)
RELEASE_BODY=$(echo "$RELEASE_INFO" | jq -r .body)
AUTHOR_NAME="Portabase"
AUTHOR_ICON="https://github.com/Portabase.png"
PAYLOAD=$(jq -n \
--arg title "$RELEASE_TITLE" \
--arg description "$RELEASE_BODY" \
--arg url "$RELEASE_URL" \
--arg author "$AUTHOR_NAME" \
--arg icon "$AUTHOR_ICON" \
--arg discord_title "${{ inputs.discord_title }}" \
--arg discord_footer "${{ inputs.discord_footer }}" \
--argjson discord_color ${{ inputs.discord_color }} \
'{
content: $discord_title,
embeds: [{
title: $title,
url: $url,
description: $description,
color: $discord_color,
author: {
name: $author,
icon_url: $icon
},
footer: {
text: $discord_footer
}
}]
}'
)
curl -H "Content-Type: application/json" \
-d "$PAYLOAD" \
"$DISCORD_WEBHOOK"
+90 -52
View File
@@ -3,10 +3,16 @@ name: Docker Publish
on:
workflow_call:
inputs:
version:
required: true
type: string
ref:
required: true
type: string
image_name:
required: false
type: string
default: 'portabase/agent'
default: "portabase/agent"
add_latest:
required: false
type: boolean
@@ -14,11 +20,11 @@ on:
target:
required: false
type: string
default: 'prod'
default: "prod"
dockerfile:
required: false
type: string
default: './docker/Dockerfile'
default: "./docker/Dockerfile"
secrets:
DOCKER_USERNAME:
required: true
@@ -26,76 +32,108 @@ on:
required: true
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
build:
name: Build architectures
runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-latest' || 'ubuntu-24.04-arm' }}
strategy:
fail-fast: false
matrix:
platform: [ linux/amd64, linux/arm64 ]
steps:
- name: Check out the repo
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
fetch-depth: 0
- name: Set up QEMU (multi-arch support)
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true
- name: Log in to Docker Hub
uses: docker/login-action@v2
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set tags
id: set-tags
- name: Prepare Image Tags
id: prep
run: |
REF_NAME=${GITHUB_REF#refs/tags/}
TAGS="${{ inputs.image_name }}:$REF_NAME"
if [[ "${{ inputs.add_latest }}" == "true" ]]; then
TAGS="$TAGS,${{ inputs.image_name }}:latest"
fi
echo "tags=$TAGS" >> $GITHUB_OUTPUT
ARCH=${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
echo "image=${{ inputs.image_name }}:${{inputs.version}}-$ARCH" >> $GITHUB_OUTPUT
echo "safe_platform=${{ matrix.platform == 'linux/amd64' && 'linux-amd64' || 'linux-arm64' }}" >> $GITHUB_OUTPUT
- name: Build amd64 image
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
file: ${{ inputs.dockerfile }}
platforms: linux/amd64
platforms: ${{ matrix.platform }}
push: true
tags: ${{ inputs.image_name }}:amd64
tags: ${{ steps.prep.outputs.image }}
target: ${{ inputs.target }}
cache-from: type=registry,ref=${{ inputs.image_name }}:buildcache-amd64
cache-to: type=registry,ref=${{ inputs.image_name }}:buildcache-amd64,mode=max
- name: Build arm64 image
uses: docker/build-push-action@v6
- name: Save image name for manifest
run: echo "${{ steps.prep.outputs.image }}" > image.txt
- uses: actions/upload-artifact@v4
with:
context: .
file: ${{ inputs.dockerfile }}
platforms: linux/arm64
push: true
tags: ${{ inputs.image_name }}:arm64
target: ${{ inputs.target }}
cache-from: type=registry,ref=${{ inputs.image_name }}:buildcache-arm64
cache-to: type=registry,ref=${{ inputs.image_name }}:buildcache-arm64,mode=max
name: image-${{ steps.prep.outputs.safe_platform }}
path: image.txt
retention-days: 1
- name: Create and push multi-arch manifest
create-manifest:
name: Create multi-arch manifest
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/download-artifact@v4
with:
name: image-linux-amd64
path: /tmp/digests/amd64
- uses: actions/download-artifact@v4
with:
name: image-linux-arm64
path: /tmp/digests/arm64
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Generate semantic tags
id: tags
run: |
REF_NAME=${GITHUB_REF#refs/tags/}
docker manifest create ${{ inputs.image_name }}:$REF_NAME \
--amend ${{ inputs.image_name }}:amd64 \
--amend ${{ inputs.image_name }}:arm64
docker manifest push ${{ inputs.image_name }}:$REF_NAME
if [[ "${{ inputs.add_latest }}" == "true" ]]; then
docker manifest create ${{ inputs.image_name }}:latest \
--amend ${{ inputs.image_name }}:amd64 \
--amend ${{ inputs.image_name }}:arm64
docker manifest push ${{ inputs.image_name }}:latest
VERSION="${{ inputs.version }}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
echo "VERSION_TAG=$VERSION" >> $GITHUB_OUTPUT
if [ -n "$MINOR" ]; then
echo "MINOR_TAG=$MAJOR.$MINOR" >> $GITHUB_OUTPUT
fi
if [ -n "$MAJOR" ]; then
echo "MAJOR_TAG=$MAJOR" >> $GITHUB_OUTPUT
fi
if [ "${{ inputs.add_latest }}" = "true" ]; then
echo "LATEST_TAG=latest" >> $GITHUB_OUTPUT
fi
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.image_name }}
tags: |
type=raw,value=${{ steps.tags.outputs.VERSION_TAG }}
type=raw,value=${{ steps.tags.outputs.MINOR_TAG }}
type=raw,value=${{ steps.tags.outputs.MAJOR_TAG }}
type=raw,value=${{ steps.tags.outputs.LATEST_TAG }}
- name: Create and push manifest list
working-directory: /tmp/digests
run: |
DOCKER_IMAGES="$(cat amd64/image.txt) $(cat arm64/image.txt)"
TAG_ARGS=$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON")
echo $TAG_ARGS
docker buildx imagetools create $TAG_ARGS $DOCKER_IMAGES
-128
View File
@@ -1,128 +0,0 @@
name: GitHub Release
on:
workflow_call:
inputs:
prerelease:
required: false
type: boolean
default: false
make_latest:
required: false
type: boolean
default: false
discord_title:
required: true
type: string
discord_color:
required: true
type: number
discord_footer:
required: true
type: string
secrets:
DISCORD_WEBHOOK:
required: true
GH_TOKEN:
required: true
jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build Changelog
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v5
with:
mode: "COMMIT"
configurationJson: |
{
"template": "#{{CHANGELOG}}",
"categories": [
{
"title": "## Feature",
"labels": ["feat", "feature"]
},
{
"title": "## Fix",
"labels": ["fix", "bug"]
},
{
"title": "## Other",
"labels": []
}
],
"label_extractor": [
{
"pattern": "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)",
"on_property": "title",
"target": "$1"
}
]
}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: false
body: ${{ steps.build_changelog.outputs.changelog }}
prerelease: ${{ inputs.prerelease }}
make_latest: ${{ inputs.make_latest }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Send Discord Notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
RELEASE_INFO=$(gh release view "${{ github.ref_name }}" -R ${{ github.repository }} --json name,url,body,author)
RELEASE_TITLE=$(echo "$RELEASE_INFO" | jq -r .name)
if [ -z "$RELEASE_TITLE" ] || [ "$RELEASE_TITLE" = "null" ]; then RELEASE_TITLE="${{ github.ref_name }}"; fi
RELEASE_URL=$(echo "$RELEASE_INFO" | jq -r .url)
RELEASE_BODY=$(echo "$RELEASE_INFO" | jq -r .body)
AUTHOR_NAME="Portabase"
AUTHOR_ICON="https://github.com/Portabase.png"
PAYLOAD=$(jq -n \
--arg title "$RELEASE_TITLE" \
--arg description "$RELEASE_BODY" \
--arg url "$RELEASE_URL" \
--arg author "$AUTHOR_NAME" \
--arg icon "$AUTHOR_ICON" \
--arg discord_title "${{ inputs.discord_title }}" \
--arg discord_footer "${{ inputs.discord_footer }}" \
--argjson discord_color ${{ inputs.discord_color }} \
'{
content: $discord_title,
embeds: [{
title: $title,
url: $url,
description: $description,
color: $discord_color,
author: {
name: $author,
icon_url: $icon
},
footer: {
text: $discord_footer
}
}]
}'
)
curl -H "Content-Type: application/json" \
-d "$PAYLOAD" \
"$DISCORD_WEBHOOK"
+37
View File
@@ -0,0 +1,37 @@
name: Publish Helm Chart
on:
workflow_call:
inputs:
version:
required: true
type: string
secrets:
GH_TOKEN:
required: true
jobs:
publish-helm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v4
- name: Package Helm chart
run: |
mkdir -p ./helm-packages
helm package helm \
--version ${{ inputs.version }} \
--app-version ${{ inputs.version }} \
--destination ./helm-packages
- name: Authenticate to GitHub Packages
run: |
echo "${{ secrets.GH_TOKEN }}" | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push Helm chart to GitHub Packages (OCI)
run: |
helm push ./helm-packages/portabase-agent-${{ inputs.version }}.tgz oci://ghcr.io/portabase/charts
+128 -12
View File
@@ -1,32 +1,148 @@
name: Publish Docker image for release
name: Auto Release & Publish
on:
push:
tags:
- '*.*.*'
- '!*-*'
pull_request:
types: [ closed ]
branches:
- main
permissions:
contents: write
packages: write
jobs:
docker_publish:
check-skip:
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.set-skip.outputs.skip }}
steps:
- name: Determine if release should be skipped
id: set-skip
run: |
TITLE="${{ github.event.pull_request.title }}"
echo "PR title: $TITLE"
if [[ "$TITLE" == *"[skip-release]"* ]]; then
echo "PR title contains [skip-release], skipping release jobs."
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
create-release:
needs: check-skip
if: ${{ needs.check-skip.outputs.skip == 'false' }}
runs-on: ubuntu-latest
outputs:
draft_tag: ${{ steps.release_step.outputs.draft_tag }}
version: ${{ steps.release_step.outputs.version }}
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
ref: main
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-edit
run: cargo install cargo-edit
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install release-it globally
run: |
npm install -g release-it
npm install -g @release-it/conventional-changelog
npm install -g @release-it/bumper
- run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Run release-it
id: release_step
run: |
git pull origin main
VERSION=$(release-it --ci --release-version)
echo $VERSION
echo "version=$VERSION" >> $GITHUB_OUTPUT
OUTPUT=$(release-it --ci)
echo "$OUTPUT"
DRAFT_TAG=$(echo "$OUTPUT" | grep -oE 'untagged-[a-z0-9]+')
echo $DRAFT_TAG
echo "draft_tag=$DRAFT_TAG" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
publish-docker:
needs: create-release
if: ${{ needs.create-release.result == 'success' }}
uses: ./.github/workflows/docker.yml
with:
version: ${{ needs.create-release.outputs.version }}
ref: ${{ needs.create-release.outputs.version }}
add_latest: true
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
github_release:
needs: docker_publish
uses: ./.github/workflows/github.yml
publish-helm:
needs: create-release
if: ${{ needs.create-release.result == 'success' }}
uses: ./.github/workflows/helm.yml
with:
prerelease: false
make_latest: true
version: ${{ needs.create-release.outputs.version }}
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
finalize-release:
needs:
- create-release
- publish-docker
- publish-helm
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.publish_release_step.outputs.release_tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Publish GitHub Release
id: publish_release_step
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
OUTPUT=$(gh release edit ${{ needs.create-release.outputs.draft_tag }} --draft=false)
echo "$OUTPUT"
RELEASE_TAG=$(echo "$OUTPUT" | sed -E 's|.*/releases/tag/||')
echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
notify-discord:
needs:
- publish-docker
- publish-helm
- create-release
- finalize-release
uses: ./.github/workflows/discord.yml
with:
release_tag: ${{ needs.create-release.outputs.version }}
discord_title: "||@release-agent|| New release published"
discord_color: 5814783
discord_color: 3066993
discord_footer: "Portabase"
secrets:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
+62
View File
@@ -0,0 +1,62 @@
{
"github": {
"release": true,
"draft": true,
"tokenRef": "GITHUB_TOKEN"
},
"git": {
"commit": true,
"commitMessage": "chore: release ${version}",
"requireCleanWorkingDir": true,
"tag": true,
"tagName": "${version}",
"push": true
},
"hooks": {
"before:bump": "cargo set-version ${version}"
},
"plugins": {
"@release-it/conventional-changelog": {
"preset": {
"name": "conventionalcommits",
"types": [
{
"type": "feat",
"section": "✨ Features"
},
{
"type": "fix",
"section": "🐛 Bug Fixes"
},
{
"type": "perf",
"section": "⚡️ Performance Improvements"
},
{
"type": "revert",
"section": "⏪️ Reverts"
},
{
"type": "docs",
"section": "📝 Documentation",
"hidden": true
},
{
"type": "chore",
"section": "🔧 Chores",
"hidden": true
}
]
}
},
"@release-it/bumper": {
"out": [
{
"file": "CITATION.cff",
"path": "version",
"type": "text/yaml"
}
]
}
}
}
+9 -4
View File
@@ -1,6 +1,6 @@
cff-version: 1.2.0
title: Portabase Agent (Rust)
message: "If you use this software, please cite it as below."
message: If you use this software, please cite it as below.
type: software
authors:
- family-names: Gauthereau
@@ -9,7 +9,12 @@ authors:
given-names: Killian
repository-code: https://github.com/Portabase/agent-rust
url: https://portabase.io
abstract: "Portabase is a free, open-source, self-hosted solution for database administration, providing backup and restore capabilities, scheduling, retention policies, notifications, and support for multiple storage backends. Its headless agent architecture enables connection to multiple database instances securely and efficiently."
abstract: >-
Portabase is a free, open-source, self-hosted solution for database
administration, providing backup and restore capabilities, scheduling,
retention policies, notifications, and support for multiple storage backends.
Its headless agent architecture enables connection to multiple database
instances securely and efficiently.
keywords:
- database
- administration
@@ -22,5 +27,5 @@ keywords:
- self-hosted
- portabase
license: Apache-2.0
version: 1.0.3-rc.8
date-released: "2026-01-28"
version: 1.4.0
date-released: '2026-02-24'
Generated
+2480 -256
View File
File diff suppressed because it is too large Load Diff
+30 -4
View File
@@ -1,6 +1,6 @@
[package]
name = "portabase-agent"
version = "1.0.3-rc.8"
version = "1.4.0"
edition = "2024"
[dependencies]
@@ -17,7 +17,7 @@ base64 = "0.22.1"
thiserror = "2.0.17"
log = "0.4.29"
toml = "0.9.10"
reqwest = { version = "0.13.1", features = ["json", "blocking", "multipart"] }
reqwest = { version = "0.13.1", features = ["json", "blocking", "multipart", "stream", "query"] }
anyhow = "1.0.100"
tokio = { version = "1.49.0", features = ["rt", "rt-multi-thread", "macros", "fs"] }
async-trait = "0.1.89"
@@ -28,11 +28,37 @@ flate2 = "1.1.5"
tar = "0.4.44"
tokio-postgres = "0.7.15"
futures = "0.3.31"
tracing-log = "0.2.0"
tracing-appender = "0.2.4"
time = { version = "0.3.44", features = ["macros"] }
mongodb = "3.5.0"
rand = "0.9.2"
bytes = "1.11.0"
async-stream = "0.3.6"
uuid = { version = "1.20.0", features = ["v4"] }
tokio-util = "0.7.18"
aws-config = "1.8.13"
aws-sdk-s3 = { version = "1.122.0", features = ["behavior-version-latest"] }
async-compression = { version = "0.4.37", features = ["tokio", "gzip"] }
tokio-tar = "0.3.1"
oauth2 = "5.0.0"
hyper = "1.8.1"
aes-gcm = "0.11.0-rc.3"
generic-array = "0.14.7"
futures-util = "0.3.31"
tokio-stream = "0.1.18"
aes = "0.9.0-rc.4"
typenum = "1.19.0"
testcontainers = "0.27.1"
testcontainers-modules = { version = "0.15.0", features = ["postgres"] }
postgres = "0.19.12"
[dev-dependencies]
tokio = { version = "1", features = ["full"] }
mockall = "0.13"
testcontainers = "0.27.1"
wiremock = "0.6"
[[bin]]
name = "app"
path = "src/main.rs"
path = "src/main.rs"
+25
View File
@@ -1,8 +1,12 @@
include .env
export $(shell sed 's/=.*//' .env)
CLUSTER_SCRIPT=docker/entrypoints/app-dev-entrypoint.sh
.PHONY: seed-mongo seed-mysql seed-postgres
up:
@bash $(CLUSTER_SCRIPT)
seed-mongo:
@echo "Seeding MongoDB..."
bash ./scripts/mongo/seed-mongo.sh
@@ -15,6 +19,10 @@ seed-mysql:
@echo "Seeding MySQL..."
mysql -h 127.0.0.1 -P "$$MYSQL_PORT" -u "$$MYSQL_USER" -p"$$MYSQL_PASSWORD" "$$MYSQL_DB" < ./scripts/mysql/seed-mysql.sql
seed-mysql-1gb:
@echo "Seeding MySQL..."
mysql -h 127.0.0.1 -P "$$MYSQL_PORT" -u "$$MYSQL_USER" -p"$$MYSQL_PASSWORD" "$$MYSQL_DB" < ./scripts/mysql/seed-1gb.sql
seed-postgres:
@echo "Seeding Postgres..."
@@ -26,4 +34,21 @@ seed-postgres-1gb:
docker exec -i -e PGPASSWORD=$$PG_PASSWORD $$PG_CONTAINER \
psql -U $$PG_USER -d $$PG_DB < ./scripts/postgres/seed-1gb.sql
SQLITE_SEED_FILE := $(if $(filter big,$(SEED)),./scripts/sqlite/seed-big.sql,./scripts/sqlite/seed.sql)
seed-sqlite:
@echo "Seeding Sqlite..."
@echo "Run as root to fix permissions inside the volume"
docker exec -u 0 -it db-sqlite sh -c "chmod -R 777 /workspace/data"
@echo "Create the database file (if it doesnt exist)"
docker exec -u 0 -it db-sqlite sh -c "touch /workspace/data/app.db"
@echo "Seed the database"
docker exec -i db-sqlite sh -c "sqlite3 /workspace/data/app.db" < $(SQLITE_SEED_FILE)
@echo "Verify"
docker exec -it db-sqlite sqlite3 /workspace/data/app.db "SELECT name FROM sqlite_master WHERE type='table';"
@echo "Done"
seed-all: seed-mongo seed-mysql seed-postgres seed-postgres-1gb
+3
View File
@@ -19,6 +19,7 @@
[![PostgreSQL](https://img.shields.io/badge/python-3.13-blue.svg)](https://www.python.org/downloads/release/python-3120/)
[![PostgreSQL](https://img.shields.io/badge/PostgreSQL-336791?logo=postgresql&logoColor=white)](https://www.postgresql.org/)
[![MySQL](https://img.shields.io/badge/MySQL-4479A1?logo=mysql&logoColor=white)](https://www.mysql.com/)
[![SQLite](https://img.shields.io/badge/-SQLite-blue?logo=sqlite&logoColor=white)](https://sqlite.org/)
[![MariaDB](https://img.shields.io/badge/MariaDB-003545?logo=mariadb&logoColor=white)](https://mariadb.org/)
[![MongoDB](https://img.shields.io/badge/-MongoDB-13aa52?logo=mongodb&logoColor=white)](https://www.mongodb.com/)
[![Self Hosted](https://img.shields.io/badge/self--hosted-yes-brightgreen)](https://github.com/Portabase/portabase)
@@ -79,3 +80,5 @@ Distributed under the Apache License. See `LICENSE.txt` for more information.
[Docker-url]: https://www.docker.com/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+12 -2
View File
@@ -34,11 +34,21 @@
"name": "Test database 5 - MongoDB",
"database": "testdb",
"type": "mongodb",
"username": "",
"password": "",
"port": 27017,
"host": "db-mongodb",
"generated_id": "16678147-ff7e-4c97-8c83-0adeff214681"
},
{
"name": "Test database 6 - SQLite DB",
"type": "sqlite",
"path": "/sqlite-data/workspace/data/app.db",
"generated_id": "16678178-ff7e-4c97-8c83-0adeff214681"
},
{
"name": "Test database 7 - SQLite DB",
"type": "sqlite",
"path": "/sqlite-data-2/workspace/data/app.db",
"generated_id": "16678179-ff7e-4c97-8c83-0adeff214681"
}
]
}
+48 -5
View File
@@ -1,10 +1,11 @@
services:
rust-app:
# build:
# context: .
# dockerfile: docker/Dockerfile
# target: prod
# build:
# context: .
# dockerfile: docker/Dockerfile
# target: prod
image: portabase/agent:latest
# platform: linux/arm64
container_name: rust-prod
volumes:
- ./databases.json:/config/config.json
@@ -13,7 +14,7 @@ services:
LOG: info
TZ: "Europe/Paris"
# DATABASES_CONFIG_FILE: "config.toml"
EDGE_KEY: "eyJzZXJ2ZXJVcmwiOiJodHRwOi8vbG9jYWxob3N0Ojg4ODciLCJhZ2VudElkIjoiY2VlZmNmNDQtOGE0YS00NjZlLTkwNDEtN2QzNDMzZjRjOTJkIiwicHVibGljS2V5IjoiLS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tXG5NSUlCQ2dLQ0FRRUFuYUVKdnVBSExlNGF5d0RmNGplelVobm45VXRkdksyZ3pEMEg2cERJYXczYkJKRkpwVnVDXG5uVFV3MXA3Q2RnOXBzdjZhRnpyOXZPd0J2MjMzckxpdVpCT2lCb2p2Q0QrSlZid3hyTzBRRW5hN2dmaHV1ZGYwXG5VVlJOMkxmK1g1aTkvZzJTNm5xcExoTm1DaGFJNk8ybktYZUNlRmtubEErRUJrNnFoV1FCVGozb05TYTFTOFY1XG40UFRTT2I4NUo3a2k5YllEbXRiNWxrU3dCNXdXOTdtQjg0ZzI2WHAvU3FFcmhKc0NGK3YrN09vTWYzTzJqTTNoXG5XMUQ0MzBPRitWaklwUGdoV09rZy96NXZQUWFHRzhqQ0h4VDlJR0Q0bjhyS05LQ3FTOGNyN2diTGU0cWpNdmhvXG5BQVVvaHpHR2FRNkhlWlJ4S0UvM3J1a2JldnY5dnJ2TTNRSURBUUFCXG4tLS0tLUVORCBSU0EgUFVCTElDIEtFWS0tLS0tXG4ifQ"
EDGE_KEY: "eyJzZXJ2ZXJVcmwiOiJodHRwOi8vbG9jYWxob3N0Ojg4ODciLCJhZ2VudElkIjoiOGZmMDE4NTQtYjJhMS00ZTE0LTkwMjctZTJiOWIxZjQ1YzdlIiwicHVibGljS2V5IjoiLS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tXG5NSUlCQ2dLQ0FRRUE5TWV4M2pmdnVLdFB5YU1ERnh2Ulp2dmd3YkRJQ2JzQi81Wll5NDNSVVRBaXZRYjJiSDdYXG5qRHBQd1lJeCs4UFBrbHlRbDVMQzV1UWZEaCs4SVd4OG1LZ3FvMXpWMkdiZXdGbEdEWFYxVEdyU1ZEU25aSWR4XG52bWdYc29EeXhVMlJvWUFUMS9YMWxuc2YxenZKdkFMTkhXdEhRdk42SjVDZTFSMmFsendVRGFEVXlJNzRmSldQXG5tNTh0SDMrYklXL0VVTXdjaWNxM0oySWw3Vm9KNkZNUHJQL1ZSOWEvdFF1SU1qa200MXpFY2NscExPa2luRkxuXG54NmVUWkFSZUpya2UrbnRvZ2t4TGEyRWV5a1lUNzB4V3hKNWp5ZExBVnRvNkkyQlVLVVJoTkowTUFaU29NYUtvXG5iMGJRcnY1UzExZWllMnMrT2I3aTYzSFpkVUx0UmV1MVJ3SURBUUFCXG4tLS0tLUVORCBSU0EgUFVCTElDIEtFWS0tLS0tXG4ifQ"
extra_hosts:
- "localhost:host-gateway"
networks:
@@ -21,6 +22,48 @@ services:
db-mongodb-auth:
container_name: db-mongodb-auth
image: mongo:latest
ports:
- "27082:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: rootpassword
MONGO_INITDB_DATABASE: testdbauth
command: mongod --auth
networks:
- portabase
volumes:
- mongodb-data-auth:/data/db
healthcheck:
test: [ "CMD", "mongo", "--eval", "db.adminCommand('ping')" ]
interval: 5s
timeout: 5s
retries: 10
db-mongodb:
container_name: db-mongodb
image: mongo:latest
ports:
- "27083:27017"
volumes:
- mongodb-data:/data/db
healthcheck:
test: [ "CMD", "mongosh", "--eval", "db.adminCommand('ping')" ]
interval: 5s
timeout: 5s
retries: 10
environment:
MONGO_INITDB_DATABASE: testdb
networks:
- portabase
volumes:
mongodb-data:
mongodb-data-auth:
networks:
portabase:
name: portabase_network
+67 -56
View File
@@ -4,7 +4,6 @@ services:
context: .
dockerfile: docker/Dockerfile
target: dev
platform: linux/arm64
container_name: rust-dev
volumes:
- .:/app
@@ -13,11 +12,13 @@ services:
- cargo-registry:/usr/local/cargo/registry
- cargo-git:/usr/local/cargo/git
- cargo-target:/app/target
# - sqlite-data:/sqlite-data/workspace/data
# - ./scripts/sqlite/test-db:/sqlite-data-2/workspace/data
environment:
APP_ENV: development
LOG: debug
TZ: "Europe/Paris"
EDGE_KEY: "eyJzZXJ2ZXJVcmwiOiJodHRwOi8vbG9jYWxob3N0Ojg4ODciLCJhZ2VudElkIjoiNmExMzc0M2ItYjMwZS00Zjg4LWJjY2EtMmMwZjE2NWVjYjQxIiwicHVibGljS2V5IjoiLS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tXG5NSUlCQ2dLQ0FRRUE5TWV4M2pmdnVLdFB5YU1ERnh2Ulp2dmd3YkRJQ2JzQi81Wll5NDNSVVRBaXZRYjJiSDdYXG5qRHBQd1lJeCs4UFBrbHlRbDVMQzV1UWZEaCs4SVd4OG1LZ3FvMXpWMkdiZXdGbEdEWFYxVEdyU1ZEU25aSWR4XG52bWdYc29EeXhVMlJvWUFUMS9YMWxuc2YxenZKdkFMTkhXdEhRdk42SjVDZTFSMmFsendVRGFEVXlJNzRmSldQXG5tNTh0SDMrYklXL0VVTXdjaWNxM0oySWw3Vm9KNkZNUHJQL1ZSOWEvdFF1SU1qa200MXpFY2NscExPa2luRkxuXG54NmVUWkFSZUpya2UrbnRvZ2t4TGEyRWV5a1lUNzB4V3hKNWp5ZExBVnRvNkkyQlVLVVJoTkowTUFaU29NYUtvXG5iMGJRcnY1UzExZWllMnMrT2I3aTYzSFpkVUx0UmV1MVJ3SURBUUFCXG4tLS0tLUVORCBSU0EgUFVCTElDIEtFWS0tLS0tXG4ifQ"
EDGE_KEY: "eyJzZXJ2ZXJVcmwiOiJodHRwOi8vbG9jYWxob3N0Ojg4ODciLCJhZ2VudElkIjoiOGYwMmExZTAtNDY0NC00MWFmLWIzYjctYjZkYWNjNzQ4OWVhIiwibWFzdGVyS2V5QjY0IjoiQlhWM1hvbEM2NTZTVjdkTmdjV1BHUWxrKytycExJNmxHRGk3Q1BCNWllbz0ifQ=="
#POOLING: 1
#DATABASES_CONFIG_FILE: "config.toml"
extra_hosts:
@@ -25,19 +26,19 @@ services:
networks:
- portabase
# db-postgres:
# container_name: db-postgres
# image: postgres:17-alpine
# ports:
# - "5436:5432"
# volumes:
# - postgres-data:/var/lib/postgresql/data
# environment:
# - POSTGRES_DB=devdb
# - POSTGRES_USER=devuser
# - POSTGRES_PASSWORD=changeme
# networks:
# - portabase
db-postgres:
container_name: db-postgres
image: postgres:17-alpine
ports:
- "5436:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=devdb
- POSTGRES_USER=devuser
- POSTGRES_PASSWORD=changeme
networks:
- portabase
#
# db-mariadb:
# container_name: db-mariadb
@@ -53,59 +54,69 @@ services:
# - mariadb-data:/var/lib/mysql
# networks:
# - portabase
#
#
# db-mongodb-auth:
# container_name: db-mongodb-auth
# image: mongo:latest
# ports:
# - "27082:27017"
# environment:
# MONGO_INITDB_ROOT_USERNAME: root
# MONGO_INITDB_ROOT_PASSWORD: rootpassword
# MONGO_INITDB_DATABASE: testdbauth
# command: mongod --auth
# networks:
# - portabase
# volumes:
# - mongodb-data-auth:/data/db
# healthcheck:
# test: [ "CMD", "mongo", "--eval", "db.adminCommand('ping')" ]
# interval: 5s
# timeout: 5s
# retries: 10
#
# db-mongodb:
# container_name: db-mongodb
# image: mongo:latest
# ports:
# - "27083:27017"
# volumes:
# - mongodb-data:/data/db
# healthcheck:
# test: [ "CMD", "mongosh", "--eval", "db.adminCommand('ping')" ]
# interval: 5s
# timeout: 5s
# retries: 10
# environment:
# MONGO_INITDB_DATABASE: testdb
# networks:
# - portabase
# sqlite:
# container_name: db-sqlite
# image: keinos/sqlite3
# volumes:
# - sqlite-data:/workspace/data
# working_dir: /workspace
# command: tail -f /dev/null
# stdin_open: true
# tty: true
db-mongodb-auth:
container_name: db-mongodb-auth
image: mongo:latest
ports:
- "27082:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: rootpassword
MONGO_INITDB_DATABASE: testdbauth
command: mongod --auth
networks:
- portabase
volumes:
- mongodb-data-auth:/data/db
healthcheck:
test: [ "CMD", "mongo", "--eval", "db.adminCommand('ping')" ]
interval: 5s
timeout: 5s
retries: 10
db-mongodb:
container_name: db-mongodb
image: mongo:latest
ports:
- "27083:27017"
volumes:
- mongodb-data:/data/db
healthcheck:
test: [ "CMD", "mongosh", "--eval", "db.adminCommand('ping')" ]
interval: 5s
timeout: 5s
retries: 10
environment:
MONGO_INITDB_DATABASE: testdb
networks:
- portabase
volumes:
cargo-registry:
cargo-git:
cargo-target:
# postgres-data:
postgres-data:
# mariadb-data:
mongodb-data:
mongodb-data-auth:
# mongodb-data:
# mongodb-data-auth:
# sqlite-data:
networks:
portabase:
name: portabase_network
external: true
# docker network create portabase_network
+35 -37
View File
@@ -1,9 +1,7 @@
# =========================
# Base Rust image
# Base image (shared)
# =========================
FROM rust:1.92 AS base
ARG TARGETARCH
FROM rust:1.92.0 AS base
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
pkg-config \
@@ -17,36 +15,45 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
zlib1g \
curl \
mariadb-client \
wget \
sqlite3 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# =========================
# PostgreSQL client binaries (only target arch)
# =========================
RUN for v in 12 13 14 15 16 17 18; do mkdir -p /usr/lib/postgresql/$v/bin; done
COPY assets/tools/$TARGETARCH/postgresql/ /tmp/pg/
RUN for v in 12 13 14 15 16 17 18; do \
cp -r /tmp/pg/postgresql-$v/bin/* /usr/lib/postgresql/$v/bin/; \
done && rm -rf /tmp/pg && chmod +x /usr/lib/postgresql/*/bin/*
ARG TARGETARCH
# =========================
# MongoDB client binaries (only target arch)
# PostgreSQL client binaries (versions 12-18)
# =========================
RUN for v in 12 13 14 15 16 17 18; do \
mkdir -p /usr/lib/postgresql/$v/bin; \
done
COPY assets/tools/amd64/postgresql/ /tmp/pg-x64/
COPY assets/tools/arm64/postgresql/ /tmp/pg-arm/
RUN if [ "$TARGETARCH" = "amd64" ]; then \
wget -q https://fastdl.mongodb.org/tools/db/mongodb-database-tools-debian12-x86_64-100.10.0.deb -O /tmp/mongodb-tools.deb; \
for v in 12 13 14 15 16 17 18; do \
cp -r /tmp/pg-x64/postgresql-$v/bin/* /usr/lib/postgresql/$v/bin/; \
done; \
elif [ "$TARGETARCH" = "arm64" ]; then \
wget -q https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-arm64-100.10.0.deb -O /tmp/mongodb-tools.deb; \
fi && dpkg -i /tmp/mongodb-tools.deb || apt-get install -f -y --no-install-recommends && \
rm -f /tmp/mongodb-tools.deb && \
mkdir -p /usr/local/mongodb/bin && \
ln -sf /usr/bin/mongodump /usr/local/mongodb/bin/mongodump || true && \
ln -sf /usr/bin/mongorestore /usr/local/mongodb/bin/mongorestore || true
for v in 12 13 14 15 16 17 18; do \
cp -r /tmp/pg-arm/postgresql-$v/bin/* /usr/lib/postgresql/$v/bin/; \
done; \
fi && \
rm -rf /tmp/pg-x64 /tmp/pg-arm && \
chmod +x /usr/lib/postgresql/*/bin/*
# =========================
# MongoDB client binaries
# =========================
COPY assets/tools/${TARGETARCH}/mongodb/ /usr/local/mongodb/
RUN chmod +x /usr/local/mongodb/bin/*
WORKDIR /app
# =========================
# Development stage
# Development image
# =========================
FROM base AS dev
@@ -57,26 +64,15 @@ RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build
RUN rm -rf src
COPY . .
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
CMD ["/entrypoint.sh"]
# =========================
# Builder stage for production
# Builder (production)
# =========================
FROM base AS builder
WORKDIR /app
RUN cargo install cargo-chef
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo chef prepare --recipe-path recipe.json
RUN cargo chef cook --recipe-path recipe.json --release
RUN rm -rf src
COPY . .
RUN cargo build --release
@@ -84,7 +80,7 @@ RUN cargo build --release
RUN echo "APP_VERSION=$(cargo pkgid | awk -F# '{print $2}')" > /app/version.env
# =========================
# Production runtime
# Runtime (production)
# =========================
FROM ubuntu:24.04 AS prod
@@ -97,18 +93,20 @@ RUN apt-get update && apt-get install -y \
libncurses6 \
zlib1g \
mariadb-client \
sqlite3 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=builder /app/target/release/app /usr/local/bin/app
COPY --from=builder /app/version.env /app/version.env
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
COPY --from=base /usr/lib/postgresql/ /usr/lib/postgresql/
COPY --from=base /usr/local/mongodb/bin /usr/local/mongodb/bin
COPY --from=base /usr/local/mongodb/bin/ /usr/local/mongodb/bin/
ENV APP_ENV=production
+39
View File
@@ -0,0 +1,39 @@
#!/bin/bash
set -euo pipefail
check_docker() {
if ! docker info > /dev/null 2>&1; then
echo "Docker is not running. Attempting to start Docker..."
if [[ "$OSTYPE" == "darwin"* ]]; then
open -a Docker
echo "Waiting for Docker to start..."
until docker info > /dev/null 2>&1; do
sleep 2
done
elif command -v systemctl >/dev/null 2>&1; then
sudo systemctl start docker
else
echo "Cannot start Docker automatically. Please start Docker manually."
exit 1
fi
else
echo "Docker is running."
fi
}
check_network() {
local network_name="portabase_network"
if ! docker network ls --format '{{.Name}}' | grep -q "^${network_name}$"; then
echo "Docker network '${network_name}' not found. Creating..."
docker network create "${network_name}"
else
echo "Docker network '${network_name}' already exists."
fi
}
check_docker
check_network
echo "Starting docker-compose..."
docker-compose -f ./docker-compose.yml up
echo "Docker-compose started successfully."
+17
View File
@@ -0,0 +1,17 @@
.DS_Store
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
*.swp
*.bak
*.tmp
*.orig
*~
.project
.idea/
*.tmproj
.vscode/
+29
View File
@@ -0,0 +1,29 @@
apiVersion: v2
name: portabase-agent
description: Helm chart for Portabase Agent
type: application
version: 0.0.0
appVersion: "latest"
keywords:
- postgresql
- mariadb
- mongodb
- mysql
- sqlite
- backup
- database
- restore
- agent
home: https://github.com/Portabase/agent
sources:
- https://github.com/Portabase/agent
- https://github.com/Portabase/agent/tree/main/helm
maintainers:
- name: Charles Gauthereau
url: https://github.com/RambokDev
- name: Killian Larcher
url: https://github.com/KillianLarcher
icon: https://raw.githubusercontent.com/Portabase/agent/main/.github/assets/logo.png
+59
View File
@@ -0,0 +1,59 @@
# Development Notes
## Check that Kubernetes is reachable locally
```bash
kubectl get nodes
```
## Install the local Portabase Agent Helm chart
```bash
helm install portabase-agent . \
--set env.EDGE_KEY=<your-edge-key>
```
## Check the pods
```bash
kubectl get pods
```
## Check the services
```bash
kubectl get svc
```
## To update .env variables or JSON config:
```bash
kubectl rollout restart deployment portabase-agent
```
## Install or upgrade the Helm chart
```bash
helm upgrade portabase-agent . \
--reuse-values \
--set env.EDGE_KEY="NEW_EDGE_KEY"
```
## Rollout to restart
```bash
kubectl rollout restart deployment portabase-agent
```
## List pods to get the pod name
```bash
kubectl get pods -l app=portabase-agent
```
## Get logs for the pod
```bash
kubectl logs portabase-agent-6f7d4f5c6b-abc12
```
## Uninstall Agent
``` bash
helm uninstall portabase-agent
```
+7
View File
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: portabase-agent-config
data:
config.json: |
{{ .Values.volume.configFile.content | nindent 4 }}
+62
View File
@@ -0,0 +1,62 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: portabase-agent
labels:
app: portabase-agent
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: portabase-agent
template:
metadata:
labels:
app: portabase-agent
spec:
hostAliases:
{{- range .Values.network.hostAliases }}
- ip: {{ .ip }}
hostnames:
{{- range .hostnames }}
- {{ . }}
{{- end }}
{{- end }}
containers:
- name: portabase-agent
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
envFrom:
- configMapRef:
name: portabase-agent-env
volumeMounts:
{{- if .Values.volume.configFile.enabled }}
{{- if .Values.volume.configFile.hostPath }}
- name: config
mountPath: /config/config.json
subPath: config.json
readOnly: true
# uses hostPath
{{- else }}
- name: config
mountPath: /config/config.json
subPath: config.json
# uses ConfigMap content
{{- end }}
{{- end }}
volumes:
{{- if .Values.volume.configFile.enabled }}
{{- if .Values.volume.configFile.hostPath }}
- name: config
hostPath:
path: {{ .Values.volume.configFile.hostPath }}
type: File
{{- else }}
- name: config
configMap:
name: portabase-agent-config
items:
- key: config.json
path: config.json
{{- end }}
{{- end }}
+10
View File
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: portabase-agent-env
data:
EDGE_KEY: {{ .Values.env.EDGE_KEY | quote }}
TZ: {{ .Values.env.TZ | quote }}
POLLING: {{ .Values.env.POLLING | quote }}
APP_ENV: {{ .Values.env.APP_ENV | quote }}
LOG: {{ .Values.env.LOG | quote }}
+48
View File
@@ -0,0 +1,48 @@
replicaCount: 1
image:
repository: portabase/agent
tag: latest
pullPolicy: IfNotPresent
env:
EDGE_KEY: "your_edge_key_here"
TZ: "UTC"
POLLING: "5"
APP_ENV: "production"
LOG: "info"
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 250m
memory: 256Mi
volume:
configFile:
enabled: true
hostPath: "" # Use host file if set, otherwise use `content`
content: | # JSON content for config.json if no hostPath
{
"databases": [
{
"name": "my-site-prod (readable name)",
"database": "devdb",
"type": "postgresql",
"host": "localhost",
"port": 5432,
"username": "admin_prod",
"password": "super_secure_password",
"generated_id": "550e8400-e29b-41d4-a716-446655440000"
}
]
}
network:
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "localhost"
-99
View File
@@ -1,99 +0,0 @@
#!/bin/bash
set -e
if [ -z "$1" ]; then
echo "Usage: ./release <version>"
echo "Example: ./release v1.0.0"
exit 1
fi
VERSION=$1
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" = "main" ]; then
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: On 'main' branch, only release tags (X.Y.Z) are allowed."
exit 1
fi
else
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+$ ]]; then
echo "Error: On branch '$CURRENT_BRANCH', only RC tags matching X.Y.Z-rc.W are allowed (e.g., 1.0.0-rc.1)."
exit 1
fi
fi
CLEAN_VERSION=${VERSION#v}
CURRENT_DATE=$(date +%Y-%m-%d)
echo "Preparing release $VERSION..."
# package.json
if [ -f package.json ]; then
echo "Updating package.json..."
if sed --version >/dev/null 2>&1; then
sed -i "s/\"version\": \".*\"/\"version\": \"$CLEAN_VERSION\"/" package.json
else
sed -i '' "s/\"version\": \".*\"/\"version\": \"$CLEAN_VERSION\"/" package.json
fi
fi
# pyproject.toml
if [ -f pyproject.toml ]; then
echo "Updating pyproject.toml..."
if sed --version >/dev/null 2>&1; then
sed -i "s/^version = \".*\"/version = \"$CLEAN_VERSION\"/" pyproject.toml
else
sed -i '' "s/^version = \".*\"/version = \"$CLEAN_VERSION\"/" pyproject.toml
fi
fi
# Cargo.toml
if [ -f Cargo.toml ]; then
echo "Updating Cargo.toml..."
if sed --version >/dev/null 2>&1; then
sed -i "s/^version = \".*\"/version = \"$CLEAN_VERSION\"/" Cargo.toml
else
sed -i '' "s/^version = \".*\"/version = \"$CLEAN_VERSION\"/" Cargo.toml
fi
fi
# CITATION.cff
if [ -f CITATION.cff ]; then
echo "Updating CITATION.cff..."
if sed --version >/dev/null 2>&1; then
sed -i "s/^version: .*/version: $CLEAN_VERSION/" CITATION.cff
sed -i "s/^date-released: .*/date-released: \"$CURRENT_DATE\"/" CITATION.cff
else
sed -i '' "s/^version: .*/version: $CLEAN_VERSION/" CITATION.cff
sed -i '' "s/^date-released: .*/date-released: \"$CURRENT_DATE\"/" CITATION.cff
fi
fi
git add .
if ! git diff-index --quiet HEAD --; then
echo "Committing changes..."
git commit -m "chore(release): $VERSION"
else
echo "No changes to commit. Proceeding to tag..."
fi
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "Tag $VERSION already exists. Aborting."
exit 1
fi
echo "Creating tag $VERSION..."
git tag -a "$VERSION" -m "Release $VERSION"
echo "Pushing changes and tags to remote..."
git push
git push origin "$VERSION"
echo "Successfully released $VERSION!"
+16 -2
View File
@@ -1,12 +1,26 @@
# Seed instructions
## MongoDB
```bash
make seed-mongo
make seed-mongo-auth
make seed-mysql
make seed-mysql-1gb
make seed-postgres
make seed-postgres-1gb
make seed-all
make seed-all
make seed-sqlite
make seed-sqlite SEED=big
```
## Verify commands
### Sqlite
```bash
docker exec -it db-sqlite sqlite3 /workspace/data/app.db "SELECT * FROM users LIMIT 10;"
```
```bash
docker exec -it db-sqlite sqlite3 /workspace/data/app.db "SELECT name FROM sqlite_master WHERE type='table';"
```
+53
View File
@@ -0,0 +1,53 @@
CREATE DATABASE IF NOT EXISTS mariadb;
USE mariadb;
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS products;
CREATE TABLE users (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;
CREATE TABLE products (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description MEDIUMTEXT,
price DECIMAL(10,2) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;
DELIMITER $$
DROP PROCEDURE IF EXISTS seed_data$$
CREATE PROCEDURE seed_data()
BEGIN
DECLARE i BIGINT DEFAULT 1;
DECLARE j BIGINT;
DECLARE large_text TEXT;
SET large_text = REPEAT('Lorem ipsum dolor sit amet, consectetur adipiscing elit. ', 300);
WHILE i <= 200000 DO
INSERT INTO users (username, email, password)
VALUES (CONCAT('user', i), CONCAT('user', i, '@example.com'), 'changeme');
SET i = i + 1;
END WHILE;
SET i = 1;
WHILE i <= 200000 DO
INSERT INTO products (name, description, price)
VALUES (CONCAT('Product ', i), large_text, ROUND(RAND()*1000,2));
SET i = i + 1;
END WHILE;
END$$
DELIMITER ;
CALL seed_data();
DROP PROCEDURE IF EXISTS seed_data;
+1 -1
View File
@@ -60,7 +60,7 @@ SELECT
)
FROM users u
JOIN generate_series(1, 30) AS p(post_no)
ON u.id <= 300000;
ON u.id <= 500000;
-- ============================================================
-- OPTIONAL: FORCE DISK MATERIALIZATION
+74
View File
@@ -0,0 +1,74 @@
PRAGMA foreign_keys = ON;
BEGIN TRANSACTION;
-- Drop tables
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS projects;
DROP TABLE IF EXISTS tasks;
-- Users
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email TEXT NOT NULL UNIQUE,
full_name TEXT NOT NULL,
role TEXT NOT NULL CHECK (role IN ('admin','manager','user')),
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
-- Projects
CREATE TABLE projects (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT,
owner_id INTEGER NOT NULL,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Tasks
CREATE TABLE tasks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER NOT NULL,
title TEXT NOT NULL,
status TEXT NOT NULL CHECK (status IN ('todo','in_progress','done')),
priority INTEGER NOT NULL DEFAULT 3,
due_date TEXT,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
);
-- Seed minimal users
INSERT INTO users (email, full_name, role) VALUES
('admin@example.com', 'System Admin', 'admin'),
('manager@example.com', 'Project Manager', 'manager'),
('user@example.com', 'Standard User', 'user');
-- Generate 10_000 projects
WITH RECURSIVE numbers(x) AS (
SELECT 1
UNION ALL
SELECT x+1 FROM numbers WHERE x<10000
)
INSERT INTO projects (name, description, owner_id)
SELECT
'Project #' || x,
'Auto-generated project description for project #' || x,
(1 + (x % 3)) -- cycle users 1..3
FROM numbers;
-- Generate 100_000 tasks
WITH RECURSIVE numbers(x) AS (
SELECT 1
UNION ALL
SELECT x+1 FROM numbers WHERE x<100000
)
INSERT INTO tasks (project_id, title, status, priority, due_date)
SELECT
(1 + (x % 10000)), -- project id cycle
'Task #' || x,
CASE (x % 3) WHEN 0 THEN 'todo' WHEN 1 THEN 'in_progress' ELSE 'done' END,
1 + (x % 5),
date('now', '+' || (x % 30) || ' days')
FROM numbers;
COMMIT;
+59
View File
@@ -0,0 +1,59 @@
PRAGMA foreign_keys = ON;
BEGIN TRANSACTION;
-- Drop existing tables (idempotent reset)
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS projects;
DROP TABLE IF EXISTS tasks;
-- Users
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email TEXT NOT NULL UNIQUE,
full_name TEXT NOT NULL,
role TEXT NOT NULL CHECK (role IN ('admin','manager','user')),
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
-- Projects
CREATE TABLE projects (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT,
owner_id INTEGER NOT NULL,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Tasks
CREATE TABLE tasks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER NOT NULL,
title TEXT NOT NULL,
status TEXT NOT NULL CHECK (status IN ('todo','in_progress','done')),
priority INTEGER NOT NULL DEFAULT 3,
due_date TEXT,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
);
-- Seed users
INSERT INTO users (email, full_name, role) VALUES
('admin@example.com', 'System Admin', 'admin'),
('manager@example.com', 'Project Manager', 'manager'),
('user@example.com', 'Standard User', 'user');
-- Seed projects
INSERT INTO projects (name, description, owner_id) VALUES
('Internal Tooling', 'Backoffice automation platform', 2),
('Client Portal', 'Customer-facing SaaS interface', 2);
-- Seed tasks
INSERT INTO tasks (project_id, title, status, priority, due_date) VALUES
(1, 'Define architecture', 'done', 1, date('now', '+3 days')),
(1, 'Implement authentication', 'in_progress', 1, date('now', '+7 days')),
(2, 'Design landing page', 'todo', 2, date('now', '+5 days')),
(2, 'Setup CI/CD', 'todo', 2, date('now', '+10 days'));
COMMIT;
Binary file not shown.
+1 -1
View File
@@ -52,7 +52,7 @@ impl Agent {
if db.data.backup.action {
let _ = self
.backup_service
.dispatch(&db.generated_id, &config, method.clone())
.dispatch(&db.generated_id, &config, method.clone(), &db.storages, db.encrypt)
.await;
} else if db.data.restore.action {
let _ = self
+9 -1
View File
@@ -1,3 +1,4 @@
use crate::services::api::ApiClient;
use crate::settings::CONFIG;
use crate::utils::edge_key::{EdgeKey, EdgeKeyError, decode_edge_key};
use tracing::{debug, error, info};
@@ -6,6 +7,7 @@ use tracing::{debug, error, info};
pub struct Context {
#[allow(dead_code)]
pub edge_key: EdgeKey,
pub api: ApiClient,
}
impl Context {
@@ -33,7 +35,13 @@ impl Context {
panic!("Cannot initialize AgentContext due to invalid EDGE_KEY");
}
};
let server_url = format!("{}/api", edge_key.server_url);
let api_client = ApiClient::new(server_url);
Context { edge_key }
Context {
edge_key: edge_key,
api: api_client,
}
}
}
+3
View File
@@ -6,6 +6,7 @@ use crate::services::config::{DatabaseConfig, DbType};
use anyhow::Result;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use crate::domain::sqlite::database::SqliteDatabase;
#[async_trait::async_trait]
pub trait Database: Send + Sync {
@@ -27,6 +28,7 @@ impl DatabaseFactory {
DbType::Mysql => Arc::new(MySQLDatabase::new(cfg)),
DbType::Mariadb => Arc::new(MySQLDatabase::new(cfg)),
DbType::MongoDB => Arc::new(MongoDatabase::new(cfg)),
DbType::Sqlite => Arc::new(SqliteDatabase::new(cfg)),
}
}
@@ -39,6 +41,7 @@ impl DatabaseFactory {
DbType::Mysql => Arc::new(MySQLDatabase::new(cfg)),
DbType::Mariadb => Arc::new(MySQLDatabase::new(cfg)),
DbType::MongoDB => Arc::new(MongoDatabase::new(cfg)),
DbType::Sqlite => Arc::new(SqliteDatabase::new(cfg)),
}
}
}
+1
View File
@@ -2,4 +2,5 @@ pub mod factory;
pub mod postgres;
pub mod mysql;
mod mongodb;
mod sqlite;
+1 -1
View File
@@ -15,7 +15,7 @@ pub async fn run(
let file_path = backup_dir.join(format!("{}{}", cfg.generated_id, file_extension));
let mongodump = select_mongo_path().join("mongodump");
let uri = get_mongo_uri(cfg.clone());
let uri = get_mongo_uri(cfg.clone())?;
let output = Command::new(mongodump)
.arg(format!("--uri={}", uri))
+8 -6
View File
@@ -3,7 +3,7 @@ use anyhow::Result;
use mongodb::Client;
pub async fn connect(cfg: DatabaseConfig) -> Result<Client> {
let uri = get_mongo_uri(cfg);
let uri = get_mongo_uri(cfg)?;
let mut options = mongodb::options::ClientOptions::parse(&uri).await?;
options.server_selection_timeout = Some(std::time::Duration::from_secs(3));
options.connect_timeout = Some(std::time::Duration::from_secs(3));
@@ -15,14 +15,16 @@ pub fn select_mongo_path() -> std::path::PathBuf {
"/usr/local/mongodb/bin".to_string().into()
}
pub fn get_mongo_uri(cfg: DatabaseConfig) -> String {
if cfg.username.is_empty() {
format!("mongodb://{}:{}/{}", cfg.host, cfg.port, cfg.database)
pub fn get_mongo_uri(cfg: DatabaseConfig) -> Result<String> {
if cfg.username.is_empty() || cfg.password.is_empty() {
Ok(format!("mongodb://{}:{}/{}", cfg.host, cfg.port, cfg.database))
} else {
format!(
Ok(format!(
"mongodb://{}:{}@{}:{}/{}?authSource=admin",
cfg.username, cfg.password, cfg.host, cfg.port, cfg.database
)
))
}
}
+9 -3
View File
@@ -1,14 +1,20 @@
#![allow(dead_code)]
use crate::domain::mongodb::connection::connect;
use crate::services::config::DatabaseConfig;
use anyhow::Result;
use mongodb::bson::doc;
use tracing::{error};
use crate::domain::mongodb::connection::connect;
use tracing::error;
pub async fn run(cfg: DatabaseConfig) -> Result<bool> {
let client = connect(cfg.clone()).await?;
let db_name = if cfg.username.is_empty() { &cfg.database } else { "admin" };
let db_name = if cfg.username.is_empty() && cfg.password.is_empty() {
&cfg.database
} else {
"admin"
};
match client.database(db_name).run_command(doc! {"ping": 1}).await {
Ok(_) => Ok(true),
Err(e) => {
+1 -1
View File
@@ -10,7 +10,7 @@ pub async fn run(cfg: DatabaseConfig, restore_file: PathBuf) -> Result<()> {
debug!("Starting MongoDB restore for database {}", cfg.name);
let mongorestore = select_mongo_path().join("mongorestore");
let uri = get_mongo_uri(cfg.clone());
let uri = get_mongo_uri(cfg.clone())?;
let output = Command::new(mongorestore)
.arg(format!("--uri={}", uri))
+1 -1
View File
@@ -1,4 +1,4 @@
use crate::domain::mysql::connection::server_version;
use crate::domain::mysql::connection::{server_version};
use crate::services::config::DatabaseConfig;
use anyhow::{Context, Result};
use std::collections::HashMap;
+2
View File
@@ -3,6 +3,7 @@ use std::process::Command;
use anyhow::Result;
pub async fn server_version(cfg: &DatabaseConfig) -> Result<String> {
let output = Command::new("mysql")
.arg("--host").arg(&cfg.host)
.arg("--port").arg(cfg.port.to_string())
@@ -25,3 +26,4 @@ pub async fn server_version(cfg: &DatabaseConfig) -> Result<String> {
Ok(version)
}
+1 -1
View File
@@ -21,7 +21,7 @@ impl MySQLDatabase {
fn build_env(&self) -> HashMap<String, String> {
let mut envs = std::env::vars().collect::<HashMap<_, _>>();
envs.insert("MYSQL_PWD".to_string(), self.cfg.password.clone());
envs.insert("MYSQL_PWD".to_string(), self.cfg.password.to_string());
envs
}
}
+16 -8
View File
@@ -1,19 +1,27 @@
use crate::services::config::DatabaseConfig;
use anyhow::Context;
use std::collections::HashMap;
use std::process::Command;
use tokio::process::Command;
use tokio::time::{Duration, timeout};
pub async fn run(cfg: DatabaseConfig, env: HashMap<String, String>) -> anyhow::Result<bool> {
let output = Command::new("mysqladmin")
.arg("--host")
let mut cmd = Command::new("mysqladmin");
cmd.arg("--host")
.arg(cfg.host)
.arg("--port")
.arg(cfg.port.to_string())
.arg("--user")
.arg(cfg.username)
.arg("ping")
.envs(env)
.output()
.with_context(|| format!("Failed to ping MySQL server {}", cfg.name))?;
Ok(output.status.success())
.envs(env);
let result = timeout(Duration::from_secs(10), cmd.output()).await;
match result {
Ok(output) => {
let output = output?;
Ok(output.status.success())
}
Err(_) => Ok(false),
}
}
+6 -7
View File
@@ -1,11 +1,10 @@
use crate::services::config::DatabaseConfig;
use anyhow::{Context, Result};
use std::fs::File;
use std::io::{Read, Write};
use anyhow::{Context, Result};
use tracing::{debug, error, info};
use std::path::PathBuf;
use std::process::Command;
use crate::services::config::DatabaseConfig;
use tracing::{debug, error, info};
pub async fn run(cfg: DatabaseConfig, restore_file: PathBuf) -> Result<()> {
let handle = tokio::task::spawn_blocking(move || -> Result<()> {
@@ -55,7 +54,8 @@ pub async fn run(cfg: DatabaseConfig, restore_file: PathBuf) -> Result<()> {
.with_context(|| format!("Failed to start mysql restore for {}", cfg.name))?;
let mut stdin = child.stdin.take().context("Failed to open child stdin")?;
stdin.write_all(sql_content.as_bytes())
stdin
.write_all(sql_content.as_bytes())
.context("Failed to write SQL content to mysql stdin")?;
stdin.flush()?;
drop(stdin);
@@ -74,8 +74,7 @@ pub async fn run(cfg: DatabaseConfig, restore_file: PathBuf) -> Result<()> {
Ok(())
});
handle
.await??;
handle.await??;
Ok(())
}
+1 -1
View File
@@ -1,7 +1,7 @@
use anyhow::Result;
use tracing::{debug, error, info};
use std::path::PathBuf;
use std::process::Command;
use tracing::{debug, error, info};
use super::connection::{select_pg_path, server_version};
use super::format::PostgresDumpFormat;
+5 -4
View File
@@ -1,11 +1,12 @@
use std::path::Path;
use crate::domain::postgres::format::PostgresDumpFormat;
use crate::services::config::DatabaseConfig;
use anyhow::Result;
use std::path::Path;
use tokio_postgres::{Client, NoTls};
use tracing::info;
use tracing::{error, info};
pub async fn connect(cfg: &DatabaseConfig) -> Result<Client> {
info!("Connecting to postgres database {}:{}", cfg.host, cfg.port);
let dsn = format!(
"host={} port={} user={} password={} dbname={}",
cfg.host, cfg.port, cfg.username, cfg.password, cfg.database
@@ -14,7 +15,7 @@ pub async fn connect(cfg: &DatabaseConfig) -> Result<Client> {
let (client, connection) = tokio_postgres::connect(&dsn, NoTls).await?;
tokio::spawn(async move {
if let Err(e) = connection.await {
tracing::error!("Postgres connection error: {}", e);
error!("Postgres connection error: {}", e);
}
});
Ok(client)
@@ -34,7 +35,7 @@ pub fn select_pg_path(version: &str) -> std::path::PathBuf {
pub async fn terminate_connections(cfg: &DatabaseConfig) -> Result<()> {
let mut admin = cfg.clone();
admin.database = "postgres".into();
admin.database = "postgres".to_string().into();
let client = connect(&admin).await?;
-2
View File
@@ -28,7 +28,6 @@ impl Database for PostgresDatabase {
match self.format {
PostgresDumpFormat::Fc => ".dump",
PostgresDumpFormat::Fd => ".gz",
// PostgresDumpFormat::Fd => ".tar.gz",
}
}
@@ -40,7 +39,6 @@ impl Database for PostgresDatabase {
FileLock::acquire(&self.cfg.generated_id, DbOpLock::Backup.as_str()).await?;
let res = backup::run(self.cfg.clone(), self.format, dir.to_path_buf()).await;
FileLock::release(&self.cfg.generated_id).await?;
res
}
+5 -1
View File
@@ -1,7 +1,7 @@
use anyhow::Result;
use tracing::{debug, error, info};
use std::path::PathBuf;
use std::process::Command;
use tracing::{debug, error, info};
use super::connection::{select_pg_path, server_version, terminate_connections};
use super::format::PostgresDumpFormat;
@@ -14,6 +14,7 @@ pub async fn run(
) -> Result<()> {
tokio::task::spawn_blocking(move || -> Result<()> {
debug!("Starting restore for database {}", cfg.name);
let version = match futures::executor::block_on(server_version(&cfg)) {
Ok(v) => {
debug!("Postgres version detected: {}", v);
@@ -86,6 +87,8 @@ pub async fn run(
}
};
info!("tar_gz {:?}", tar_gz);
let dec = flate2::read::GzDecoder::new(tar_gz);
let mut archive = tar::Archive::new(dec);
@@ -106,6 +109,7 @@ pub async fn run(
}
debug!("Listing contents of temp dir: {}", tmp_dir.path().display());
for entry in std::fs::read_dir(tmp_dir.path())? {
if let Ok(entry) = entry {
let path = entry.path();
+45
View File
@@ -0,0 +1,45 @@
use crate::services::config::DatabaseConfig;
use anyhow::{Context, Result};
use std::path::PathBuf;
use std::process::Command;
use tracing::{debug, error, info};
pub async fn run(
cfg: DatabaseConfig,
backup_dir: PathBuf,
file_extension: &'static str,
) -> Result<PathBuf> {
tokio::task::spawn_blocking(move || -> Result<PathBuf> {
debug!("Starting SQLite backup for database {}", cfg.name);
let db_path_str = if cfg.path.is_empty() {
anyhow::bail!("Database path not configured");
} else {
cfg.path.as_str().to_string()
};
let db_path = PathBuf::from(db_path_str);
if !db_path.exists() {
anyhow::bail!("SQLite database file not found: {}", db_path.display());
}
let file_path = backup_dir.join(format!("{}{}", cfg.generated_id, file_extension));
let output = Command::new("sqlite3")
.arg(db_path.as_os_str())
.arg(format!(".backup '{}'", file_path.display()))
.output()
.context("SQLite backup command failed to start")?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
error!("SQLite backup failed for {}: {}", cfg.name, stderr);
anyhow::bail!("SQLite backup failed for {}: {}", cfg.name, stderr);
}
info!("SQLite backup completed for {}", cfg.name);
Ok(file_path)
})
.await?
}
+43
View File
@@ -0,0 +1,43 @@
use anyhow::Result;
use async_trait::async_trait;
use std::path::{Path, PathBuf};
use super::{backup, ping, restore};
use crate::domain::factory::Database;
use crate::services::config::DatabaseConfig;
use crate::utils::locks::{DbOpLock, FileLock};
pub struct SqliteDatabase {
cfg: DatabaseConfig,
}
impl SqliteDatabase {
pub fn new(cfg: DatabaseConfig) -> Self {
Self { cfg }
}
}
#[async_trait]
impl Database for SqliteDatabase {
fn file_extension(&self) -> &'static str {
".backup"
}
async fn ping(&self) -> Result<bool> {
ping::run(self.cfg.clone()).await
}
async fn backup(&self, dir: &Path) -> Result<PathBuf> {
FileLock::acquire(&self.cfg.generated_id, DbOpLock::Backup.as_str()).await?;
let res = backup::run(self.cfg.clone(), dir.to_path_buf(), self.file_extension()).await;
FileLock::release(&self.cfg.generated_id).await?;
res
}
async fn restore(&self, file: &Path) -> Result<()> {
FileLock::acquire(&self.cfg.generated_id, DbOpLock::Restore.as_str()).await?;
let res = restore::run(self.cfg.clone(), file.to_path_buf()).await;
FileLock::release(&self.cfg.generated_id).await?;
res
}
}
+4
View File
@@ -0,0 +1,4 @@
mod backup;
mod restore;
mod ping;
pub mod database;
+5
View File
@@ -0,0 +1,5 @@
use crate::services::config::DatabaseConfig;
pub async fn run(_cfg: DatabaseConfig) -> anyhow::Result<bool> {
Ok(true)
}
+44
View File
@@ -0,0 +1,44 @@
use crate::services::config::DatabaseConfig;
use anyhow::{Context, Result};
use std::path::PathBuf;
use std::process::Command;
use tracing::{debug, error, info};
pub async fn run(cfg: DatabaseConfig, restore_file: PathBuf) -> Result<()> {
tokio::task::spawn_blocking(move || -> Result<()> {
debug!("Starting SQLite restore for database {}", cfg.name);
let db_path_str = if cfg.path.is_empty() {
anyhow::bail!("Database path not configured");
} else {
cfg.path.as_str().to_string()
};
let db_path = PathBuf::from(db_path_str);
if !restore_file.exists() {
anyhow::bail!("Restore file not found: {}", restore_file.display());
}
if db_path.exists() {
std::fs::remove_file(&db_path)
.with_context(|| format!("Failed to remove existing DB {}", db_path.display()))?;
}
let output = Command::new("sqlite3")
.arg(db_path.as_os_str())
.arg(format!(".restore '{}'", restore_file.display()))
.output()
.with_context(|| format!("Failed to run sqlite3 restore for {}", cfg.name))?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
error!("SQLite restore failed for {}: {}", cfg.name, stderr);
anyhow::bail!("SQLite restore failed for {}", cfg.name);
}
info!("SQLite restore completed for {}", cfg.name);
Ok(())
})
.await?
}
+2
View File
@@ -4,6 +4,8 @@ mod services;
mod settings;
mod tasks;
mod utils;
#[cfg(test)]
mod tests;
use crate::tasks::ping::ping_server;
use crate::utils::locks::FileLock;
+83
View File
@@ -0,0 +1,83 @@
#![allow(dead_code)]
use reqwest::{Client, Method};
use serde::de::DeserializeOwned;
use std::time::Duration;
use crate::services::api::ApiError;
#[derive(Clone, Debug)]
pub struct ApiClient {
base_url: String,
http: Client,
}
impl ApiClient {
pub fn new(base_url: impl Into<String>) -> Self {
let http = Client::builder()
.timeout(Duration::from_secs(30))
.build()
.expect("failed to build http client");
Self {
base_url: base_url.into(),
http,
}
}
pub async fn request<T: DeserializeOwned>(
&self,
method: Method,
path: &str,
) -> Result<Option<T>, ApiError> {
let url = format!("{}{}", self.base_url, path);
let res = self.http.request(method, &url).send().await?;
let status = res.status();
let body = res.text().await.unwrap_or_default();
if !status.is_success() {
return Err(ApiError::HttpResponse { status, body });
}
if body.trim().is_empty() {
Ok(None)
} else {
Ok(Some(serde_json::from_str::<T>(&body)?))
}
}
pub async fn request_with_body<T, B>(
&self,
method: Method,
path: &str,
body: &B,
) -> Result<Option<T>, ApiError>
where
T: DeserializeOwned,
B: serde::Serialize,
{
let url = format!("{}{}", self.base_url, path);
let res = self
.http
.request(method, &url)
.json(body)
.send()
.await?;
let status = res.status();
let body_text = res.text().await.unwrap_or_default();
if !status.is_success() {
return Err(ApiError::HttpResponse {
status,
body: body_text,
});
}
if body_text.trim().is_empty() {
Ok(None)
} else {
Ok(Some(serde_json::from_str::<T>(&body_text)?))
}
}
}
@@ -0,0 +1,67 @@
pub mod upload;
use crate::services::api::models::agent::backup::BackupResponse;
use crate::services::api::{ApiClient, ApiError};
use anyhow::Result;
use reqwest::Method;
use serde::Serialize;
#[derive(Serialize)]
pub struct BackupCreateRequest {
pub method: String,
#[serde(rename = "generatedId")]
pub generated_id: String,
}
#[derive(Serialize)]
pub struct BackupUpdateRequest {
#[serde(rename = "backupId")]
pub backup_id: String,
pub status: String,
pub size: Option<u64>,
#[serde(rename = "generatedId")]
pub generated_id: String,
}
impl ApiClient {
pub async fn backup_create(
&self,
method: impl Into<String>,
agent_id: impl Into<String>,
generated_id: impl Into<String>,
) -> Result<Option<BackupResponse>, ApiError> {
let body = BackupCreateRequest {
method: method.into(),
generated_id: generated_id.into(),
};
let agent_id = agent_id.into();
let path = format!("/agent/{}/backup", agent_id);
self.request_with_body(Method::POST, path.as_str(), &body)
.await
}
pub async fn backup_update(
&self,
agent_id: impl Into<String>,
backup_id: impl Into<String>,
status: impl Into<String>,
file_size: impl Into<Option<u64>>,
generated_id: impl Into<String>,
) -> Result<Option<BackupResponse>, ApiError> {
let body = BackupUpdateRequest {
backup_id: backup_id.into(),
status: status.into(),
size: file_size.into(),
generated_id: generated_id.into(),
};
let agent_id = agent_id.into();
let path = format!("/agent/{}/backup", agent_id);
self.request_with_body(Method::PATCH, path.as_str(), &body)
.await
}
}
@@ -0,0 +1,37 @@
use crate::services::api::{ApiClient, ApiError};
use anyhow::Result;
use reqwest::Method;
use serde::Serialize;
use crate::services::api::models::agent::backup::BackupUploadResponse;
#[derive(Serialize)]
pub struct InitUploadRequest {
#[serde(rename = "generatedId")]
pub generated_id: String,
#[serde(rename = "storageChannelId")]
pub storage_channel_id: String,
#[serde(rename = "backupId")]
pub backup_id: String,
}
impl ApiClient {
pub async fn backup_upload_init(
&self,
agent_id: impl Into<String>,
generated_id: impl Into<String>,
storage_channel_id: impl Into<String>,
backup_id: impl Into<String>,
) -> Result<Option<BackupUploadResponse>, ApiError> {
let body = InitUploadRequest {
generated_id: generated_id.into(),
storage_channel_id: storage_channel_id.into(),
backup_id: backup_id.into(),
};
let agent_id = agent_id.into();
let path = format!("/agent/{}/backup/upload/init", agent_id);
self.request_with_body(Method::POST, path.as_str(), &body)
.await
}
}
@@ -0,0 +1,2 @@
pub mod init;
pub mod status;
@@ -0,0 +1,46 @@
use crate::services::api::models::agent::backup::BackupUploadResponse;
use crate::services::api::{ApiClient, ApiError};
use anyhow::Result;
use reqwest::Method;
use serde::Serialize;
#[derive(Serialize)]
pub struct StatusUploadRequest {
#[serde(rename = "generatedId")]
pub generated_id: String,
#[serde(rename = "backupStorageId")]
pub backup_storage_id: String,
pub status: String,
pub path: String,
pub size: u64,
#[serde(rename = "backupId")]
pub backup_id: String,
}
impl ApiClient {
pub async fn backup_upload_status(
&self,
agent_id: impl Into<String>,
generated_id: impl Into<String>,
backup_storage_id: impl Into<String>,
status: impl Into<String>,
remote_path: impl Into<String>,
total_size: impl Into<u64>,
backup_id: impl Into<String>,
) -> Result<Option<BackupUploadResponse>, ApiError> {
let body = StatusUploadRequest {
generated_id: generated_id.into(),
backup_storage_id: backup_storage_id.into(),
status: status.into(),
path: remote_path.into(),
size: total_size.into(),
backup_id: backup_id.into(),
};
let agent_id = agent_id.into();
let path = format!("/agent/{}/backup/upload/status", agent_id);
self.request_with_body(Method::PATCH, path.as_str(), &body)
.await
}
}
+3
View File
@@ -0,0 +1,3 @@
pub mod status;
pub mod backup;
pub mod restore;
@@ -0,0 +1,33 @@
use crate::services::api::models::agent::restore::ResultRestoreResponse;
use crate::services::api::{ApiClient, ApiError};
use anyhow::Result;
use reqwest::Method;
use serde::Serialize;
#[derive(Serialize)]
pub struct ResultRestoreRequest {
#[serde(rename = "generatedId")]
pub generated_id: String,
pub status: String,
}
impl ApiClient {
pub async fn restore_result(
&self,
agent_id: impl Into<String>,
generated_id: impl Into<String>,
status: impl Into<String>,
) -> Result<Option<ResultRestoreResponse>, ApiError> {
let body = ResultRestoreRequest {
generated_id: generated_id.into(),
status: status.into(),
};
let agent_id = agent_id.into();
let path = format!("/agent/{}/restore", agent_id);
self.request_with_body(Method::POST, path.as_str(), &body)
.await
}
}
@@ -0,0 +1,36 @@
use crate::services::api::models::agent;
use crate::services::api::{ApiClient, ApiError};
use agent::status::PingResult;
use anyhow::Result;
use reqwest::Method;
use serde::Serialize;
#[derive(Serialize)]
pub struct DatabasePayload<'a> {
pub name: &'a str,
pub dbms: &'a str,
#[serde(rename = "generatedId")]
pub generated_id: &'a str,
}
#[derive(Serialize)]
pub struct StatusRequest<'a> {
pub version: &'a str,
pub databases: Vec<DatabasePayload<'a>>,
}
impl ApiClient {
pub async fn agent_status<'a>(
&self,
agent_id: impl Into<String>,
version: &'a str,
databases: Vec<DatabasePayload<'a>>,
) -> Result<Option<PingResult>, ApiError> {
let body = StatusRequest { version, databases };
let agent_id = agent_id.into();
let path = format!("/agent/{}/status", agent_id);
self.request_with_body(Method::POST, path.as_str(), &body).await
}
}
+3
View File
@@ -0,0 +1,3 @@
pub mod agent;
pub use agent::status;
+21
View File
@@ -0,0 +1,21 @@
use reqwest::StatusCode;
use thiserror::Error;
#[derive(Debug, Error)]
#[allow(dead_code)]
pub enum ApiError {
#[error("http client error: {0}")]
Http(#[from] reqwest::Error),
#[error("serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("api error: status={status}, body={body}")]
HttpResponse {
status: StatusCode,
body: String,
},
#[error("api returned unexpected response")]
UnexpectedResponse,
}
+8
View File
@@ -0,0 +1,8 @@
pub mod client;
pub mod error;
pub mod models;
pub mod endpoints;
pub use client::ApiClient;
pub use error::ApiError;
+24
View File
@@ -0,0 +1,24 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct BackupStorage {
pub id: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BackupUploadResponse {
pub message: String,
#[serde(rename = "backupStorage")]
pub backup_storage: BackupStorage,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct Backup {
pub id: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BackupResponse {
pub message: String,
pub backup: Backup,
}
+3
View File
@@ -0,0 +1,3 @@
pub mod status;
pub mod backup;
pub mod restore;
+7
View File
@@ -0,0 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct ResultRestoreResponse {
pub message: String,
pub status: bool,
}
+57
View File
@@ -0,0 +1,57 @@
#![allow(dead_code)]
use serde::{Deserialize, Serialize};
use toml::Value;
use crate::utils::deserializer::deserialize_snake_case;
#[derive(Debug, Deserialize)]
pub struct PingResult {
pub agent: AgentInfo,
pub databases: Vec<DatabaseStatus>,
}
#[derive(Debug, Deserialize)]
pub struct AgentInfo {
pub id: String,
#[serde(rename = "lastContact")]
pub last_contact: String,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "snake_case")]
pub struct DatabaseStorage {
pub id: String,
#[serde(deserialize_with = "deserialize_snake_case")]
pub config: Value,
pub provider: String,
}
#[derive(Debug, Deserialize)]
pub struct DatabaseStatus {
pub dbms: String,
#[serde(rename = "generatedId")]
pub generated_id: String,
pub storages: Vec<DatabaseStorage>,
pub encrypt: bool,
pub data: DatabaseData,
}
#[derive(Debug, Deserialize)]
pub struct DatabaseData {
pub backup: BackupInfo,
pub restore: RestoreInfo,
}
#[derive(Debug, Deserialize)]
pub struct BackupInfo {
pub action: bool,
pub cron: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct RestoreInfo {
pub action: bool,
pub file: Option<String>,
#[serde(rename = "metaFile")]
pub meta_file: Option<String>,
}
+2
View File
@@ -0,0 +1,2 @@
pub mod agent;
-219
View File
@@ -1,219 +0,0 @@
#![allow(dead_code)]
use crate::core::context::Context;
use crate::domain::factory::DatabaseFactory;
use crate::services::config::{DatabaseConfig, DatabasesConfig, DbType};
use crate::utils::common::BackupMethod;
use crate::utils::file::full_extension;
use anyhow::Result;
use hex;
use openssl::encrypt::Encrypter;
use openssl::hash::MessageDigest;
use openssl::pkey::PKey;
use openssl::rand::rand_bytes;
use openssl::rsa::Padding;
use openssl::symm::{Cipher, Crypter, Mode};
use reqwest::multipart::{Form, Part};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use tempfile::TempDir;
use tokio::fs;
use tracing::{error, info};
#[derive(Debug)]
pub struct BackupResult {
pub generated_id: String,
pub db_type: DbType,
pub status: String,
pub backup_file: Option<PathBuf>,
pub code: Option<String>,
}
pub struct BackupService {
ctx: Arc<Context>,
}
impl BackupService {
pub fn new(ctx: Arc<Context>) -> Self {
Self { ctx }
}
pub async fn dispatch(
&self,
generated_id: &String,
config: &DatabasesConfig,
method: BackupMethod,
) {
if let Some(cfg) = config
.databases
.iter()
.find(|c| c.generated_id == generated_id.as_str())
{
let db_cfg = cfg.clone();
let ctx_clone = self.ctx.clone();
tokio::spawn(async move {
match TempDir::new() {
Ok(temp_dir) => {
let tmp_path = temp_dir.path().to_path_buf();
info!("Created temp directory {}", tmp_path.display());
match BackupService::run(db_cfg, &tmp_path).await {
Ok(result) => {
let service = BackupService { ctx: ctx_clone };
service.send_result(result, method).await;
}
Err(e) => error!("Backup error {}", e),
}
// TempDir is automatically deleted when dropped here
}
Err(e) => error!("Failed to create temp dir: {}", e),
}
});
}
}
pub async fn run(cfg: DatabaseConfig, tmp_path: &Path) -> Result<BackupResult> {
let db_instance = DatabaseFactory::create_for_backup(cfg.clone()).await;
let generated_id = cfg.generated_id.clone();
let db_type = cfg.db_type.clone();
let reachable = db_instance.ping().await.unwrap_or(false);
info!("Reachable: {}", reachable);
if !reachable {
return Ok(BackupResult {
generated_id,
db_type,
status: "failed".into(),
backup_file: None,
code: None,
});
}
match db_instance.backup(tmp_path).await {
Ok(file) => Ok(BackupResult {
generated_id,
db_type,
status: "success".into(),
backup_file: Some(file),
code: None,
}),
Err(e) => match e.to_string().as_str() {
"backup_already_in_progress" => Ok(BackupResult {
generated_id,
db_type,
status: "failed".into(),
backup_file: None,
code: Some(e.to_string()),
}),
_ => Ok(BackupResult {
generated_id,
db_type,
status: "failed".into(),
backup_file: None,
code: None,
}),
},
}
}
pub async fn send_result(&self, result: BackupResult, method: BackupMethod) {
if result.code.as_deref() == Some("backup_already_in_progress") {
info!(
"[BackupService] Skipping send for DB {}: backup already in progress",
result.generated_id
);
return;
}
info!(
"[BackupService] DB: {} Type: {} Status: {} File: {:?}",
result.generated_id,
result.db_type.as_str(),
result.status,
result.backup_file
);
let client = reqwest::Client::new();
let url = format!(
"{}/api/agent/{}/backup",
self.ctx.edge_key.server_url, self.ctx.edge_key.agent_id
);
let mut form = Form::new()
.text("generatedId", result.generated_id.clone())
.text("status", result.status.clone())
.text("method", method.to_string());
if let Some(file_path) = result.backup_file {
match fs::read(&file_path).await {
Ok(raw_data) => {
// AES key + IV
let mut aes_key = [0u8; 32];
rand_bytes(&mut aes_key).unwrap();
let mut iv = [0u8; 16];
rand_bytes(&mut iv).unwrap();
// AES CBC PKCS7 encryption
let cipher = Cipher::aes_256_cbc();
let mut encrypter =
Crypter::new(cipher, Mode::Encrypt, &aes_key, Some(&iv)).unwrap();
encrypter.pad(true);
let mut encrypted = vec![0u8; raw_data.len() + cipher.block_size()];
let count = encrypter.update(&raw_data, &mut encrypted).unwrap();
let rest = encrypter.finalize(&mut encrypted[count..]).unwrap();
encrypted.truncate(count + rest);
// Encrypt AES key with RSA public key
let pub_key_pem = self.ctx.edge_key.public_key.as_bytes();
let pkey = PKey::public_key_from_pem(pub_key_pem).unwrap();
let mut encrypter = Encrypter::new(&pkey).unwrap();
// Set OAEP padding (default OAEP uses SHA1, so override)
encrypter.set_rsa_padding(Padding::PKCS1_OAEP).unwrap();
// Set OAEP hash to SHA256
encrypter.set_rsa_oaep_md(MessageDigest::sha256()).unwrap();
encrypter.set_rsa_mgf1_md(MessageDigest::sha256()).unwrap();
let mut encrypted_key = vec![0u8; encrypter.encrypt_len(&aes_key).unwrap()];
let encrypted_len = encrypter.encrypt(&aes_key, &mut encrypted_key).unwrap();
encrypted_key.truncate(encrypted_len);
let extension = full_extension(&file_path);
// Attach file and AES info to multipart form
form = form
.part(
"file",
Part::bytes(encrypted)
.file_name(format!("{}.enc", result.generated_id)),
)
.text("aes_key", hex::encode(encrypted_key))
.text("iv", hex::encode(iv))
.text("extension", extension);
}
Err(e) => {
error!("Failed to read backup file: {}", e);
}
}
} else {
form = form.text("file", "");
}
match client.post(&url).multipart(form).send().await {
Ok(resp) => {
let status = resp.status();
if status.is_success() {
info!("Backup result sent successfully");
} else {
let text = resp.text().await.unwrap_or_default(); // consumes resp
error!("Backup result failed, status: {}, body: {}", status, text);
}
}
Err(e) => {
error!("Failed to send backup result: {}", e);
}
}
}
}
+20
View File
@@ -0,0 +1,20 @@
use super::service::BackupService;
use crate::utils::compress::compress_to_tar_gz_large;
use std::path::PathBuf;
use anyhow::Result;
impl BackupService {
pub async fn compress_backup(
&self,
backup_file: Option<PathBuf>,
) -> Result<PathBuf> {
let file = backup_file
.ok_or_else(|| anyhow::anyhow!("No backup file generated"))?;
let compression = compress_to_tar_gz_large(&file).await?;
Ok(compression.compressed_path)
}
}
+44
View File
@@ -0,0 +1,44 @@
use super::service::BackupService;
use crate::services::config::DatabasesConfig;
use crate::services::api::models::agent::status::DatabaseStorage;
use crate::utils::common::BackupMethod;
use tracing::error;
impl BackupService {
pub async fn dispatch(
&self,
generated_id: &String,
config: &DatabasesConfig,
method: BackupMethod,
storages: &Vec<DatabaseStorage>,
encrypt: bool,
) {
let Some(cfg) = config
.databases
.iter()
.find(|c| c.generated_id == generated_id.as_str())
else {
error!("Database config not found for {}", generated_id);
return;
};
let service = Self {
ctx: self.ctx.clone(),
};
let db_cfg = cfg.clone();
let storages = storages.clone();
let generated_id = generated_id.clone();
tokio::spawn(async move {
if let Err(e) = service
.execute_backup(generated_id, db_cfg, method, storages, encrypt)
.await
{
error!("Backup execution failed: {}", e);
}
});
}
}
+49
View File
@@ -0,0 +1,49 @@
use super::service::BackupService;
use crate::services::config::DatabaseConfig;
use crate::services::api::models::agent::status::DatabaseStorage;
use crate::utils::common::BackupMethod;
use crate::utils::locks::FileLock;
use tempfile::TempDir;
use anyhow::Result;
impl BackupService {
pub async fn execute_backup(
&self,
generated_id: String,
db_cfg: DatabaseConfig,
method: BackupMethod,
storages: Vec<DatabaseStorage>,
encrypt: bool,
) -> Result<()> {
if FileLock::is_locked(&generated_id).await? {
anyhow::bail!("backup already running");
}
let backup = self.create_backup_record(&generated_id, &method).await?;
let backup_id = backup.backup.id;
let temp_dir = TempDir::new()?;
let tmp_path = temp_dir.path();
let mut result = Self::run(db_cfg, tmp_path).await?;
if result.status == "failed" {
self.send_result(result, vec![], &backup_id).await?;
return Ok(());
}
let compressed = self.compress_backup(result.backup_file.take()).await?;
result.backup_file = Some(compressed);
let uploads = self
.upload(result.clone(), method, storages, encrypt, &backup_id)
.await?;
self.send_result(result, uploads, &backup_id).await?;
Ok(())
}
}
+26
View File
@@ -0,0 +1,26 @@
use super::service::BackupService;
use crate::utils::common::BackupMethod;
use anyhow::{Result, anyhow};
use crate::services::api::models::agent::backup::BackupResponse;
impl BackupService {
pub async fn create_backup_record(
&self,
generated_id: &str,
method: &BackupMethod,
) -> Result<BackupResponse> {
let response = self
.ctx
.api
.backup_create(
method.to_string(),
self.ctx.edge_key.agent_id.clone(),
generated_id,
)
.await?;
response.ok_or_else(|| anyhow!("backup_create returned empty response"))
}
}
+11
View File
@@ -0,0 +1,11 @@
pub mod service;
pub mod dispatcher;
pub mod executor;
pub mod compressor;
pub mod uploader;
pub mod result;
pub mod models;
pub mod helpers;
pub mod runner;
pub use service::BackupService;
+22
View File
@@ -0,0 +1,22 @@
#![allow(dead_code)]
use std::path::PathBuf;
use crate::services::config::DbType;
#[derive(Debug, Clone)]
pub struct BackupResult {
pub generated_id: String,
pub db_type: DbType,
pub status: String,
pub backup_file: Option<PathBuf>,
pub code: Option<String>,
}
#[derive(Debug)]
pub struct UploadResult {
pub storage_id: String,
pub success: bool,
pub error: Option<String>,
pub remote_file_path: Option<String>,
pub total_size: Option<u64>,
}
+45
View File
@@ -0,0 +1,45 @@
use super::models::{BackupResult, UploadResult};
use super::service::BackupService;
use crate::services::api::ApiError;
use crate::services::api::models::agent::backup::BackupResponse;
use anyhow::Result;
use tracing::error;
impl BackupService {
pub async fn send_result(
&self,
result: BackupResult,
upload_results: Vec<UploadResult>,
backup_id: &String,
) -> Result<Option<BackupResponse>, ApiError> {
let status = if upload_results.iter().any(|r| r.success) {
"success"
} else {
"failed"
};
let file_size = upload_results
.iter()
.filter_map(|r| r.total_size)
.reduce(|a, b| a + b)
.map(|sum| sum / upload_results.len() as u64);
self.ctx
.api
.backup_update(
self.ctx.edge_key.agent_id.clone(),
backup_id,
status,
file_size,
&result.generated_id,
)
.await
.map_err(|e| {
error!(
"backup_update failed (generated_id={}, backup_id={}): {}",
result.generated_id, backup_id, e
);
e.into()
})
}
}
+70
View File
@@ -0,0 +1,70 @@
use super::models::BackupResult;
use super::service::BackupService;
use crate::domain::factory::DatabaseFactory;
use crate::services::config::DatabaseConfig;
use anyhow::Result;
use std::path::Path;
use tracing::{error, info};
impl BackupService {
pub async fn run(
cfg: DatabaseConfig,
tmp_path: &Path,
) -> Result<BackupResult> {
let db = DatabaseFactory::create_for_backup(cfg.clone()).await;
let generated_id = cfg.generated_id.clone();
let db_type = cfg.db_type.clone();
let reachable = match db.ping().await {
Ok(v) => v,
Err(e) => {
error!("Ping failed: {}", e);
return Err(e.into());
}
};
info!("Reachable: {}", reachable);
if !reachable {
return Ok(BackupResult {
generated_id,
db_type,
status: "failed".into(),
backup_file: None,
code: None,
});
}
match db.backup(tmp_path).await {
Ok(file) => Ok(BackupResult {
generated_id,
db_type,
status: "success".into(),
backup_file: Some(file),
code: None,
}),
Err(e) if e.to_string() == "backup_already_in_progress" => Ok(BackupResult {
generated_id,
db_type,
status: "failed".into(),
backup_file: None,
code: Some("backup_already_in_progress".into()),
}),
Err(_) => Ok(BackupResult {
generated_id,
db_type,
status: "failed".into(),
backup_file: None,
code: None,
}),
}
}
}
+12
View File
@@ -0,0 +1,12 @@
use std::sync::Arc;
use crate::core::context::Context as CoreContext;
pub struct BackupService {
pub ctx: Arc<CoreContext>,
}
impl BackupService {
pub fn new(ctx: Arc<CoreContext>) -> Self {
Self { ctx }
}
}
+181
View File
@@ -0,0 +1,181 @@
use super::service::BackupService;
use super::models::{BackupResult, UploadResult};
use crate::services::storage;
use crate::services::api::models::agent::status::DatabaseStorage;
use crate::utils::common::BackupMethod;
use futures::future::join_all;
use anyhow::{Result, bail};
use tracing::{info, error};
impl BackupService {
pub async fn upload(
&self,
result: BackupResult,
method: BackupMethod,
storages: Vec<DatabaseStorage>,
encrypt: bool,
backup_id: &String,
) -> Result<Vec<UploadResult>> {
if result.code.as_deref() == Some("backup_already_in_progress") {
info!("Skipping send: backup already in progress");
bail!("backup_already_in_progress");
}
let ctx = self.ctx.clone();
let futures = storages.into_iter().map(|storage| {
let ctx_clone = ctx.clone();
let result_clone = result.clone();
let provider = storage::get_provider(&storage);
let storage_id = storage.id.clone();
let generated_id = result_clone.generated_id.clone();
async move {
info!("Uploading storage -> {:?} for {:?}", storage.provider, storage_id);
/*
INIT STEP
*/
let init = match ctx_clone.api
.backup_upload_init(
ctx_clone.edge_key.agent_id.clone(),
generated_id.clone(),
storage_id.clone(),
backup_id,
)
.await
{
Ok(v) => v,
Err(e) => {
error!("backup_upload_init failed: {}", e);
return UploadResult {
storage_id,
success: false,
error: Some("backup_upload_init failed".into()),
remote_file_path: None,
total_size: None,
};
}
};
let backup_storage_id = match init {
Some(v) => v.backup_storage.id,
None => {
return UploadResult {
storage_id,
success: false,
error: Some("backup_upload_init returned empty response".into()),
remote_file_path: None,
total_size: None,
};
}
};
/*
PROVIDER CHECK
*/
let Some(provider) = provider else {
error!("Skipping storage due to missing provider");
return UploadResult {
storage_id,
success: false,
error: Some("missing provider".into()),
remote_file_path: None,
total_size: None,
};
};
/*
STORAGE UPLOAD
*/
let upload_result = provider
.upload(
ctx_clone.clone(),
result_clone,
method,
&storage,
Some(encrypt),
)
.await;
let status = if upload_result.success { "success" } else { "failed" };
if status != "success" {
return upload_result;
}
info!(
"Storage {} uploaded to remote path {:?}",
storage_id,
upload_result.remote_file_path
);
/*
METADATA VALIDATION
*/
let (remote_path, total_size) = match (
&upload_result.remote_file_path,
upload_result.total_size,
) {
(Some(path), Some(size)) => (path.clone(), size),
_ => {
return UploadResult {
storage_id,
success: false,
error: Some("remote_file_path or total_size missing".into()),
remote_file_path: None,
total_size: None,
};
}
};
/*
STATUS UPDATE
*/
match ctx_clone.api.backup_upload_status(
ctx_clone.edge_key.agent_id.clone(),
generated_id,
backup_storage_id,
status,
remote_path,
total_size,
backup_id,
).await {
Ok(_) => upload_result,
Err(err) => {
error!(
"backup_upload_status failed (storage_id={}): {}",
storage_id,
err
);
UploadResult {
storage_id,
success: false,
error: Some(err.to_string()),
remote_file_path: None,
total_size: None,
}
}
}
}
});
let results: Vec<UploadResult> = join_all(futures).await;
info!("Upload results: {:#?}", results);
Ok(results)
}
}
+94 -6
View File
@@ -9,6 +9,7 @@ use std::path::Path;
use std::sync::Arc;
use toml;
use tracing::info;
use uuid::Uuid;
#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "lowercase")]
@@ -16,8 +17,8 @@ pub enum DbType {
Mysql,
Mariadb,
Postgresql,
MongoDB
// Sqlite,
MongoDB,
Sqlite,
// Add other DB types if needed
}
@@ -28,7 +29,7 @@ impl DbType {
DbType::Mariadb => "mysql",
DbType::Postgresql => "postgresql",
DbType::MongoDB => "mongodb",
// DbType::Sqlite => "sqlite",
DbType::Sqlite => "sqlite",
}
}
}
@@ -45,6 +46,7 @@ pub struct DatabaseConfig {
pub port: u16,
pub host: String,
pub generated_id: String,
pub path: String,
}
#[allow(dead_code)]
@@ -53,6 +55,29 @@ pub struct DatabasesConfig {
pub databases: Vec<DatabaseConfig>,
}
#[allow(dead_code)]
#[derive(Debug, Deserialize, Clone)]
pub struct InputDatabaseConfig {
pub name: String,
pub database: Option<String>,
#[serde(rename = "type")]
pub db_type: DbType,
pub username: Option<String>,
pub password: Option<String>,
pub port: Option<u16>,
pub host: Option<String>,
pub generated_id: String,
pub path: Option<String>,
}
#[allow(dead_code)]
#[derive(Debug, Deserialize, Clone)]
pub struct InputDatabasesConfig {
pub databases: Vec<InputDatabaseConfig>,
}
pub struct ConfigService {
ctx: Arc<Context>,
}
@@ -95,7 +120,7 @@ impl ConfigService {
file.read_to_string(&mut contents)
.map_err(|e| format!("Failed to read config file: {}", e))?;
let config: DatabasesConfig = match extension {
let input_config: InputDatabasesConfig = match extension {
"json" => {
serde_json::from_str(&contents).map_err(|e| format!("JSON parsing error: {}", e))?
}
@@ -105,8 +130,71 @@ impl ConfigService {
_ => return Err("Unsupported config file format. Use .json or .toml".to_string()),
};
info!("Databases : {:?} instances loaded", config.databases.len());
fn required<T: Clone>(opt: &Option<T>, db_name: &str, field_name: &str) -> Result<T, String> {
match opt {
Some(v) => Ok(v.clone()),
None => {
let msg = format!("Missing required field '{}' for database '{}'", field_name, db_name);
Err(msg)
}
}
}
Ok(config)
fn optional<T: Clone>(opt: &Option<T>) -> T where T: Default {
opt.clone().unwrap_or_default()
}
let mut databases = Vec::with_capacity(input_config.databases.len());
for db in input_config.databases {
if Uuid::parse_str(&db.generated_id).is_err() {
return Err(format!("Invalid UUID for database '{}'", db.name));
}
let username = match db.db_type {
DbType::Postgresql | DbType::Mysql | DbType::Mariadb => required(&db.username, &db.name, "username")?,
_ => optional(&db.username),
};
let password = match db.db_type {
DbType::Postgresql | DbType::Mysql | DbType::Mariadb => required(&db.password, &db.name, "password")?,
_ => optional(&db.password),
};
let host = match db.db_type {
DbType::Postgresql | DbType::Mysql | DbType::Mariadb | DbType::MongoDB => required(&db.host, &db.name, "host")?,
DbType::Sqlite => optional(&db.host),
};
let port = match db.db_type {
DbType::Postgresql | DbType::Mysql | DbType::Mariadb | DbType::MongoDB => required(&db.port, &db.name, "port")?,
DbType::Sqlite => db.port.unwrap_or(0),
};
let database_name = match db.db_type {
DbType::Sqlite => optional(&db.database),
_ => required(&db.database, &db.name, "database")?
};
let path_val = match db.db_type {
DbType::Sqlite => required(&db.path, &db.name, "path")?,
_ => optional(&db.path),
};
databases.push(DatabaseConfig {
name: db.name,
database: database_name,
db_type: db.db_type,
username,
password,
host,
port,
generated_id: db.generated_id,
path: path_val,
});
}
info!("Databases: {} instances loaded", databases.len());
Ok(DatabasesConfig { databases })
}
}
+13 -3
View File
@@ -1,11 +1,13 @@
#![allow(dead_code)]
use crate::core::context::Context;
use crate::services::status::DatabaseStatus;
use crate::utils::common::vec_to_option_json;
use crate::utils::redis_client;
use crate::utils::task_manager::cron::check_and_update_cron;
use std::sync::Arc;
use redis::aio::MultiplexedConnection;
use serde_json::{Value, json};
use std::sync::Arc;
use crate::services::api::models::agent::status::DatabaseStatus;
pub struct CronService {
ctx: Arc<Context>,
@@ -23,6 +25,12 @@ impl CronService {
let dbms = database.dbms.as_str();
let task_name = format!("periodic.backup_{}", generated_id);
let args = vec![generated_id.to_string(), dbms.to_string()];
let storages: Option<Value> = vec_to_option_json(database.storages.clone());
let encrypt: bool = database.encrypt;
let metadata = json!({
"storages": storages,
"encrypt": encrypt
});
check_and_update_cron(
&mut self.conn,
@@ -30,7 +38,9 @@ impl CronService {
args,
"tasks.database.periodic_backup",
task_name,
).await;
Option::from(metadata),
)
.await;
Ok(true)
}
+4 -2
View File
@@ -1,5 +1,7 @@
pub mod config;
pub mod status;
pub mod cron;
pub mod backup;
pub mod restore;
pub mod restore;
mod storage;
pub mod api;
pub mod status;

Some files were not shown because too many files have changed in this diff Show More