
This tutorial describes the steps to properly backup a MySQL/MariaDB server on Ubuntu 20.04 LTS. Backing up databases is one of the most important tasks in production; a human error or a simple distraction could cause big issues, which are not easy to fix if there are no backups.
This guide has been tested on a new Vultr Ubuntu 20.04 LTS cloud server instance.
Log in with a user that has the permissions to see all the databases (default: root) and check the database list.
If it is needed to use a password to login into the account, add -p to the command below.
After the connection is established, run the command below to list all the databases.
Exit the SQL console.
If you use a password to log in to the account, add -p to the command below. If you need to save all the databases, you can use the shortcut --all-databases instead of --databases names.
A file called "database_dump.sql" is created and contains all the data to rebuild the selected databases.
If the data in the database contains sensitive data may be a good idea to encrypt it before saving it or moving it between servers.
Execute the first command below and then type in the password; it won't be shown on your screen.
To decrypt the backup in the new server, use the command below.
Sometimes the .sql may be too large, and the transfer process through a residential internet connection may require too much time. Instead, it is possible to use tools like rsync to share the data directly between servers, taking advantage of the network speed of Vultr instances.
user@ with your username on the remote server. 192.0.2.1 with the remote server's IP address. /tmp/ with the directory location on the remote server.To restore a database dump use the mysql utility.
If you need a password to log in to the account, add -p to the command below before the minus sign.
0 Comments
Be the first to comment and share your perspective with the community.