ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

Local backups of dockerized install

I have ERPNext installed on KDE Neon via Docker. I have an external HDD which I use for backups via Vorta. How should I configure my backups in such a way that I can easily restore the ERPNext settings and the database on another system?

check this if it helps https://github.com/frappe/frappe_docker/wiki/Backup-and-Push-to-cloud-Cron-job

check this for site operations related to backup and restore https://github.com/frappe/frappe_docker/blob/develop/docs/site-operations.md#restore-backups

These links have what I want, but I have no idea what to do with the information. It’s my first time using Docker, ERPNext and Frappe.

Are there any GUI options to create local backups? I found Portainer and thought that might work.

portainer just gives you gui to manage docker swarm. You will still use the same Yaml files that are used without portainer. You can’t escape learning docker if you’re planning to use it.

sharing again : https://github.com/frappe/frappe_docker/wiki/Backup-and-Push-to-cloud-Cron-job

This link contains stacks to setup cronjob on docker swarm. Add the stack using portainer ui or docker cli.

Thanks I’ll look into it further.

What do I actually need to backup? I read up on the difference between containers, volumes and images, but I’m not sure if I need to backup the volumes or containers.

For frappe/erpnext you need to backup

  • database dump
  • private files, public files and site_config.json files (the sites volume, sites-vol)

No need to backup containers. Only backup volumes.

This looks like it may be helpful.

The guide seems easy enough, but I can’t figure out how to ssh into my ERPNext installation at mysite.localhost.

If I can get this to work I might be able to get a script somewhere to perform the actions automatically.

The guide is not related to dockerized setup.

to enter any container use

docker exec -it container-name bash

replace container name with erpnext-python container to exec into it and use bench_helper commands.

With docker, script should be written like the cron jobs examples shared before. scripts are additional containers that run and complete.

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 https://frappeframework.com/docs/user/en/bench/reference/restore#options 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

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

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?