The best way to protect yourself in the event of the loss of your database is to perform regular updates of it. This page will show you how to do this.
To avoid data corruption, and for more flexibility, we will start by exporting the entire contents of your database into a single file by using the mysqldump command.
mysqldump [OPTIONS] database_name [table1, table2,...]
To save a complete database into a file, you need to use the following command via SSH:
mysqldump -u login -p password -h server_name --opt database_name > /srv/mydisk/exportsql/backup_database_name.sql
To save one or several tables into a file use:
mysqldump -u login -p password -h server_name --opt database_name table1_name table2_name > /srv/mydisk/exportsql/backup_table1and2.sql
You can do the same thing but compress the file into gzip for example (so that it takes up less space on your disk):
mysqldump -u login -p password -h server_name --opt database_name | /bin/gzip > /srv/mydisk/exportsql/backup_table1and2.sql
To make the MySQL database export something that is automatically done on a regular basis, you can use the cron command. In this case, just edit "crontab" on your machine via SSH, by adding the process that you want to perform:
The following command opens the crontab file on your server in edit mode:
crontab -e
To launch the export every night at 2AM, for example, you must insert a command like:
# m h dom mon dow command 0 2 * * * mysqldump -u login -p password -h server_name --opt database_name | /bin/gzip > /srv/mydisk/exportsql/database_backup.sql
You can add the directory /srv/mydisk/exportsql to the list of directories monitored by Gsync in order to automatically archive your database to your backup disk
No question on this page and its children.
RSS feed for questions matching this filter (Help)Last modified: 08 Jul 2010 at 11:27 by Ryan A. (Gandi)