How to Backup MySQL Database to Exoscale Using Bash
Exoscale is a convenient, reliable and cost-effective object storage platform. It allows you to store and manage a large number of files through a web browser and API. It has an S3 Compatible API that can work out of the box with thousands of application data backup tools.
In this post, we will show you how to backup the MySQL database to Exoscale using bash.
Table Of Contents
- Create a Bucket on Exoscale
- Create Exoscale Credentials
- Install S3cmd Tool
- Configure S3cmd to Connect Your Server to Exoscale Bucket
- Use S3cmd to Backup MySQL Database to Exoscale Bucket
- Conclusion
Create a Bucket on Exoscale
First, you will need to create a bucket on Exoscale where you want to store your MySQL database. Follow the below steps to create a bucket.
Step 1 - First, sign in to your Exoscale account.
Step 2 - Click on the STORAGE on the left pane, you should see the following screen:
Step 3 - Click on the ADD button. You should see the bucket creation screen:
Step 4 - Provide your bucker name, choose your Zone and click on the Create button. Once the bucket is created, you should see the following screen:
Create Exoscale Credentials
Next, you will need to create an Exoscale credential to connect your bucket from the remote server. Follow the below steps to create an Exoscale credential:
Step 1 - On the Exoscale dashboard, click on the AMI in the left pane. You should see the following screen:
Step 2 - Click on ADD KEY button. You should see the following screen:
Step 3 - Provide your key name and click on the CREATE button. You should see your created access key and secret key on the following screen:
Install S3cmd Tool
Next, you will need to install the S3cmd tool on your MySQL database server from where you want to back up your MySQL database.
S3cmd is a free and open-source command-line tool that allows you to upload, download and manage data in Exoscale bucket and other cloud storage service providers. Follow the below steps to install the S3cmd to your server.
First, login to your server and install the Python and other dependencies by running the following command:
apt-get install python3 python3-setuptools curl -y
Next, download the latest version of S3cmd using the following command:
curl -LO https://github.com/s3tools/s3cmd/releases/download/v2.2.0/s3cmd-2.2.0.tar.gz
Next, extract the downloaded file with the following command:
tar -xvzf s3cmd-2.2.0.tar.gz
Next, navigate to the extracted directory and install it using the following command:
cd s3cmd-2.2.0python3 setup.py install
Once the S3cmd is installed, verify the S3cmd version using the following command:
s3cmd --version
You will get the following output:
s3cmd version 2.2.0
Configure S3cmd to Connect Your Server to Exoscale Bucket
Next, you will need to configure the S3cmd using the Exoscale Access key and Secret key. You will require the following details to configure S3cmd:
Access Key: FEO2c60fbb123a7c263cc53751d
Secret Key: KhnddL-AA8DpYRG8o_nlnsdngPosi5KfsaoSEdA1s9k
Region: Frankfurt-de-fra-1
S3 Endpoint: sos-de-fra-1.exo.io
host_bucket: %(bucket)s.sos-de-fra-1.exo.io
Next, run the following command to configure S3cmd tool:
s3cmd --configure
You will be asked to provide your Exoscale Access Key, Secret Key, Region, and Endpoint as shown below:
Enter new values or accept defaults in brackets with Enter.Refer to user manual for detailed description of all options. Access key and Secret key are your identifiers for Amazon S3. Leave them empty for using the env variables.Access Key: FEO2c60fbb123a7c263cc53751dSecret Key: KhnddL-AA8DpYRG8o_nlnsdngPosi5KfsaoSEdA1s9kDefault Region [US]: Frankfurt-de-fra-1 Use "s3.amazonaws.com" for S3 Endpoint and not modify it to the target Amazon S3.S3 Endpoint [s3.amazonaws.com]: sos-de-fra-1.exo.io Use "%(bucket)s.s3.amazonaws.com" to the target Amazon S3. "%(bucket)s" and "%(location)s" vars can be usedif the target S3 system supports dns based buckets.DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.s3.amazonaws.com]: %(bucket)s.sos-de-fra-1.exo.io Encryption password is used to protect your files from readingby unauthorized persons while in transfer to S3Encryption password:Path to GPG program: When using secure HTTPS protocol all communication with Amazon S3servers is protected from 3rd party eavesdropping. This method isslower than plain HTTP, and can only be proxied with Python 2.7 or newerUse HTTPS protocol [Yes]: On some networks all internet access must go through a HTTP proxy.Try setting it here if you can't connect to S3 directlyHTTP Proxy server name: New settings:Access Key: FEO2c60fbb123a7c263cc53751dSecret Key: KhnddL-AA8DpYRG8o_nlnsdngPosi5KfsaoSEdA1s9kDefault Region: Frankfurt-de-fra-1S3 Endpoint: sos-de-fra-1.exo.ioDNS-style bucket+hostname:port template for accessing a bucket: %(bucket)s.sos-de-fra-1.exo.ioEncryption password:Path to GPG program: NoneUse HTTPS protocol: TrueHTTP Proxy server name:HTTP Proxy server port: 0 Test access with supplied credentials? [Y/n] YPlease wait, attempting to list all buckets...Success. Your access key and secret key worked fine :-) Now verifying that encryption works...Not configured. Never mind. Save settings? [y/N] yConfiguration saved to '/root/.s3cfg'
Once the S3cmd is configured, you can verify your bucket information using the following command:
s3cmd info s3://mysql-exoscale/
You will get the following output:
s3://mysql-exoscale/ (bucket):Location: de-fra-1Payer: BucketOwnerExpiration Rule: nonePolicy: noneCORS: <?xml version="1.0" encoding="UTF-8"?><CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"></CORSConfiguration>ACL: snapshooter: FULL_CONTROL
Use S3cmd to Backup MySQL Database to Exoscale Bucket
S3cmd is now installed and configured to manage the Exoscale bucket.
Next, log in to the server from where your MySQL server is hosted, then log in to the MySQL using the following command:
mysql -u root -p
Once you are log in, list all MySQL databases using the following command:
MariaDB [(none)]> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sampledb |+--------------------+
Next, create a backup of sampledb database using the following command:
mysqldump -u root -p sampledb > sampledb.sql
To create a backup of all databases, run the following command:
mysqldump -u root -p --all-databases > alldb_backup.sql
Next, run the S3cmd command to copy the alldb_backup.sql backup file to the Exoscale bucket:
s3cmd put alldb_backup.sql s3://mysql-exoscale/
You will get the following output:
upload: 'alldb_backup.sql' -> 's3://mysql-exoscale/alldb_backup.sql' [1 of 1]7340032 of 7340032 100% in 1s 5.77 MB/s doneupload: 'alldb_backup.sql' -> 's3://mysql-exoscale/alldb_backup.sql' [1 of 1]7340032 of 7340032 100% in 0s 13.21 MB/s done
To copy sampledb.sql backup file to Exoscale bucket, run the following command:
s3cmd put sampledb.sql s3://mysql-exoscale/
You will get the following output:
upload: 'sampledb.sql' -> 's3://mysql-exoscale/sampledb.sql' [1 of 1]1048576 of 1048576 100% in 0s 1172.50 KB/s doneupload: 'sampledb.sql' -> 's3://mysql-exoscale/sampledb.sql' [1 of 1]1048576 of 1048576 100% in 0s 3.16 MB/s done
You can now verify all backups on the Exoscale bucket using the following command:
s3cmd ls s3://mysql-exoscale
You will get the following output:
2022-07-28 06:22 7340032 s3://mysql-exoscale/alldb_backup.sql2022-07-28 06:23 1048576 s3://mysql-exoscale/sampledb.sql
You can also log in to the Exoscale and verify your MySQL backup files as shown below:
Conclusion
In this post, we showed you how to backup the MySQL database to Exoscale using bash. You can now easily backup and manage your MySQL database from your server using bash.
Scheduled MySQL Single Databases Backups SnapShooter
Backup a single MySQL database to your external storage
Learn more about MySQL Single Databases Backups
Get started for freeRelated
Thank you for helping us improve!