From 9fd2b7dd8bc549ddf0c20d8b2d4ca1e57d21a15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Fernandes?= Date: Sun, 14 Sep 2025 16:12:23 +0100 Subject: [PATCH] modified: README.md --- README.md | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 343cafd..406ff97 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,33 @@ docker run git.limbosolutions.com/kb/borg-backup:latest ``` +## repo init + +```bash +services: + borg-backup: + image: git.limbosolutions.com/kb/borg-backup:latest + restart: no + tty: true + environment: + - BORG_REPO: ssh://user@server/home/user/borg-repo + - BORG_RSH: "-o StrictHostKeyChecking=no -o LogLevel=ERROR" + configs: + - source: id_ed25519 # required for ssh client + target: /home/borg/.ssh/id_ed25519 + +configs: + create.sh: + content: + while true; do + sleep 5 + done + # execute for example + #borg init --encryption=keyfile-blake2 $BORG_REPO + # dont forget to copy key file content on borg folder (/root/.borg/keys/*) and BORG_PASSPHRASE + +``` + ### docker compose Example of simple usage for creating a backup @@ -28,7 +55,7 @@ services: environment: - BORG_REPO=????? - - BORG_RSH="ssh -o StrictHostKeyChecking=no" + - BORG_RSH: "-o StrictHostKeyChecking=no -o LogLevel=ERROR" - BORG_PASSPHRASE=???? configs: @@ -56,6 +83,82 @@ configs: ``` +Example using an bash script + +```yaml +services: + borg-backup: + restart: no + image: git.limbosolutions.com/kb/borg-backup:latest + entrypoint: ["bash", "backup.sh"] + configs: + - source: backup_script + target: /backup.sh + - source: id_ed25519 + target: /root/.ssh/id_ed25519 + mode: 0400 + - source: borg_key + target: /app/borg/key + environment: + BORG_REPO: ssh://user@server/path + BORG_RSH: "ssh -o StrictHostKeyChecking=no" + BORG_PASSPHRASE: ***** + REPO_SYNC_MAX_SIZE: 10737418240 #10GB + + + volumes: + - /home/mf/repos:/mnt/repos + +configs: + backup_script: + content: | + source loadenv + set -e + + # while true; do + # sleep 5 + # done + + SCRIPT_START_TIME=$$(date +%s) + + borg create $${BORG_REPO}::repos-$$(date +%Y%m%d%H%M%S) /mnt/backup + + #cleanup + borg prune -v --list --keep-daily=10 --keep-weekly=7 --keep-monthly=-1 $${BORG_REPO} --glob-archives='backup*' + borg compact $${BORG_REPO} + + # check repo size + REPO_SIZE_IN_BYTES=$$(remote-connect du -b "$$SSH_FOLDER" -d 0 | awk '{print $$1}') + echo "Repository size: $$((REPO_SIZE_IN_BYTES / 1024 / 1024)) MB" + echo "Repository max size: $$((REPO_SYNC_MAX_SIZE / 1024 / 1024)) MB" + if [ $$REPO_SIZE_IN_BYTES -gt $$REPO_SYNC_MAX_SIZE ]; then \ + echo "ERROR: Repository size exceeds $$REPO_SYNC_MAX_SIZE"; + exit 1; + else + # Repository size is within limits for offsite sync + # ssh to backup server and enforce rclone to onedrive + remote-connect "rclone sync $$SSH_FOLDER xxxxx:.backups/xxxxxx" && \ + SCRIPT_DURATION=$$(($(date +%s) - SCRIPT_START_TIME)) && \ + echo "INFO: Finished Backup (offsite) ($((SCRIPT_DURATION / 60 / 60)):$$((SCRIPT_DURATION / 60)):$$((SCRIPT_DURATION % 60))) " + fi + + #outputs info + borg info ${BORG_REPO} + exit 0 + + + id_ed25519: + content: | + -----BEGIN OPENSSH PRIVATE KEY----- + `*****************************ยด + -----END OPENSSH PRIVATE KEY----- + + borg_key: + content: | + BORG_KEY ****** + *************** +``` + ### dev ``` bash