Skip to content

Purge Docker Containers Every 15 Days, Zip, Upload Volume to s3, Store Meta Data in Mysql. Includes Recovery Script To Rebuild Docker Container

License

Notifications You must be signed in to change notification settings

bbarclay/docker_purge_s3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Container Backup and Purge (Store and Recover from s3)

#Warning, I have not tested this yet. Please test it in a none production environment before fully deploying.

This repository contains two bash scripts to backup and purge Docker containers and their associated volumes. The scripts also have the option to remove the Docker images.

The scripts use the Docker, AWS CLI, and MySQL CLI commands to perform their tasks. They interact with Amazon S3 for storing backups and MySQL for storing backup metadata.

Prerequisites

  • Docker
  • AWS CLI
  • MySQL CLI

Setup

  1. Clone this repository:
    git clone https://github.com/bbarclay/docker_purge_s3.git
  2. Change into the repository directory:
    cd repo
  3. Edit the .env file to include your AWS and MySQL credentials:
    nano .env
    Be sure to replace the placeholders with your actual credentials. Save and close the file when you're done editing.

Usage

Backup and Purge

The backup_and_purge.sh script is used to backup and purge Docker containers that are older than 15 days.

Run the script without any options to simply backup and purge the containers and volumes:

./backup_and_purge.sh

You can also use the -r option to remove the Docker images:

./backup_and_purge.sh -r

Restore

The restore.sh script is used to restore a Docker container and its volumes from a backup.

To use this script, pass the ID of the backup record from the MySQL database:

./restore.sh -i 123

Replace 123 with the actual ID.

Scheduling

You can schedule the backup_and_purge.sh script to run at a certain time every day using cron.

For example, to run the script every day at 2 AM:

0 2 * * * /path/to/backup_and_purge.sh -r >> /path/to/logfile.log 2>&1

Replace /path/to/backup_and_purge.sh with the actual path to the backup_and_purge.sh script, and /path/to/logfile.log with the actual path to the log file.

#Be sure to set the correct permissions on the script file:

chmod +x backup_and_purge.sh

The Database Table Schema is located in the backups.sql file

CREATE TABLE backups (
    id INT AUTO_INCREMENT PRIMARY KEY,
    container_id VARCHAR(64) NOT NULL,
    container_name VARCHAR(255) NOT NULL,
    image VARCHAR(255) NOT NULL,
    volume_name VARCHAR(255) NOT NULL,
    s3_path VARCHAR(255) NOT NULL
);

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Purge Docker Containers Every 15 Days, Zip, Upload Volume to s3, Store Meta Data in Mysql. Includes Recovery Script To Rebuild Docker Container

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages