Local backups of dockerized install

After executing docker exec -it container-name bash and bench --site <sitename> backup --with-files I got:

frappe@e2f0cfa4c092:~/frappe-bench/sites$ bench --site mysite.localhost backup --with-files
Backup Summary for mysite.localhost at 2021-09-21 08:36:52.947017
Config : ./mysite.localhost/private/backups/20210921_083638-mysite_localhost-site_config_backup.json 266.0B
Database: ./mysite.localhost/private/backups/20210921_083638-mysite_localhost-database.sql.gz 2.2MiB
Public : ./mysite.localhost/private/backups/20210921_083638-mysite_localhost-files.tar 10.0KiB
Private : ./mysite.localhost/private/backups/20210921_083638-mysite_localhost-private-files.tar 56.4MiB
Backup for Site mysite.localhost has been successfully completed with files

the backups are in sites-vol.

they are under {{site_name}}/private/backups for each site.

frappe@e2f0cfa4c092:~/frappe-bench/sites/mysite.localhost/private/backups$ ls
20210920_161910-mysite_localhost-database.sql.gz 20210920_161910-mysite_localhost-site_config_backup.json 20210921_083638-mysite_localhost-private-files.tar
20210920_161910-mysite_localhost-files.tar 20210921_083638-mysite_localhost-database.sql.gz 20210921_083638-mysite_localhost-site_config_backup.json
20210920_161910-mysite_localhost-private-files.tar 20210921_083638-mysite_localhost-files.tar

I just didn’t know what to do with these, but now it made sense when it was reformatted.

It worked and 0 */6 * * * cd /home/francois && /usr/local/bin/bench --site all backup >> /home/francois/logs/backup.log 2>&1 should backup to the {{site_name}}/private/backups directory.

I used bench restore to find the restore commands. Although I couldn’t find the command to use for restoring site_config.json

frappe@e2f0cfa4c092:~/frappe-bench/sites$ bench --site mysite.localhost restore ./mysite.localhost/private/backups/20210921_104636-mysite_localhost-database.sql.gz --with-public-files ./mysite.localhost/private/backups/20210921_104636-mysite_localhost-files.tar --with-private-files ./mysite.localhost/private/backups/20210921_104636-mysite_localhost-private-files.tar
MySQL root password:
*** Scheduler is enabled ***
Site mysite.localhost has been restored with files

1 Like

if you need containerized cronjob check following link

There is no way to restore site_config. It is backed up so you don’t lose the secrets stored in the file. like the encryption_key. You’ll have to manually add your secrets to the site_config

1 Like

This seems to be what I need. I just don’t have the expertise to modify it so that it backs up to my local disk.

I know now how to do the process manually. I think that configuring a regular cron-job to do the same actions automatically would be more than enough.

How long would those backups under {{site_name}}/private/backups remain there? I know that ERPNext has an option to configure the number of backups. Do those settings apply to backups that weren’t made by ERPNext?

Something like this although this doesn’t work for some reason.

/usr/bin/docker exec -it e2f0cfa4c092 bash && bench --site mysite.localhost backup --with-files && docker cp e2f0cfa4c092:./mysite.localhost/priva
te/backups/ /home/francois/backups

you can do lot of things with that docker-compose

  1. mount a local directory as volume in container
  2. expand the command: [...] section to run multiple commands that take backup first and then copy them to the mounted vol/directory

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: <your_frappe_docker_project_name>_default

volumes:
minio-vol:

I created a stack with the above content.
All I changed was the random keys and the <your_frappe_docker_project_name> to the name that I used for the ERPNext stack.

version: "3.7"
services:
  push-backup:
    image: frappe/erpnext-worker:v13
    entrypoint: ["bash", "-c"]
    command: ["docker-entrypoint.sh backup; docker-entrypoint.sh push-backup"]
    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
    volumes:
      - "sites-vol:/home/frappe/frappe-bench/sites"
    networks:
      - erpnext-network

networks:
  erpnext-network:
    external: true
    name: <your_frappe_docker_project_name>_default

volumes:
  sites-vol:
    external: true
    name: <your_frappe_docker_project_name>_sites-vol

Where should I save the backup-job.yml file?

try like this, edit the scripts as per your need, you can even use custom script instead of existing method

version: "3.7"
services:
  push-backup:
    image: frappe/erpnext-worker:v13.11.1
    entrypoint: ["bash", "-c"]
    command: > 
      docker-entrypoint.sh backup;
      mv ./mysite.localhost/private/backups/* /home/frappe/backups;
    # command: ["/opt/custom.sh"]
    environment:
      - WITH_FILES=1
    volumes:
      - "sites-vol:/home/frappe/frappe-bench/sites"
      - ./backups:/home/frappe/backups
      # - /custom/executable/script/to/run.sh/:/opt/custom.sh
    networks:
      - erpnext-network

networks:
  erpnext-network:
    external: true
    name: <your_frappe_docker_project_name>_default

volumes:
  sites-vol:
    external: true
    name: <your_frappe_docker_project_name>_sites-vol
francois@francois-pc:~$ /usr/local/bin/docker-compose -f /media/francois/Storage/Documents/backup-job.yml start > /dev/null
Starting push-backup ... failed
ERROR: No containers to start
ERROR: 1

for docker-compose start to work the project’s containers must be first created.

docker-compose up -d will create the containers. Once containers are create they can be started.

francois@francois-pc:/media/francois/Storage/Documents$ docker-compose up -d
Creating documents_push-backup_1 ... done

check the backups directory now.

You need to understand volumes in docker-compose, check docs.

the yml mounts ./backups:/home/frappe/backups

the script takes backup and moves the files to this mounted directory.

The backups should be available in ./backups directory

Think I should find another way to backup ERPNext data.
I don’t know bash nor Docker.

Hey @revant_one ,

I have a similar setup using the steps described here: Installing the Docker image on a local machine without Letsencrypt so we can access it with http://localhost

I’d like to have backups of my erpnext instance.
The volumes used by the docker-compose are these 4 I believe:

  • frappe_docker_assets → seem to be the css/js etc. for the site, no need to back it up ?
  • frappe_docker_db-data → the mysql data, to be backed up every time I guess ?
  • frappe_docker_redis-data → afaik redis is only cache stuff right ? I guess I can ignore ?
  • frappe_docker_sites → the sites data, can I only back this up once ? as the data shouldn’t change right ?

When restoring, can I just follow the regular docker-compose up etc., and then once my containers are running simply replace the two volumes I backed up (in case I only back up frappe_docker_db-data and frappe_docker_sites) ?

Last but not least @francois072 if you use Docker Desktop, and if @revant_one confirms what I said earlier, you can just download the “Volumes Backup & Share” extension which allows to backup and replace docker volumes very easily. If this works, then the backing up becomes a breeze !

Thanks again for the support, and happy holidays.
Zauber.

sites and db-data are the volumes to be backed up.

if you depend on volume backups, you can explore alternatives for snapshots.

or you can use this built in bench backup command. frappe_docker/backup-and-push-cronjob.md at main · frappe/frappe_docker · GitHub