Create Postgres or MySQL dumps in a container. Dumps are saved to a host-mounted directory and uploads to DigitalOcean Spaces are optional.
docker build -t db-backup .
docker run --rm \ -e DB_TYPE=postgres \ -e BACKUP_FILE_NAME=mydb \ -e POSTGRES_HOST=your-postgres-host \ -e POSTGRES_PORT=5432 \ -e POSTGRES_USER=your-user \ -e POSTGRES_PASSWORD=your-password \ -e POSTGRES_DB=your-db \ -e UPLOAD_TO_DO=false \ -v /host/backups:/backups \ db-backup
docker run --rm \ -e DB_TYPE=mysql \ -e BACKUP_FILE_NAME=mydb \ -e MYSQL_HOST=your-mysql-host \ -e MYSQL_PORT=3306 \ -e MYSQL_USER=your-user \ -e MYSQL_PASSWORD=your-password \ -e MYSQL_DB=your-db \ -e UPLOAD_TO_DO=false \ -v /host/backups:/backups \ db-backup
Notes:
mariadb-dump when available and falls back to mysqldump.MYSQL_DUMP_BIN to override the dump binary.By default, dumps are written to /backups inside the container. Bind-mount a
host folder to persist them, or change the target directory with DUMP_DIR.
Example with a custom directory:
docker run --rm \ -e DB_TYPE=postgres \ -e BACKUP_FILE_NAME=mydb \ -e POSTGRES_HOST=your-postgres-host \ -e POSTGRES_USER=your-user \ -e POSTGRES_DB=your-db \ -e DUMP_DIR=/data/backups \ -v /host/backups:/data/backups \ db-backup
Uploads are disabled by default. To enable them, set UPLOAD_TO_DO=true and
provide the DigitalOcean Spaces credentials and endpoint.
Required vars when upload is enabled:
DO_SPACES_BUCKETDO_SPACES_KEYDO_SPACES_SECRETDO_SPACES_ENDPOINT (example: nyc3.digitaloceanspaces.com)Example:
docker run --rm \ -e DB_TYPE=postgres \ -e BACKUP_FILE_NAME=mydb \ -e POSTGRES_HOST=your-postgres-host \ -e POSTGRES_USER=your-user \ -e POSTGRES_DB=your-db \ -e UPLOAD_TO_DO=true \ -e DO_SPACES_BUCKET=your-bucket \ -e DO_SPACES_KEY=your-key \ -e DO_SPACES_SECRET=your-secret \ -e DO_SPACES_ENDPOINT=nyc3.digitaloceanspaces.com \ -v /host/backups:/backups \ db-backup
Common:
DB_TYPE (default: postgres)BACKUP_FILE_NAME (required)DUMP_DIR (default: /backups)UPLOAD_TO_DO (default: false)Postgres:
POSTGRES_HOST (required)POSTGRES_PORT (default: 5432)POSTGRES_USER (required)POSTGRES_PASSWORD (optional, required if your DB needs auth)POSTGRES_DB (required)MySQL:
MYSQL_HOST (required)MYSQL_PORT (default: 3306)MYSQL_USER (required)MYSQL_PASSWORD (optional, required if your DB needs auth)MYSQL_DB (required)MYSQL_DUMP_BIN (optional, override dump binary)Content type
Image
Digest
sha256:45f0517c5…
Size
73.1 MB
Last updated
8 months ago
docker pull kerosine/db-backups:9