Sign inSign up

daweizhou22/python-backup-script

By daweizhou22

Updated about 1 year ago

Simple Python Backup Script

Image
Developer tools
0

1.1K

daweizhou22/python-backup-script repository overview

Backup Tool

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.


Quick Start

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
PartWhat it does
--rmAutomatically removes (cleans up) the container filesystem when it exits.
-e backup_type=gztarSets 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:/dataMounts the host directory /host/data into the container at /data.
/data is the source folder that will be archived.
-v /host/backups:/destinationMounts the host directory /host/backups into /destination in the container.
/destination is where the compressed archive will be written.
daweizhou22/backup-toolThe 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.

Warnings & Errors

  • If you specify an invalid archive format, you’ll see:
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.
What happens if you DON'T mount /data or /destination

If 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”.

If /data is empty or not mounted

If the source directory is empty or not mounted the backup will still run but produce an empty archive.

Timestamp Format

All backup files are suffixed with the current UTC date-time in this exact layout:

YYYYMMDDThhmmssZ
  • YYYY = four-digit year
  • MM = two-digit month (01–12)
  • DD = two-digit day (01–31)
  • T = literal “T” separator
  • hh = two-digit hour (00–23)
  • mm = two-digit minute (00–59)
  • ss = two-digit second (00–59)
  • Z = literal “Z” (denotes UTC)\

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

Tag summary

Content type

Image

Digest

sha256:6c778675d

Size

41.2 MB

Last updated

about 1 year ago

docker pull daweizhou22/python-backup-script