You've already forked docker-volume-backup
mirror of
https://github.com/offen/docker-volume-backup.git
synced 2025-11-23 21:44:40 +02:00
Add failing test
This commit is contained in:
@@ -42,7 +42,9 @@ func (c *command) runAsCommand() error {
|
||||
return errwrap.Wrap(err, "error running script")
|
||||
}
|
||||
case "container":
|
||||
panic("execution mode container not implemented")
|
||||
if err := runInContainer(config); err != nil {
|
||||
return errwrap.Wrap(err, "error spawning container")
|
||||
}
|
||||
default:
|
||||
return errwrap.Wrap(nil, fmt.Sprintf("unknown execution mode %s", config.ExecutionMode))
|
||||
}
|
||||
@@ -131,7 +133,17 @@ func (c *command) schedule(strategy configStrategy) error {
|
||||
)
|
||||
}
|
||||
case "container":
|
||||
panic("execution mode container not implemented")
|
||||
if err := runInContainer(config); err != nil {
|
||||
c.logger.Error(
|
||||
fmt.Sprintf(
|
||||
"Unexpected error running schedule %s in container: %v",
|
||||
config.BackupCronExpression,
|
||||
errwrap.Unwrap(err),
|
||||
),
|
||||
"error",
|
||||
err,
|
||||
)
|
||||
}
|
||||
default:
|
||||
c.logger.Error(
|
||||
fmt.Sprintf(
|
||||
|
||||
5
cmd/backup/container.go
Normal file
5
cmd/backup/container.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package main
|
||||
|
||||
func runInContainer(config *Config) error {
|
||||
return nil
|
||||
}
|
||||
22
test/container/docker-compose.yml
Normal file
22
test/container/docker-compose.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
services:
|
||||
backup:
|
||||
image: offen/docker-volume-backup:${TEST_VERSION:-canary}
|
||||
restart: always
|
||||
environment:
|
||||
BACKUP_FILENAME: test.tar.gz
|
||||
BACKUP_CRON_EXPRESSION: 0 0 5 31 2 ?
|
||||
EXECUTION_MODE: container
|
||||
volumes:
|
||||
- app_data:/backup/app_data:ro
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
- ${LOCAL_DIR:-./local}:/archive
|
||||
|
||||
offen:
|
||||
image: offen/offen:latest
|
||||
labels:
|
||||
- docker-volume-backup.stop-during-backup=true
|
||||
volumes:
|
||||
- app_data:/var/opt/offen
|
||||
|
||||
volumes:
|
||||
app_data:
|
||||
28
test/container/run.sh
Executable file
28
test/container/run.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
. ../util.sh
|
||||
current_test=$(basename $(pwd))
|
||||
|
||||
export LOCAL_DIR=$(mktemp -d)
|
||||
|
||||
docker compose up -d --quiet-pull
|
||||
sleep 5
|
||||
|
||||
# A symlink for a known file in the volume is created so the test can check
|
||||
# whether symlinks are preserved on backup.
|
||||
docker compose exec offen ln -s /var/opt/offen/offen.db /var/opt/offen/db.link
|
||||
docker compose exec backup backup
|
||||
|
||||
sleep 5
|
||||
|
||||
expect_running_containers "2"
|
||||
|
||||
tmp_dir=$(mktemp -d)
|
||||
tar -xvf "$LOCAL_DIR/test.tar.gz" -C $tmp_dir
|
||||
if [ ! -f "$tmp_dir/backup/app_data/offen.db" ]; then
|
||||
fail "Could not find expected file in untared archive."
|
||||
fi
|
||||
rm -f "$LOCAL_DIR/test-hostnametoken.tar.gz"
|
||||
Reference in New Issue
Block a user