# Help troubleshooting cronjob to automate database backup

**URL:** <https://community.vikunja.io/t/help-troubleshooting-cronjob-to-automate-database-backup/505>\
**Category:** Support\
**Created:** [9 December 2021 14:24 UTC](https://community.vikunja.io/t/help-troubleshooting-cronjob-to-automate-database-backup/505 "2021-12-09T14:24:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![heeep](https://community.vikunja.io/letter_avatar_proxy/v4/letter/h/d6d6ee/32.png) [@heeep](https://community.vikunja.io/u/heeep)\
**Post date:** [9 December 2021 14:24 UTC](https://community.vikunja.io/t/help-troubleshooting-cronjob-to-automate-database-backup/505/1 "2021-12-09T14:24:22Z")

</div>

Hello,

I set up a cronjob by running the command **crontab -e** and inserting this command

**0 \* \* \* \* docker-compose exec db mysqldump -u vikunja -pPASSWORDGOESHERE vikunja \> backup.sql**

I also tried, but the behavior is the same

**0 \* \* \* \* sudo docker-compose exec db mysqldump -u vikunja -pPASSWORDGOESHERE vikunja \> backup.sql**

The cronjob appears to run successfully because **backup.sql** is being created, but it has size of 0.  
If I manually run the command, the **backup.sql** much larger.

I am sure this is something simple, but it is my first time setting up cronjobs,so any help would be appreciated. Thank you!

something to note is that when I run the command manually I do **sudo** before the command

I’m on Ubuntu 20.04.3 LTS

---

<div class="post-metadata">

**Author:** ![kolaente](https://community.vikunja.io/user_avatar/community.vikunja.io/kolaente/32/5_2.png) [@kolaente](https://community.vikunja.io/u/kolaente)\
**Post date:** [10 December 2021 18:41 UTC](https://community.vikunja.io/t/help-troubleshooting-cronjob-to-automate-database-backup/505/2 "2021-12-10T18:41:28Z")

</div>

I think that’s because you don’t have a folder set. The `docker-compose` command does not know what compose stack you’re referring to and fails. I’d use the full name of the container (From `docker ps`) and run it with a plain `docker` command. Something like this:

```auto
0 * * * * docker exec vikunja_db mysqldump -u vikunja -pPASSWORDGOESHERE vikunja > /path/to/backups/backup.sql

```

The `backup.sql` file is empty because the error output is going to stderr but you’re only piping stdout to the file. Check out this article for information about how to change that: [https://linuxize.com/post/bash-redirect-stderr-stdout/](https://linuxize.com/post/bash-redirect-stderr-stdout/)

If you’re looking for a simple solution to create backups, you might be interested in this thing I recently built: [konrad/docker-db-backup - docker-db-backup - Gitea](https://kolaente.dev/konrad/docker-db-backup)

---

<div class="post-metadata">

**Author:** ![heeep](https://community.vikunja.io/letter_avatar_proxy/v4/letter/h/d6d6ee/32.png) [@heeep](https://community.vikunja.io/u/heeep)\
**Post date:** [17 December 2021 20:07 UTC](https://community.vikunja.io/t/help-troubleshooting-cronjob-to-automate-database-backup/505/3 "2021-12-17T20:07:04Z")

</div>

> [@kolaente](#):
>
> `docker exec vikunja_db mysqldump -u vikunja -pPASSWORDGOESHERE vikunja > /path/to/backups/backup.sql`

That worked, thanks for your help. I will also be checking out your script when I get a bit more time. Thanks!
