With the Linux console you can excellent automate the backup of MySQL databases. Prerequisite is an installed MySQL client which can be installed if required.
In the first Part I present a very simple script available which connects to the MySQL database and creates the dump file with a current timestamp in a specified directory.
The timestamp is specified in the example here with the date function and the corresponding date and time format.
1 2 3 4 5 6 7 8 9 10 11 |
#!/bin/sh HOST='ubuntu-blog.info' USER='db-user' PASSWORD='db-password' DATABASE='db-name' FILENAME='backup_blog' BACKUPDATE=$(date +"%Y-%m-%d_%T") BACKUPFILE=$FILENAME"_"$BACKUPDATE".sql" mysqldump -h $HOST -u $USER -p$PASSWORD $DATABASE > $BACKUPFILE |
This script can be executed either automatically when needed as well as a cron job. The dump file will be replayed this in a MySQL database is done in the next part, there is also simply described how to secure its MySQL database from a provider and which records to its local database.