Skip to content
DigitalBox98 edited this page Sep 19, 2021 · 41 revisions

It's important to backup on a regular basis your MariaDB database.

On Windows10

On Linux

You can use the "mysqldump" command and put it in a shell script named "backup_dol_db.sh" :

#!/usr/bin/env bash
mysqldump --user=root --password=mypass --lock-tables --databases dol >/data/backup/dol_``date '+%u'``.sql

Note : replace `` by `

The above script will save the entire DB in a SQL file suffixed by the day number (1=monday to 7=sunday), so that you can have archive files on a 7 days basis.

If you need to restore the DB, you just need to use the corresponding backup file :

mysql -u root -p -b dol </data/backup/dol_backup_1.sql

Here the DB archive corresponding to monday is used to restore the database

In order to automatisme the launch of the script, you will need to use "crontab" command.

Edit the crontab tasks with the below command :

sudo crontab -e

Edit the file and add the below line at the end of the file :

0 1 * * * /home/myuser/dol_tools/backup_dol_db.sh

Where the syntax is :
.---------------- minute (0 - 59)
| .------------- hour (0 - 23)
| | .---------- day of month (1 - 31)
| | | .------- month (1 - 12) OR jan,feb,mar,apr ...
| | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
| | | | |
* * * * * user command to be executed

In the above example "backup_dol_db.sh" will be called every day at 1:00 AM in order to perform the dump.

To finalize the crontab, save the edited file :)

On MacOS