{"id":13688425,"url":"https://github.com/appleboy/docker-backup-database","last_synced_at":"2025-04-09T20:09:03.464Z","repository":{"id":57559560,"uuid":"314072668","full_name":"appleboy/docker-backup-database","owner":"appleboy","description":"Docker image to periodically backup your database (MySQL, Postgres, or MongoDB) to S3 or local disk.","archived":false,"fork":false,"pushed_at":"2025-03-06T08:34:23.000Z","size":267,"stargazers_count":120,"open_issues_count":3,"forks_count":27,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T20:08:56.032Z","etag":null,"topics":["database","docker","mongodb","mysql","postgres"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/appleboy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-18T22:22:52.000Z","updated_at":"2025-04-02T02:51:14.000Z","dependencies_parsed_at":"2022-08-28T10:20:18.237Z","dependency_job_id":null,"html_url":"https://github.com/appleboy/docker-backup-database","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appleboy%2Fdocker-backup-database","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appleboy%2Fdocker-backup-database/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appleboy%2Fdocker-backup-database/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appleboy%2Fdocker-backup-database/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/appleboy","download_url":"https://codeload.github.com/appleboy/docker-backup-database/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103872,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","docker","mongodb","mysql","postgres"],"created_at":"2024-08-02T15:01:13.423Z","updated_at":"2025-04-09T20:09:03.430Z","avatar_url":"https://github.com/appleboy.png","language":"Go","funding_links":[],"categories":["Go","docker"],"sub_categories":[],"readme":"# docker-backup-database\n\n[![GoDoc](https://godoc.org/github.com/appleboy/docker-backup-database?status.svg)](https://godoc.org/github.com/appleboy/docker-backup-database)\n[![codecov](https://codecov.io/gh/appleboy/docker-backup-database/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/docker-backup-database)\n[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/docker-backup-database)](https://goreportcard.com/report/github.com/appleboy/docker-backup-database)\n[![Docker Image](https://github.com/appleboy/docker-backup-database/actions/workflows/docker.yml/badge.svg)](https://github.com/appleboy/docker-backup-database/actions/workflows/docker.yml)\n\nEnglish | [繁體中文](README_zh-TW.md) | [簡體中文](README_zh-CN.md)\n\nDocker image to periodically backup a your database (MySQL, Postgres or MongoDB) to Local Disk or S3 ([AWS S3](https://aws.amazon.com/free/storage/s3) or [Minio](https://min.io/)).\n\n[中文 Youtube 影片](https://www.youtube.com/watch?v=nsiKKSy5fUA)\n\n## Support Database\n\nsee the [docker hub page](https://hub.docker.com/repository/docker/appleboy/docker-backup-database).\n\n- Postgres (9, 10, 11, 12, 13, 14, 15, 16, 17)\n  - 9: appleboy/docker-backup-database:postgres9\n  - 10: appleboy/docker-backup-database:postgres10\n  - 11: appleboy/docker-backup-database:postgres11\n  - 12: appleboy/docker-backup-database:postgres12\n  - 13: appleboy/docker-backup-database:postgres13\n  - 14: appleboy/docker-backup-database:postgres14\n  - 15: appleboy/docker-backup-database:postgres15\n  - 16: appleboy/docker-backup-database:postgres16\n  - 17: appleboy/docker-backup-database:postgres17\n- MySQL (8, 9)\n  - 8: appleboy/docker-backup-database:mysql8\n  - 9: appleboy/docker-backup-database:mysql9\n- Mongo (4.4)\n  - 4.4: appleboy/docker-backup-database:mongo4.4\n\n## Docker Image\n\nYou can pull the latest image of the project from the Docker Hub Registry.\n\n```sh\ndocker pull appleboy/docker-backup-database:postgres12\n```\n\nOr you can pull the latest image of the project from the GitHub Container Registry.\n\n```sh\ndocker pull ghcr.io/appleboy/docker-backup-database:postgres12\n```\n\n## Usage\n\nFirst steps: Setup the Minio and Postgres 12 Server using docker-compose command.\n\n```yaml\nservices:\n  minio:\n    image: quay.io/minio/minio\n    restart: always\n    volumes:\n      - data1-1:/data1\n    ports:\n      - 9000:9000\n      - 9001:9001\n    environment:\n      MINIO_ROOT_USER: minioadmin\n      MINIO_ROOT_PASSWORD: minioadmin\n    command: server /data --console-address \":9001\"\n    healthcheck:\n      test: [\"CMD\", \"curl\", \"-f\", \"http://localhost:9000/minio/health/live\"]\n      interval: 30s\n      timeout: 20s\n      retries: 3\n\n  postgres:\n    image: postgres:12\n    restart: always\n    volumes:\n      - pg-data:/var/lib/postgresql/data\n    logging:\n      options:\n        max-size: \"100k\"\n        max-file: \"3\"\n    environment:\n      POSTGRES_USER: db\n      POSTGRES_DB: db\n      POSTGRES_PASSWORD: db\n```\n\nSecond Steps: Backup your database and upload the dump file to S3 storage.\n\n```yaml\nbackup_postgres:\n  image: appleboy/docker-backup-database:postgres12\n  logging:\n    options:\n      max-size: \"100k\"\n      max-file: \"3\"\n  environment:\n    STORAGE_DRIVER: s3\n    STORAGE_ENDPOINT: minio:9000\n    STORAGE_BUCKET: test\n    STORAGE_REGION: ap-northeast-1\n    STORAGE_PATH: backup_postgres\n    STORAGE_SSL: \"false\"\n    STORAGE_INSECURE_SKIP_VERIFY: \"false\"\n    ACCESS_KEY_ID: minioadmin\n    SECRET_ACCESS_KEY: minioadmin\n\n    DATABASE_DRIVER: postgres\n    DATABASE_HOST: postgres:5432\n    DATABASE_USERNAME: db\n    DATABASE_PASSWORD: db\n    DATABASE_NAME: db\n    DATABASE_OPTS:\n```\n\nThe default lifecycle policy is disabled. You can enable it by setting the `STORAGE_DAYS` environment variable. You can change the `STORAGE_DAYS` environment variable to keep the backup files for a different number of days. You also can change the `STORAGE_PATH` environment variable to save the backup files in a different directory.\n\n```yaml\nSTORAGE_DAYS: 30\nSTORAGE_PATH: backup_postgres\n```\n\nCron schedule to run periodic backups. See the `TIME_SCHEDULE` and `TIME_LOCATION`\n\n```yaml\nbackup_mysql:\n  image: appleboy/docker-backup-database:mysql8\n  logging:\n    options:\n      max-size: \"100k\"\n      max-file: \"3\"\n  environment:\n    STORAGE_DRIVER: s3\n    STORAGE_ENDPOINT: minio:9000\n    STORAGE_BUCKET: test\n    STORAGE_REGION: ap-northeast-1\n    STORAGE_PATH: backup_mysql\n    STORAGE_SSL: \"false\"\n    STORAGE_INSECURE_SKIP_VERIFY: \"false\"\n    ACCESS_KEY_ID: 1234567890\n    SECRET_ACCESS_KEY: 1234567890\n\n    DATABASE_DRIVER: mysql\n    DATABASE_HOST: mysql:3306\n    DATABASE_USERNAME: root\n    DATABASE_PASSWORD: db\n    DATABASE_NAME: db\n    DATABASE_OPTS:\n\n    TIME_SCHEDULE: \"@daily\"\n    TIME_LOCATION: Asia/Taipei\n```\n\nEach line of a crontab file represents a job, and looks like this:\n\n```sh\n# ┌───────────── minute (0 - 59)\n# │ ┌───────────── hour (0 - 23)\n# │ │ ┌───────────── day of the month (1 - 31)\n# │ │ │ ┌───────────── month (1 - 12)\n# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;\n# │ │ │ │ │                                   7 is also Sunday on some systems)\n# │ │ │ │ │\n# │ │ │ │ │\n# * * * * * \u003ccommand to execute\u003e\n```\n\nA cron expression represents a set of times, using 5 space-separated fields.\n\n| Field name   | Mandatory? | Allowed values  | Allowed special characters |\n| ------------ | ---------- | --------------- | -------------------------- |\n| Minutes      | Yes        | 0-59            | \\* / , -                   |\n| Hours        | Yes        | 0-23            | \\* / , -                   |\n| Day of month | Yes        | 1-31            | \\* / , - ?                 |\n| Month        | Yes        | 1-12 or JAN-DEC | \\* / , -                   |\n| Day of week  | Yes        | 0-6 or SUN-SAT  | \\* / , - ?                 |\n\nYou may use one of several pre-defined schedules in place of a cron expression.\n\n```sh\n| Entry                  | Description                                | Equivalent To |\n| ---------------------- | ------------------------------------------ | ------------- |\n| @yearly (or @annually) | Run once a year, midnight, Jan. 1st        | 0 0 1 1 *     |\n| @monthly               | Run once a month, midnight, first of month | 0 0 1 * *     |\n| @weekly                | Run once a week, midnight between Sat/Sun  | 0 0 * * 0     |\n| @daily (or @midnight)  | Run once a day, midnight                   | 0 0 * * *     |\n| @hourly                | Run once an hour, beginning of hour        | 0 * * * *     |\n```\n\n### Setup Webhook Notification\n\nYou can setup the webhook notification to send the backup status to the slack channel.\n\n```diff\nbackup_mysql:\n  image: appleboy/docker-backup-database:mysql8\n  logging:\n    options:\n      max-size: \"100k\"\n      max-file: \"3\"\n  environment:\n    STORAGE_DRIVER: s3\n    STORAGE_ENDPOINT: minio:9000\n    STORAGE_BUCKET: test\n    STORAGE_REGION: ap-northeast-1\n    STORAGE_PATH: backup_mysql\n    STORAGE_SSL: \"false\"\n    STORAGE_INSECURE_SKIP_VERIFY: \"false\"\n    ACCESS_KEY_ID: 1234567890\n    SECRET_ACCESS_KEY: 1234567890\n\n    DATABASE_DRIVER: mysql\n    DATABASE_HOST: mysql:3306\n    DATABASE_USERNAME: root\n    DATABASE_PASSWORD: db\n    DATABASE_NAME: db\n    DATABASE_OPTS:\n\n    TIME_SCHEDULE: \"@daily\"\n    TIME_LOCATION: Asia/Taipei\n\n+   WEBHOOK_URL: https://example.com/webhook\n+   WEBHOOK_INSECURE: \"false\"\n```\n\n## Envionment Variables\n\n### Database Section\n\n- DATABASE_DRIVER - support `postgres`, `mysql` or `mongo`. default is `postgres`\n- DATABASE_USERNAME - database username\n- DATABASE_PASSWORD - database password\n- DATABASE_NAME - database name\n- DATABASE_HOST - database host\n- DATABASE_OPTS - see the `pg_dump`, `mysqldump` or `mongodump` command\n\n### Storage Section\n\n- STORAGE_DRIVER - support `s3` or `disk`. default is `s3`\n- ACCESS_KEY_ID - Minio or AWS S3 ACCESS Key ID\n- SECRET_ACCESS_KEY - Minio or AWS S3 SECRET ACCESS Key\n- STORAGE_ENDPOINT - S3 Endpoint. default is `s3.amazonaws.com`\n- STORAGE_BUCKET - S3 bucket name\n- STORAGE_REGION - S3 Region. default is `ap-northeast-1`\n- STORAGE_PATH - backup folder path in bucket. default is `backup` and all dump file will save in `bucket_name/backup` directory\n- STORAGE_SSL - default is `false`\n- STORAGE_INSECURE_SKIP_VERIFY - default is `false`\n- STORAGE_DAYS - The number of days to keep the backup files. default is `7`\n\n### Schedule Section\n\n- TIME_SCHEDULE - You may use one of several pre-defined schedules in place of a cron expression.\n- TIME_LOCATION - By default, all interpretation and scheduling is done in the machine's local time zone. You can specify a different time zone on construction.\n\n## File Section\n\n- FILE_PREFIX - Prefix name of file, default is `storage driver` name.\n- FILE_SUFFIX - Suffix name of file\n- FILE_FORMAT - Format string of file, default is `20060102150405`.\n\n## Webhook Section\n\n- WEBHOOK_URL - Webhook URL\n- WEBHOOK_INSECURE - default is `false`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappleboy%2Fdocker-backup-database","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fappleboy%2Fdocker-backup-database","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappleboy%2Fdocker-backup-database/lists"}