Bobcares

How to backup databases in DigitalOcean

by | Dec 29, 2018

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.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF