Simple Python Backup Script
1.1K
A lightweight container that compresses a mounted source directory into a timestamped archive (zip, tar, gztar, bztar, xztar).
Ideal for simple, cron-style backups inside CI pipelines, IoT devices, or on any Docker-compatible host.
Run the container
docker run --rm \
-e backup_type=gztar \
-e backup_name=project_backup_ \
-v /host/data:/data \
-v /host/backups:/destination \
daweizhou22/python-backup-script
| Part | What it does |
|---|---|
--rm | Automatically removes (cleans up) the container filesystem when it exits. |
-e backup_type=gztar | Sets the environment variable backup_type inside the container to gztar. |
• Valid formats: zip, tar, gztar, bztar, xztar. | |
• Here: gztar means “create a .tar.gz archive.” | |
-e backup_name=project_backup_ | Sets the environment variable backup_name to project_backup_. |
| • This string is used as the filename prefix. | |
• Example output: project_backup_20250803T123045Z.tar.gz. | |
-v /host/data:/data | Mounts the host directory /host/data into the container at /data. |
• /data is the source folder that will be archived. | |
-v /host/backups:/destination | Mounts the host directory /host/backups into /destination in the container. |
• /destination is where the compressed archive will be written. | |
daweizhou22/backup-tool | The image name (and implicitly the :latest tag) you’re running. |
• This image’s CMD runs the backup.py script using the above env vars and mounts. |
Format is not valid!
Important
Make sure you bind host paths with -v /host/path:/container/path so archives are saved on your host and not into Docker-managed anonymous volumes. See the section "If you forget to mount" below.
/data or /destinationIf you run the container without
-v /host/path:/data or
-v /host/path:/destination,
Docker will create anonymous volumes for the VOLUME paths declared in the image (or mount ephemeral temporary filesystems).
The container will still see /data and /destination as mountpoints and your backup script may run successfully — but the resulting archives will be stored inside Docker's volume store (not in a host directory you control) and can appear “lost”.
/data is empty or not mountedIf the source directory is empty or not mounted the backup will still run but produce an empty archive.
All backup files are suffixed with the current UTC date-time in this exact layout:
YYYYMMDDThhmmssZ
For example, backing up on August 3, 2025 at 14:05:09 UTC with prefix project_backup yields:
Backup compressed /destination/project_backup-20250803T140509Z.tar.gz
Content type
Image
Digest
sha256:6c778675d…
Size
41.2 MB
Last updated
about 1 year ago
docker pull daweizhou22/python-backup-script