Databases are really critical for the proper working of websites.
These databases undergo frequent read, write of data and can easily become corrupt. Therefore, it is important to have a proper database backup for data recovery.
At Bobcares, we help DigitalOcean server owners with periodic database backup as part of our Managed Cloud Services.
Today, let’s discuss the different ways to backup database in DigitalOcean Droplets and how we fix the common errors with it.
How to take Database backup in DigitalOcean?
Database backup comes handy during any unexpected website crash. That’s why, it is really important to have a clear plan on when and how to backup website databases.
Although, there are multiple ways to backup databases, our Cloud Engineers suggest backup methods based on the server environment, website type, etc.
Now let’s have a look at the different methods for database backup.
1. Using Command-line Mysqldump
One of the common ways to do database backup via command-line is using the mysqldump utility. In a DigitalOcean Droplet, this command is invoked from the shell prompt as the ‘root’ user.
To take the backup of a single database, our Engineers use the following command.
mysqldump -u username -p database_to_backup > backup_name.sql
Then, it prompts for MySQL user password. And, we have the database backup available at backup_name.sql
However, when there are multiple databases, taking backup manually becomes a tedious process. In such a scenario, our Cloud Engineers set up database backup script that takes dump of all databases. Here, we specify the MySQL password in the file /root/.my.cnf. Then, we export these backup files to a remote location.
Again, we schedule this via cron jobs. The frequency of the backup task depends on type of data too.
For instance, when one of our customers contacted us for backup up plan for his auction website, we set up backup task that runs twice daily. Thus, we could save all the frequent changes in databases at a remote location.
2. Using backup tools
Similarly, we can take backup of databases using utilities like Automysqlbackup, Percona XtraBackup backup tools, etc. too.
To setup backup in Ubuntu servers, we can easily install “automysqlbackup“. For further configuration, we edit the file at /etc/default/automysqlbackup.
Again, when there is a need for backups of MySQL data while the system is running, our Cloud Engineers often recommend Percona XtraBackup backup tool. This tool copies the data files at the filesystem level.
[Do you have critical databases in your Droplet ? We can set up scheduled database backup for you.]
Top errors with Database backup in DigitalOcean
With our expertise in managing DigitalOcean Droplets, we often see errors with backup process too. Let’s have a quick look at them.
1. mysqldump: Got error: 1045: Access denied for user
At times, while using mysqldump, we see the error with access restrictions. The exact error on the Droplet was:
mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect
Here, the root user was not able to connect and the database backup was failing.
On further analysis, we found that the password used was correct. But, the privileges of the user was not correct. So, to fix the problem, our Cloud Engineers had to grant proper privileges to the root user on the databases.
Additionally, we set the MySQL root password in the /root/.my.cnf file too.
2. AutoMYSQLBackup cannot encrypt database backup
Another error that we noticed in a DigitalOcean Droplet was that AutoMYSQLBackup was not able to encrypt database backup.
Here, our Support Engineers had to upgrade the AutoMYSQLBackup utility on the server first. Then, we edited the file /etc/default/automysqlbackup and made these changes.
# Do you wish to encrypt your backups using openssl?
CONFIG_encrypt='yes'
# Choose a password to encrypt the backups.
CONFIG_encrypt_password='$YOUR_PASSWORD'
Then the backups started working perfectly.
Conclusion
Enabling database backups in DigitalOcean Droplets can be done manually or using backup tools. But at times, things can go wrong with the database backup. Today, we saw the different ways to backup databases and how our Cloud Engineers fix the common errors with backup process.
0 Comments