Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ ENV_CRON='0 1 * * *'
### possible values: "postgres", "nextcloud", "none"
ENV_PROVISION_MODE="nextcloud"

## storagebox settings
### storagebox settings (optional)
# when not set, defaults to 22
ENV_TARGET_DOMAIN_PORT="22"
### storagebox settings (needed)
ENV_TARGET_DOMAIN=name_of_your_storagebox_domain
ENV_TARGET_DOMAIN_USER=login_name_of_your_storagebox
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,69 @@ jobs:
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
repository: ${{ vars.DOCKER_HUB_USERNAME }}/backup
readme-filepath: ./README.md


test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Generate SSH Key Pair
run: |
mkdir -p sftp-keys
ssh-keygen -t rsa -b 2048 -f sftp-keys/id_rsa -q -N ""
chmod 600 sftp-keys/id_rsa

- name: Start SFTP Server with Mounts
run: |
docker run -d --name fake-sftp \
-p 2222:22 \
-v $(pwd)/sftp-keys/id_rsa.pub:/home/test/.ssh/keys/id_rsa.pub:ro \
-v $(pwd)/sftp-data:/home/test/uploads \
atmoz/sftp test::1001

- name: Wait for SFTP server to be ready
run: |
for i in {1..10}; do
if nc -z localhost 2222; then
echo "SFTP server is up!"
exit 0
fi
echo "Waiting for SFTP server..."
sleep 2
done
echo "SFTP server did not start in time" && exit 1

- name: Create test files
run: |
mkdir -p test-data
echo "File 1 content" > test-data/file1.txt
echo "File 2 content" > test-data/file2.txt
echo "File 3 content" > test-data/file3.txt

- name: delete before
run: |
docker rmi ${{ vars.DOCKER_HUB_USERNAME }}/backup:test || true

- uses: docker/setup-buildx-action@v3
- name: Build for testing
uses: docker/build-push-action@v6
with:
context: ./docker
push: false
load: true
tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:test
platforms: linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max

- name: prepare test.env
run: |
echo "ENV_SSH_PRIVATE_KEY_BASE64=$(cat $(pwd)/sftp-keys/id_rsa | base64 -w 0)" >> test.env
cat test.env

- name: Run Backup Container
run: |
./run_backup.sh backup /source
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Project specific ignores
/test.env
/local.env
/prod.env

/log/*
Expand Down
8 changes: 8 additions & 0 deletions docker/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ if [[ "$DEBUG" == "1" ]];then
exec bin/bash
fi

echo "TODO: REMOVE ME: CI/CD TESTING"
echo "DEBUG: prepare_ssh.sh"
echo "cat known hosts"
cat /etc/ssh/ssh_known_hosts

echo "cat ssh_config"
cat /etc/ssh/ssh_config

# argument mode
if [[ $# -gt 0 ]]; then
restic "${@}"
Expand Down
4 changes: 4 additions & 0 deletions docker/manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ fi

if [[ $status_backup == 0 ]]; then
telegram.sh "Backup: Successful"
# todo: find a better way for assert the backup status in tests
echo "Backup: Successful" 2>&1 | tee ${backupLastLogfile}
else
telegram.sh "Backup: Failure"
# todo: find a better way for assert the backup status in tests
echo "Backup: Failure" 2>&1 | tee ${backupLastLogfile}
fi
7 changes: 7 additions & 0 deletions docker/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,12 @@ mkdir -p /restore
## Backup specific parts not plugins
prepare_ssh.sh

echo "DEBUG: prepare_ssh.sh"
echo "cat known hosts"
cat /etc/ssh/ssh_known_hosts

echo "cat ssh_config"
cat /etc/ssh/ssh_config

## Feature specific parts
# currently nothing here
9 changes: 9 additions & 0 deletions docker/prepare_ssh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,14 @@ cat <<EOL > /etc/ssh/ssh_config
Host storagebox
Hostname $TARGET_DOMAIN
User $TARGET_DOMAIN_USER
Port ${TARGET_DOMAIN_PORT:-22}
IdentityFile /private_key
EOL


echo "DEBUG: prepare_ssh.sh"
echo "cat known hosts"
cat /etc/ssh/ssh_known_hosts

echo "cat ssh_config"
cat /etc/ssh/ssh_config
6 changes: 4 additions & 2 deletions run_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ if [[ "$#" -gt 0 ]]; then
esac
fi
###
source .env
### TODO: find a way to change env file for testing and prod usage
source test.env
###

### create restore folder at the same level as the script
Expand Down Expand Up @@ -65,6 +66,7 @@ docker run ${RESTART_OPTION} --hostname backup \
$SOURCE_MOUNT \
-e "DEBUG"="${_DEBUG}" \
-e "TARGET_DOMAIN"="${ENV_TARGET_DOMAIN}" \
-e "TARGET_DOMAIN_PORT"="${ENV_TARGET_DOMAIN_PORT}" \
-e "TARGET_DOMAIN_USER"="${ENV_TARGET_DOMAIN_USER}" \
-e "SSH_PRIVATE_KEY_BASE64"="${ENV_SSH_PRIVATE_KEY_BASE64}" \
-e "NC_URL"="${ENV_NC_URL}" \
Expand All @@ -80,4 +82,4 @@ docker run ${RESTART_OPTION} --hostname backup \
-e POSTGRES_HOST="${ENV_POSTGRES_HOST}" \
-e PROVISION_MODE="${ENV_PROVISION_MODE}" \
-e "CRON"="${ENV_CRON}" \
devp1337/backup:latest "${@}"
devp1337/backup:test "${@}"
23 changes: 23 additions & 0 deletions test.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SCRIPT_DATA_TO_BACKUP='none'
#SCRIPT_RESTORE_DATA_TO=/path/to/restore/data
#SCRIPT_LOG_PATH=/path/to/logfiles

### restic (needed)
ENV_RESTIC_REPOSITORY_NAME=test
ENV_RESTIC_PASSWORD='test123'

### telegram (needed)
ENV_TELEGRAM_TOKEN=123
ENV_TELEGRAM_CHAT_ID=123

### CRON, defaults to 1am (needed)
ENV_CRON='0 1 * * *'

### provision mode (needed)
### possible values: "postgres", "nextcloud", "none"
ENV_PROVISION_MODE="none"

ENV_TARGET_DOMAIN_PORT=2222
### storagebox settings (needed)
ENV_TARGET_DOMAIN=localhost
ENV_TARGET_DOMAIN_USER=test
File renamed without changes.
File renamed without changes.
Loading