ssh client revision added some helper scripts and changed to alpine
All checks were successful
/ build-docker-image (push) Successful in 50s
All checks were successful
/ build-docker-image (push) Successful in 50s
This commit is contained in:
78
README.md
78
README.md
@@ -1 +1,77 @@
|
|||||||
git.limbosolutions.com/kb/borg-backup
|
# borg-backup
|
||||||
|
|
||||||
|
<https://www.borgbackup.org/>
|
||||||
|
|
||||||
|
## container image
|
||||||
|
|
||||||
|
## environment variables
|
||||||
|
|
||||||
|
<https://borgbackup.readthedocs.io/en/stable/usage/general.html#environment-variables>
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
docker run git.limbosolutions.com/kb/borg-backup:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
### docker compose
|
||||||
|
|
||||||
|
Example of simple usage for creating a backup
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
borg-backup:
|
||||||
|
image: git.limbosolutions.com/kb/borg-backup:latest
|
||||||
|
command: create ${BORG_REPO}::repos-$(date +%Y%m%d%H%M%S) /mnt/user
|
||||||
|
restart: no
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- ./home/user:/mnt/user # Mount local folder to container
|
||||||
|
|
||||||
|
environment:
|
||||||
|
- BORG_REPO=?????
|
||||||
|
- BORG_RSH="ssh -o StrictHostKeyChecking=no"
|
||||||
|
- BORG_PASSPHRASE=????
|
||||||
|
|
||||||
|
configs:
|
||||||
|
- source: id_ed25519 # required for ssh client
|
||||||
|
target: /home/borg/.ssh/id_ed25519
|
||||||
|
- source: borg_key # required for borg client
|
||||||
|
target: /app/borg/key
|
||||||
|
|
||||||
|
|
||||||
|
configs:
|
||||||
|
|
||||||
|
id_ed25519:
|
||||||
|
content: |
|
||||||
|
-----BEGIN OPENSSH PRIVATE KEY-----
|
||||||
|
**************
|
||||||
|
**************
|
||||||
|
-----END OPENSSH PRIVATE KEY-----
|
||||||
|
|
||||||
|
borg_key:
|
||||||
|
content: |
|
||||||
|
BORG_KEY ???????
|
||||||
|
????????????????
|
||||||
|
????????????????
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### dev
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
docker compose \
|
||||||
|
--project-name borg-backup-dev \
|
||||||
|
-f docker-compose.dev.yaml \
|
||||||
|
-f docker-compose.dev.local.yaml \
|
||||||
|
up
|
||||||
|
```
|
||||||
|
|
||||||
|
Force Build:
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
docker compose \
|
||||||
|
--project-name borg-backup-dev \
|
||||||
|
-f docker-compose.dev.yaml \
|
||||||
|
-f docker-compose.dev.local.yaml \
|
||||||
|
up --build
|
||||||
|
```
|
||||||
|
|||||||
35
docker-compose.dev.yaml
Normal file
35
docker-compose.dev.yaml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
services:
|
||||||
|
borg:
|
||||||
|
tty: true
|
||||||
|
stdin_open: true
|
||||||
|
# entrypoint: ["bash"]
|
||||||
|
build:
|
||||||
|
dockerfile: docker/Dockerfile
|
||||||
|
context: .
|
||||||
|
environment:
|
||||||
|
- BORG_REPO=???????
|
||||||
|
- BORG_RSH="ssh -o StrictHostKeyChecking=no"
|
||||||
|
- BORG_PASSPHRASE=????
|
||||||
|
|
||||||
|
configs:
|
||||||
|
- source: id_ed25519
|
||||||
|
target: /home/borg/.ssh/id_ed25519
|
||||||
|
- source: borg_key
|
||||||
|
target: /app/borg/key
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- ./docker/app/scripts:/app/scripts
|
||||||
|
configs:
|
||||||
|
|
||||||
|
id_ed25519:
|
||||||
|
content: |
|
||||||
|
-----BEGIN OPENSSH PRIVATE KEY-----
|
||||||
|
???????
|
||||||
|
???????
|
||||||
|
-----END OPENSSH PRIVATE KEY-----
|
||||||
|
|
||||||
|
borg_key:
|
||||||
|
content: |
|
||||||
|
BORG_KEY ???????
|
||||||
|
????????????????
|
||||||
|
????????????????
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
services:
|
|
||||||
borg:
|
|
||||||
build:
|
|
||||||
dockerfile: /docker/dockerfile
|
|
||||||
context: .
|
|
||||||
environment:
|
|
||||||
- BORG_REPO=${BORG_REPO}
|
|
||||||
- BORG_RSH=${BORG_RSH}
|
|
||||||
- BORG_PASSPHRASE=${BORG_PASSPHRASE}
|
|
||||||
- SSH_ID=${SSH_ID}
|
|
||||||
- BORG_KEY=${BORG_KEY}
|
|
||||||
@@ -1,16 +1,25 @@
|
|||||||
FROM ubuntu:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
RUN apt-get update
|
# Install BorgBackup and OpenSSH client
|
||||||
|
RUN apk update && apk add --no-cache \
|
||||||
RUN apt-get install -y \
|
borgbackup \
|
||||||
python3 \
|
openssh \
|
||||||
python3-pip \
|
bash \
|
||||||
borgbackup \
|
tzdata
|
||||||
fuse \
|
|
||||||
python3-pyfuse3 \
|
|
||||||
openssh-client
|
|
||||||
|
|
||||||
COPY ./docker/app /app
|
COPY ./docker/app /app
|
||||||
RUN chmod +x /app/scripts/ffenv
|
RUN chmod +x /app/scripts -R
|
||||||
RUN ln -s /app/scripts/ffenv /usr/local/bin/ffenv
|
RUN ln -s /app/scripts/loadenv /usr/local/bin/loadenv
|
||||||
|
RUN ln -s /app/scripts/remote-connect /usr/local/bin/remote-connect
|
||||||
|
RUN ln -s /app/scripts/remote-connect /usr/local/bin/remote-get-folder-size
|
||||||
|
RUN addgroup -S borg && adduser -S borg -G borg
|
||||||
|
USER borg
|
||||||
|
|
||||||
|
WORKDIR /home/borg
|
||||||
|
|
||||||
|
RUN echo "source /usr/local/bin/loadenv" > ~/.bash_profile
|
||||||
|
RUN echo "source /usr/local/bin/loadenv" > ~/.bashrc
|
||||||
|
|
||||||
|
ENTRYPOINT ["bash" , "-c", "borg $0"]
|
||||||
|
|
||||||
|
CMD ["--help"]
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
echo "checking SSH_ID..."
|
|
||||||
if [[ "${SSH_ID}" ]]; then
|
|
||||||
echo "found SSH_ID..."
|
|
||||||
mkdir -p /root/.ssh
|
|
||||||
echo "${SSH_ID}" > /root/.ssh/id_rsa
|
|
||||||
chmod 700 /root/.ssh/id_rsa
|
|
||||||
fi
|
|
||||||
echo "checking BORG_KEY..."
|
|
||||||
if [[ "${BORG_KEY}" ]]; then
|
|
||||||
echo "found BORG_KEY..."
|
|
||||||
mkdir -p /root/.config/borg/keys
|
|
||||||
echo "${BORG_KEY}" > /root/.config/borg/keys/key
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
32
docker/app/scripts/loadenv
Executable file
32
docker/app/scripts/loadenv
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
(return 0 2>/dev/null) || {
|
||||||
|
echo "Please source this script: source $0"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if [ -f "/app/borg/key" ]; then
|
||||||
|
export BORG_KEY_FILE="/app/borg/key"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# extracts ssh connection from borg-repo
|
||||||
|
export SSH_CONNECTION="${BORG_REPO#ssh://}"
|
||||||
|
export SSH_CONNECTION="${SSH_CONNECTION%%/*}"
|
||||||
|
|
||||||
|
#extract folder from ssh connection
|
||||||
|
export SSH_FOLDER="/${BORG_REPO#ssh://*/}"
|
||||||
|
|
||||||
|
|
||||||
|
export SSH_COMMAND="ssh"
|
||||||
|
if [ "${BORG_RSH}" ]; then
|
||||||
|
export SSH_COMMAND=${BORG_RSH}
|
||||||
|
fi
|
||||||
|
|
||||||
|
export SSH_COMMAND="$SSH_COMMAND $SSH_CONNECTION"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
11
docker/app/scripts/remote-connect
Executable file
11
docker/app/scripts/remote-connect
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#/bin/bash
|
||||||
|
source /app/scripts/loadenv
|
||||||
|
#echo "Received: $@"
|
||||||
|
#echo "Trace: Connecting with: ${SSH_COMMAND[@]}" "$@"
|
||||||
|
|
||||||
|
# converts command to array
|
||||||
|
read -r -a SSH_COMMAND_ARRAY <<< "$SSH_COMMAND"
|
||||||
|
|
||||||
|
#echo "Running: ${SSH_COMMAND_ARRAY[@]} $@"
|
||||||
|
# executes ssh command with all arguments received from caller
|
||||||
|
"${SSH_COMMAND_ARRAY[@]}" "$@"
|
||||||
5
docker/app/scripts/remote-get-folder-size
Executable file
5
docker/app/scripts/remote-get-folder-size
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#/bin/bash
|
||||||
|
source loadenv
|
||||||
|
repo_size_bytes=$(remote-connect du -b "$SSH_FOLDER" -d 0)
|
||||||
|
repo_size_bytes=$(echo "$repo_size_bytes" | awk '{print $1}')
|
||||||
|
echo "$repo_size_bytes"
|
||||||
Reference in New Issue
Block a user