From 3e424fb522a13d8f07474ea51e643f91938f0a08 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Sun, 13 Feb 2022 23:25:41 +0530 Subject: [PATCH] docs: backup and push (#19) --- docs/backup-and-push-cronjob.md | 120 +++++++++----------------------- 1 file changed, 31 insertions(+), 89 deletions(-) diff --git a/docs/backup-and-push-cronjob.md b/docs/backup-and-push-cronjob.md index aaee4406..ec2f3827 100644 --- a/docs/backup-and-push-cronjob.md +++ b/docs/backup-and-push-cronjob.md @@ -1,105 +1,41 @@ -Install [crazy-max/swarm-cronjob](https://github.com/crazy-max/swarm-cronjob) and then deploy following stack. +Create backup service or stack. ```yaml +# backup-job.yml version: "3.7" - services: backup: - image: frappe/erpnext-worker:version-13 - entrypoint: ["bash", "-c"] - command: ["docker-entrypoint.sh backup; docker-entrypoint.sh push-backup"] - environment: - - WITH_FILES=1 - - BUCKET_NAME=backups - - REGION=region - - ACCESS_KEY_ID=access_id_from_provider - - SECRET_ACCESS_KEY=secret_access_from_provider - - ENDPOINT_URL=https://region.storage-provider.com - - BUCKET_DIR=frappe-bench - volumes: - - "sites-vol:/home/frappe/frappe-bench/sites" - deploy: - labels: - - "swarm.cronjob.enable=true" - - "swarm.cronjob.schedule=0 */3 * * *" - - "swarm.cronjob.skip-running=true" - replicas: 0 - restart_policy: - condition: none - networks: - - frappe-network - -volumes: - sites-vol: - external: true - name: frappe-bench-v12_sites-vol - -networks: - frappe-network: - external: true -``` - -Note: - -- In Above stack, `backup` runs every 3 hours. -- Change image and tag version as per need. -- Change environment variables as per the bucket credentials. -- Change cron string(s) as per need. - -### For docker-compose based installation not using docker swarm - -Add minio - -```yaml -version: "3.7" -services: - minio: - image: minio/minio - command: ["server", "/data"] - environment: - - MINIO_ACCESS_KEY=RANDOMACCESSKEY - - MINIO_SECRET_KEY=RANDOMSECRETKEY - volumes: - - "minio-vol:/data" - networks: - - erpnext-network - # Do not enable, check how to secure minio, out of scope of this project. - #labels: - # - "traefik.enable=true" - # - "traefik.http.routers.minio.rule=Host(`backup.example.com`)" - # - "traefik.http.routers.minio.entrypoints=websecure" - # - "traefik.http.routers.minio.tls.certresolver=myresolver" - # - "traefik.http.services.minio.loadbalancer.server.port=9000" - -networks: - erpnext-network: - external: true - name: _default - -volumes: - minio-vol: -``` - -Create backup service. Create file `backup-job.yml` - -```yaml -version: "3.7" -services: - push-backup: image: frappe/erpnext-worker:v13 entrypoint: ["bash", "-c"] - command: ["docker-entrypoint.sh backup; docker-entrypoint.sh push-backup"] + command: | + for $SITE in $(/home/frappe/frappe-bench/env/bin/python -c "import frappe;print(' '.join(frappe.utils.get_sites()))") + do + bench --site $SITE backup --with-files + push-backup \ + --site $SITE \ + --bucket $BUCKET_NAME \ + --region-name $REGION \ + --endpoint-url $ENDPOINT_URL \ + --aws-access-key-id $ACCESS_KEY_ID \ + --aws-secret-access-key $SECRET_ACCESS_KEY + done environment: - - WITH_FILES=1 - BUCKET_NAME=erpnext - REGION=us-east-1 - ACCESS_KEY_ID=RANDOMACCESSKEY - SECRET_ACCESS_KEY=RANDOMSECRETKEY - - ENDPOINT_URL=http://minio:9000 - - BUCKET_DIR=backups - - BACKUP_LIMIT=8 + - ENDPOINT_URL=https://endpoint.url volumes: - "sites-vol:/home/frappe/frappe-bench/sites" + # Uncomment in case of Docker Swarm with crazy-max/swarm-cronjob + # deploy: + # labels: + # - "swarm.cronjob.enable=true" + # - "swarm.cronjob.schedule=0 */3 * * *" + # - "swarm.cronjob.skip-running=true" + # replicas: 0 + # restart_policy: + # condition: none networks: - erpnext-network @@ -114,8 +50,14 @@ volumes: name: _sites-vol ``` -Add crontab entry for backup every 6 hours +In case of single docker host setup, add crontab entry for backup every 6 hours. ``` 0 */6 * * * /usr/local/bin/docker-compose -f /path/to/backup-job.yml up -d > /dev/null ``` + +Notes: + +- Install [crazy-max/swarm-cronjob](https://github.com/crazy-max/swarm-cronjob) for docker swarm. +- Uncomment `deploy` section in case of usage on docker swarm. +- Change the cron string as per need.