# Running neo4j-admin backup from inside docker container on cron interval

**URL:** <https://community.neo4j.com/t/running-neo4j-admin-backup-from-inside-docker-container-on-cron-interval/807>\
**Category:** Docker\
**Tags:** operations\
**Created:** [August 30, 2018, 7:48pm UTC](https://community.neo4j.com/t/running-neo4j-admin-backup-from-inside-docker-container-on-cron-interval/807 "2018-08-30T19:48:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmorley](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mmorley/32/2199_2.png) [@mmorley](https://community.neo4j.com/u/mmorley)\
**Post date:** [August 30, 2018, 7:48pm UTC](https://community.neo4j.com/t/running-neo4j-admin-backup-from-inside-docker-container-on-cron-interval/807/1 "2018-08-30T19:48:48Z")

</div>

Greetings! We are running neo4j using docker in a production environment. We are deriving our own neo4j docker image that encapsulates the plug-ins we are using.

We need to have a backup process using neo4j-admin backup that runs from inside the container on a regular time interval as a cron job.

Ideally this would be configurable from outside container through environmental variables in terms of the specific time the backup was run.

I was wondering if there were any guidance available as to how we might set this up?

Thanks!  
M.

---

<div class="post-metadata">

**Author:** ![david\_allen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/david_allen/32/13090_2.png) [@david\_allen](https://community.neo4j.com/u/david_allen)\
**Post date:** [August 31, 2018, 12:54pm UTC](https://community.neo4j.com/t/running-neo4j-admin-backup-from-inside-docker-container-on-cron-interval/807/2 "2018-08-31T12:54:05Z")

</div>

This post discusses the topic right here:

> [@Scheduling Neo4j Backups while running in Kubernetes](https://community.neo4j.com/t/scheduling-neo4j-backups-while-running-in-kubernetes/627):
>
> I was talking to a customer about this topic earlier today and realized we hadn't written anything up on this, and thought I'd drop a short post here for folks to find as it's relevant. If you're running Neo4j on Kubernetes, either via the Google Kubernetes Marketplace entry, the public helm chart, or other -- you're probably going to have questions about how to do common maintenance operations in Kubernetes. As part of the Google Kubernetes Marketplace offering of Neo4j, we engineered a speci…

It provides a docker container with a sample backup script and talks about how to do backups with docker (here with kubernetes, but not using kubernetes is very similar, if you want to follow up with extra questions).

For the scheduling part -- there are many ways to do this but it matters a lot how you're running docker containers in production. Using kubernetes? Using something like docker cloud? Something else?

---

<div class="post-metadata">

**Author:** ![david\_allen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/david_allen/32/13090_2.png) [@david\_allen](https://community.neo4j.com/u/david_allen)\
**Post date:** [August 31, 2018, 12:55pm UTC](https://community.neo4j.com/t/running-neo4j-admin-backup-from-inside-docker-container-on-cron-interval/807/3 "2018-08-31T12:55:27Z")

</div>

The simplest cron solution (but not the most elegant) is to actually use cron inside of a container. You can write a shell script to deploy the backup container, and then make a very tiny extra container to run cron like this:

[https://www.ekito.fr/people/run-a-cron-job-with-docker/](https://www.ekito.fr/people/run-a-cron-job-with-docker/)

Within most management frameworks though you have better options.

---

<div class="post-metadata">

**Author:** ![mmorley](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mmorley/32/2199_2.png) [@mmorley](https://community.neo4j.com/u/mmorley)\
**Post date:** [August 31, 2018, 1:59pm UTC](https://community.neo4j.com/t/running-neo4j-admin-backup-from-inside-docker-container-on-cron-interval/807/4 "2018-08-31T13:59:54Z")

</div>

Greetings! We are using rancher in the case of the current production installation it's rancher 1.6, for new ones we are moving to rancher 2 which is kunernetes based.

I had looked at the scripting docker container approach - but it seems fragile and inelegant, so was seeking an alternative...

---

<div class="post-metadata">

**Author:** ![markrity](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/markrity/32/1744_2.png) [@markrity](https://community.neo4j.com/u/markrity)\
**Post date:** [October 19, 2018, 6:51pm UTC](https://community.neo4j.com/t/running-neo4j-admin-backup-from-inside-docker-container-on-cron-interval/807/5 "2018-10-19T18:51:49Z")

</div>

> [@mmorley](#):
>
> I had looked at the scripting docker container approach - but it seems fragile and inelegant, so was seeking an alternative...

I wonder if you have found some solution for that ?

---

<div class="post-metadata">

**Author:** ![mmorley](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mmorley/32/2199_2.png) [@mmorley](https://community.neo4j.com/u/mmorley)\
**Post date:** [November 6, 2018, 11:56pm UTC](https://community.neo4j.com/t/running-neo4j-admin-backup-from-inside-docker-container-on-cron-interval/807/6 "2018-11-06T23:56:12Z")

</div>

One way I thought of doign this is cron job from outside container. This works as long as the container name doesn't change:

docker exec CONTAINER NAME --backup-dir=/var/lib/neo4j/backups --name=graph.db-backup --check-consistency=true

---

<div class="post-metadata">

**Author:** ![david\_allen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/david_allen/32/13090_2.png) [@david\_allen](https://community.neo4j.com/u/david_allen)\
**Post date:** [November 7, 2018, 12:50pm UTC](https://community.neo4j.com/t/running-neo4j-admin-backup-from-inside-docker-container-on-cron-interval/807/7 "2018-11-07T12:50:04Z")

</div>

That approach will certainly work.

In the Kubernetes world there's also this:

> **[CronJob](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/)**
>
> FEATURE STATE: Kubernetes v1.21 \[stable\] A CronJob creates Jobs on a repeating schedule.
> CronJob is meant for performing regular scheduled actions such as backups, report generation, and so on. One CronJob object is like one line of a crontab (cron...

I'm afraid the real answer here is that there are a bunch of different ways of doing this, depending on the assumptions about your docker environment, like whether you're doing kubernetes, mesos, running on your local machine, some place remote, whether it's on one big machine or a cluster, etc. etc.

---

<div class="post-metadata">

**Author:** ![david\_allen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/david_allen/32/13090_2.png) [@david\_allen](https://community.neo4j.com/u/david_allen)\
**Post date:** [October 27, 2020, 11:24am UTC](https://community.neo4j.com/t/running-neo4j-admin-backup-from-inside-docker-container-on-cron-interval/807/8 "2020-10-27T11:24:14Z")

</div>

_UPDATE_ - this is now almost 2 years later - but the neo4j-helm backup container has built-in job scheduling. See the jobSchedule argument here:

> **[Backing up Neo4j Containers - Neo4j-Helm User Guide](https://neo4j.com/labs/neo4j-helm/1.0.0/backup/)**
