To automatically backup
the MySQL
or MariaDB database daily using MySQLDump, you can follow the steps below:
Create a backup script file
Create a script file (e.g., backup.sh
) to contain the backup commands. Open a text editor and add the following commands to the script file:
Save the script file and ensure it has executable permissions. To do this, run the following command:
Set up an automatic backup job
Use the cron
scheduler to set up a daily automatic backup job. Open the cron schedule by running the command:
Add the following line to the cron schedule file to set up a daily backup job at 2 AM:
Save and close the cron
schedule file.
The backup.sh
script will then be executed daily at 2 AM, and it will backup the MySQL
or MariaDB database to the backup-YYYY-MM-DD.sql
file in the specified directory.
Note that in the script, you need to replace username
, password
, and database_name
with the actual login information and database name. Similarly, change /path/to/backup/directory
to the actual backup storage directory path on your system.