Sign inSign up

steveliedtke/simple_backup_dir

By steveliedtke

•Updated about 2 months ago

Creates a simple backup of your directory by copying the directory.

Image
Developer tools
0

10K+

steveliedtke/simple_backup_dir repository overview

⁠simple_backup_dir

This image creates a simple backup of your directory by copying it.

The backup directory is placed beside the source directory and a date stamp is added. In case a backup directory already exists for the current date a counter will be added.

Assuming the current date is 25th of May in 2024 the following results can be expected:

  • /data/my_directory will be backup'd to /data/my_directory_backup_2024-05-25 no other backup directory exists for the current date.
  • If the backup directory /data/my_directory_backup_2024-05-25 already exists /data/my_directory will be backup'd to /data/my_directory_backup_2024-05-25_1
  • If the backup directory /data/my_directory_backup_2024-05-25_1 already exists /data/my_directory will be backup'd to /data/my_directory_backup_2024-05-25_2
  • and so on

⁠Usage

⁠With command argument
docker run 
        -v /data:/app/data 
        steveliedtke/simple_backup_dir:0.7.1 /app/backup.sh data/my_directory
⁠With environment variable
docker run 
        -v /data:/app/data 
        -e BACKUP_DIR=data/my_directory 
        steveliedtke/simple_backup_dir:0.7.1
⁠With Kubernetes Job

You can run the backup as a Kubernetes Job. Here's an example manifest:

apiVersion: batch/v1
kind: Job
metadata:
  name: directory-backup-job
spec:
  template:
    spec:
      containers:
      - name: backup
        image: steveliedtke/simple_backup_dir:0.7.1
        env:
        - name: BACKUP_DIR
          value: "data/my_directory"
        volumeMounts:
        - name: data-volume
          mountPath: /app/data
      volumes:
      - name: data-volume
        persistentVolumeClaim:
          claimName: your-pvc-name
      restartPolicy: Never

This job will:

  1. Run the backup container with specified environment variables
  2. Mount your persistent volume at /app/data
  3. Create a backup according to the settings

For use with ArgoCD, you can modify the metadata to use generateName and hook annotations:

metadata:
  generateName: directory-backup-
  annotations:
    argocd.argoproj.io/hook: PreSync

⁠Cleanup Options

The backup script supports automatic cleanup of old backups through two optional environment variables. Both variables have no default values, meaning if they are not set, no cleanup will be performed:

⁠CLEANUP_MORE_THAN

This option allows you to keep a specific number of the most recent backups and remove older ones.

docker run 
        [..] 
        -e CLEANUP_MORE_THAN=5 
        steveliedtke/simple_backup_dir:0.7.1

In this example, only the 5 most recent backups will be kept. After creating a new backup, any older backups beyond this limit will be automatically removed.

⁠CLEANUP_OLDER_THAN_DAYS

This option allows you to remove backups that are older than a specified number of days.

docker run 
        [..] 
        -e CLEANUP_OLDER_THAN_DAYS=30 
        steveliedtke/simple_backup_dir:0.7.1

In this example, any backups that are older than 30 days will be automatically removed after creating a new backup.

⁠Combined Cleanup

You can use both cleanup options together:

docker run 
        [..] 
        -e CLEANUP_MORE_THAN=5 
        -e CLEANUP_OLDER_THAN_DAYS=30 
        steveliedtke/simple_backup_dir:0.7.1

This will ensure that:

  1. Only the 5 most recent backups are kept
  2. No backups older than 30 days are kept

Note that both cleanup operations run independently, so whichever condition is met first will trigger the removal of the backup.

⁠Other Variables

⁠Help Flag

You can display the script's help information using either -h or --help:

docker run steveliedtke/simple_backup_dir:0.7.1 /app/backup.sh --help

This will show all available arguments and environment variables with their descriptions.

⁠ALPINE_REGEX

This environment variable controls the type of regular expression syntax used for finding backup directories. It's particularly useful when running the container in different environments.

docker run 
        [..] 
        -e ALPINE_REGEX=false 
        steveliedtke/simple_backup_dir:0.7.1
  • When ALPINE_REGEX=true: Uses Alpine Linux compatible regex syntax (default when using the docker image)
  • When ALPINE_REGEX=false: Uses standard regex syntax with Perl-compatible patterns

This setting may need to be adjusted if you're experiencing issues with backup directory detection in different environments. The Alpine version is particularly useful when running the container on Alpine-based images.

Tag summary

Content type

Image

Digest

sha256:ab3fbc6c5…

Size

3.9 MB

Last updated

about 2 months ago

docker pull steveliedtke/simple_backup_dir