# Database backup with cronjob

**URL:** <https://forum.mautic.org/t/database-backup-with-cronjob/29526>\
**Category:** Product Support\
**Created:** [October 3, 2023, 12:05pm UTC](https://forum.mautic.org/t/database-backup-with-cronjob/29526 "2023-10-03T12:05:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan-franz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/stefan-franz/32/12758_2.png) [@stefan-franz](https://forum.mautic.org/u/stefan-franz)\
**Post date:** [October 3, 2023, 12:05pm UTC](https://forum.mautic.org/t/database-backup-with-cronjob/29526/1 "2023-10-03T12:05:37Z")

</div>

**Your software**  
My Mautic version is: 4.4.10  
My PHP version is: 8.0.30  
My Database type and version is: 10.6

First, i have a daily backup of my server with metzner. So i don’t know, of i need an additional backup…but i’m a security focused user…

Is it possible to make every day automatically a database backup with cron job an delete older than e.g. 1 month automatically somehow?  
I would it save to /home/backup as a .zip file.

I found here a description - but i’m a bit new so i’m not shure hot the synthax for the cron job is really right

> **[Back Up and Restore MariaDB Databases From the Command line - LinuxBabe](https://www.linuxbabe.com/mariadb/how-to-back-up-mariadb-databases-from-the-command-line)**
>
> MariaDB is a community-driven variant of MySQL. In this tutorial, I will show you how to back up and restore MariaDB databases using the mysqldump utility. mysqldump mysqldump is the utility that we will use to back up our MariaDB database. It’s...

---

<div class="post-metadata">

**Author:** ![stefan-franz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/stefan-franz/32/12758_2.png) [@stefan-franz](https://forum.mautic.org/u/stefan-franz)\
**Post date:** [October 4, 2023, 11:32am UTC](https://forum.mautic.org/t/database-backup-with-cronjob/29526/2 "2023-10-04T11:32:07Z")

</div>

I found the solution:

For backup database every day to /home/backups i made a script:  
`mysqldump.sh`

```auto
#!/bin/sh
mysqldump -p'myrootpassword' -u root databasename > /home/backups/mautic-database-$(date +%Y%m%d-%H%M%S).sql
find /home/backups -iname mautic-database* -mtime +30 -delete

```

and in the crontab that entry of the script:

```auto
0 4 * * * /home/backups/mysqldump.sh

```

What it does:  
Start the script every day at 4 o’clock and  
Backup the database and append date and time  
Delete Backups older than 30 days

---

<div class="post-metadata">

**Author:** ![stefan-franz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/stefan-franz/32/12758_2.png) [@stefan-franz](https://forum.mautic.org/u/stefan-franz)\
**Post date:** [October 5, 2023, 4:50am UTC](https://forum.mautic.org/t/database-backup-with-cronjob/29526/3 "2023-10-05T04:50:42Z")

</div>

Additional version of a script: To make a compress the database the command is:

```auto
#!/bin/sh
mysqldump -p'myrootpassword' -u root mautic | gzip > /home/backups/mautic-database-$(date +%Y%m%d-%H%M%S).sql.gz

```

And to save the Mautic directory and compress

```auto
#!/bin/sh
zip -r /home/backups/mautic_full-$(date +%Y%m%d-%H%M%S).sql.zip /var/www/html/mautic

```

Refer to this, to decide what to save.

> **[Mautic Backup for Dummies & Marketers too | Mauteam.org](https://mauteam.org/mautic/mautic-admins/mautic-backup-for-dummies-marketers-too/)**
>
> There's much more to making backups than just copying files, as you probably know, you need a backup strategy. In this post, I'm not going to enter in detail on the strategic part. Anyway, I'

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/1X/43c63600fe51440378769136903f1fa2a9a34102.png) [@system](https://forum.mautic.org/u/system)\
**Post date:** [October 6, 2023, 4:51pm UTC](https://forum.mautic.org/t/database-backup-with-cronjob/29526/4 "2023-10-06T16:51:00Z")

</div>

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.
