How to take backup of erpnext using crontab in a docker? The bench command is working but it does not execute it from crontab? Any solution?
you cant run a cronjob inside a container, but you can on the host running docker.
then you can just pass it a command docker exec -i frappecontainername cmd
* * * * docker exec -i sugarcrm_sugarcrm_1 sudo -u www-data php -f /var/www/html/cron.php > /dev/null 2>&1
Above is an example from our docker host, that runs a sugarcrm php page for example
@cjpit has it right. You should run commands from the host.
You could:
- Backup the entire Volume or Bind Mount.
- Run mysqldump
- Use âdocker execâ to run commands inside the container. Maybe you want to rsync directories, or run mariabackup
That is why I wanted to setup a ERPNext docker configuration with the database out on the underlying host. This way it is easy to use the 'mysqldump" command to backup as often as you want.
Unfortunately this also then requires that the âŚ/private/files and âŚ/public/files directories also need to be kept out on the underlying host as well.
BKM
Technically, itâs all on the host anyway. If you run MariaDB inside of docker, then your database files are either in a Volume (which is on your host). Or mapped using a Bind Mount (which points at your host).
To run âmysqldumpâ against a Docker MariaDB, you would just do something like this:
$ docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
Yeah, but that still puts the resulting file in another volume somewhere and not out where you can use simple tools like crontab to manipulate them.
For example: You cannot easily run âscpâ from within docker to move files from one physical host to another backup host.
BKM
No, the resulting backup file is on your laptop. Or wherever you called âdocker execâ from.
In docker we run the command by going to folder âfrappe_dockerâ and the command is âsudo ./dbench backupâ, so why canât I run this command in crontabs? It works normally why not with crons? I donât need to call crons from inside the container
Docker is not the same as a virtual machine. Cron is not running automatically in the background. You have to manually start it.
So itâs possible to run cron jobs from a docker container. Itâs just not recommended. Iâve included a few links:
How to run a cron job inside a docker container? - Stack Overflow
How to install/run Cron in a Docker Container ¡ GitHub
The best option is to use your hostâs cron. And add âdocker exec âŚâ commands.
But I am using the host machine crontab and running the command that I mentioned above not the containerâs crontab.
Can you show the crontab line?
What happens if you execute the command just using a terminal?
Normally running the command created the backup folder but If I run this command from crontab it doesnât do anything even it shows in cronjobs list
-
-
-
-
- cd ~/frappe_docker & sudo ./dbench backup
-
-
-
It still looks like your running it inside of the container, which wonât work.
really? that would result into not being ablke to âtransportâ such cronjobs with any given container (docker, lxc, âŚ) can you explain what the benefit from running this from your container host?
⌠Now as I am thinking of it. Maybe it is (not that much a matter on lxd container which may be more equal to a VM then a docker container) that you would loose the cronjob once you update.or re-run/rebuild the docker container?
Yes, LXD containers are most similar to virtual machines.
Docker containers are different.
- They donât have hardware virtualization, a hypervisor, or a boot & init system.
- They donât have a complete operating system.
- They are tightly integrated with the Host.
- Their data and storage is not persistent. Each time you start a Docker container, it launches from scratch. It does not remember anything from the last time it was run. (exceptions â any files you map to a Volume or Bind Mount)
Docker containers are intended to run just 1 service each.
- MariaDB: Thatâs 1 docker container.
- Redis: Thatâs 1 more docker container.
- Nginx: Another docker container.
- SMTP: Another docker container.
- MongoDB: Another docker container.
- etc.
You can launch them together (Docker Compose). You can link them together (IP address, Docker Swarm). But they are designed to perform 1 service, each.
Can you make them do 2+ services? Yes. But thatâs not what they were designed for.
Dockerâs purpose is to virtualize a service. Example:
- I can run my MariaDB in complete isolation.
- Nothing I do on my laptop/servers will ever impact MariaDB Docker.
- Nothing I do in MariaDB Docker will ever touch my host operating system or files.
- I can upgrade from MariaDB v10 to v11 by replacing my container. And be 100% confident that I have not changed anything on my host, or its services.
- I can start/stop a container in 1-2 seconds.
- They are tiny. Alpine Linux = 5 megabytes. Nginx Reverse Proxy = 15 megabytes. MariaDB = 300 megabytes.
This is very different from a Virtual Machine. On a VM, all the applications are running together. Sharing virtual disks. Sharing files. Sharing libraries, dependencies, IP addresses, sockets, etc.