Database backup with cronjob

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

I found the solution:

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

#!/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:

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

3 Likes

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

#!/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

#!/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.

2 Likes

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