{"id":3929,"date":"2023-11-24T11:36:22","date_gmt":"2023-11-24T03:36:22","guid":{"rendered":"https:\/\/www.servergigabit.com\/guide\/?post_type=kb&#038;p=3929"},"modified":"2026-03-16T09:45:01","modified_gmt":"2026-03-16T01:45:01","slug":"7-steps-backup-mysql-data-object","status":"publish","type":"kb","link":"https:\/\/www.servergigabit.com\/guide\/kb\/7-steps-backup-mysql-data-object","title":{"rendered":"7 Easy Steps to Backup MySQL Database to Object Storage"},"content":{"rendered":"<div class=\"markdown markdown-main-panel\" dir=\"ltr\">\n<p data-sourcepos=\"3:1-3:62\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-3930\" src=\"https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/45-300x169.jpeg\" alt=\"MySQL Data\" width=\"769\" height=\"433\" srcset=\"https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/45-300x169.jpeg 300w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/45-1024x576.jpeg 1024w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/45-768x432.jpeg 768w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/45-1536x864.jpeg 1536w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/45-2048x1152.jpeg 2048w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/45-370x208.jpeg 370w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/45-1230x692.jpeg 1230w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/45-800x450.jpeg 800w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/45-390x219.jpeg 390w\" sizes=\"(max-width: 769px) 100vw, 769px\" \/><\/p>\n<p data-sourcepos=\"5:1-5:393\">In the realm of data management, protecting your valuable <a href=\"https:\/\/www.mysql.com\/\" rel=\"nofollow noopener\" target=\"_blank\">MySQL<\/a> databases is of paramount importance. Regular backups serve as a crucial line of defense against data loss, ensuring that your MySQL databases remain resilient in the face of unforeseen events. Object Storage, with its remarkable scalability and cost-effectiveness, has emerged as a favored destination for storing these backups.<\/p>\n<p data-sourcepos=\"7:1-7:256\">This comprehensive guide will delve into the process of backing up your MySQL database to object storage using the command line. The ease of configuration and S3-compatibility of object storage make it a compelling choice for securely storing your backups.<\/p>\n<h2 data-sourcepos=\"9:1-9:37\"><strong>Prerequisites for Backup Success<\/strong><\/h2>\n<p data-sourcepos=\"11:1-11:87\">To embark on this backup journey, ensure you have the following prerequisites in place:<\/p>\n<ol data-sourcepos=\"13:1-20:0\">\n<li data-sourcepos=\"13:1-14:0\">\n<p data-sourcepos=\"13:4-13:73\"><strong>Object Storage:<\/strong> Access to an S3-compatible object storage service.<\/p>\n<\/li>\n<li data-sourcepos=\"15:1-16:0\">\n<p data-sourcepos=\"15:4-15:113\"><strong>Access Key and Secret Key:<\/strong> Obtain your unique access key and secret key from your object storage provider.<\/p>\n<\/li>\n<li data-sourcepos=\"17:1-18:0\">\n<p data-sourcepos=\"17:4-17:74\"><strong>S3 URL:<\/strong> Locate the S3 URL provided by your object storage provider.<\/p>\n<\/li>\n<li data-sourcepos=\"19:1-20:0\">\n<p data-sourcepos=\"19:4-19:134\"><strong>AWS CLI Installation:<\/strong> Install and configure the AWS Command Line Interface (AWS CLI) on the server hosting your MySQL database.<\/p>\n<\/li>\n<\/ol>\n<h2 data-sourcepos=\"21:1-21:31\"><strong>Creating a Database Backup<\/strong><\/h2>\n<p data-sourcepos=\"23:1-23:165\">Before transferring your backup to object storage, it&#8217;s essential to generate a local backup. Fortunately, MySQL provides a built-in command to accomplish this task:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container\" role=\"text\">mysqldump \u2013u [username] -p[password] [database_name] &gt; backup.sql\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"29:1-29:53\">Replace the placeholders with the appropriate values:<\/p>\n<ul data-sourcepos=\"31:1-38:0\">\n<li data-sourcepos=\"31:1-32:0\">\n<p data-sourcepos=\"31:3-31:59\"><code>[username]<\/code>: Your login username for the MySQL instance.<\/p>\n<\/li>\n<li data-sourcepos=\"33:1-34:0\">\n<p data-sourcepos=\"33:3-33:59\"><code>[password]<\/code>: Your login password for the MySQL instance.<\/p>\n<\/li>\n<li data-sourcepos=\"35:1-36:0\">\n<p data-sourcepos=\"35:3-35:66\"><code>[database_name]<\/code>: The name of the database you want to back up.<\/p>\n<\/li>\n<li data-sourcepos=\"37:1-38:0\">\n<p data-sourcepos=\"37:3-37:82\"><code>backup.sql<\/code>: The name of your backup file. You can change this name if desired.<\/p>\n<\/li>\n<\/ul>\n<h2 data-sourcepos=\"39:1-39:35\"><strong>Uploading Your Database Backup<\/strong><\/h2>\n<p data-sourcepos=\"41:1-41:110\">Once you&#8217;ve successfully created a local backup, it&#8217;s time to transfer it to object storage using the AWS CLI:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container\" role=\"text\">aws --profile eu2 --region default --endpoint-url [your_s3_url] s3 cp [name_of_your_backup_file] s3:\/\/[bucket_name]\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"47:1-47:53\">Replace the placeholders with the appropriate values:<\/p>\n<ul data-sourcepos=\"49:1-52:0\">\n<li data-sourcepos=\"49:1-50:0\">\n<p data-sourcepos=\"49:3-49:72\"><code>[name_of_your_backup_file]<\/code>: The name of the backup file you created.<\/p>\n<\/li>\n<li data-sourcepos=\"51:1-52:0\">\n<p data-sourcepos=\"51:3-51:100\"><code>[bucket_name]<\/code>: The name of the bucket in your object storage where you want to store the backup.<\/p>\n<\/li>\n<\/ul>\n<h2 data-sourcepos=\"53:1-53:31\"><strong>Scheduling Regular Backups<\/strong><\/h2>\n<p data-sourcepos=\"55:1-55:118\">Regular backups are crucial for maintaining a robust data protection strategy. To automate this process, utilize Cron:<\/p>\n<h4><strong>1. Create a Shell Script:<\/strong><\/h4>\n<p data-sourcepos=\"59:1-59:87\">Create a shell script that generates a local backup and transfers it to object storage:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container\" role=\"text\"><span class=\"hljs-meta\">#!\/bin\/bash<\/span>\r\n\r\nmysqldump \u2013u [username] -p[password] [database_name] &gt; backup.sql\r\n\r\naws --profile eu2 --region default --endpoint-url [your_s3_url] s3 cp [name_of_your_backup_file] s3:\/\/[bucket_name]\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"69:1-69:53\">Replace the placeholders with the appropriate values.<\/p>\n<p data-sourcepos=\"71:1-71:62\">Save the script as &#8220;database-to-os.sh&#8221; and make it executable:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container\" role=\"text\">chmod +x database-to-os.sh\r\n<\/code><\/pre>\n<\/div>\n<h4><strong>2. Edit the Crontab File:<\/strong><\/h4>\n<p data-sourcepos=\"79:1-79:52\">Open the Crontab file to schedule the backup script:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container\" role=\"text\">crontab -e\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"85:1-85:77\">Add the following line to schedule the backup script to run daily at 3:00 AM:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">0 3 * * * \/[path_to_script]\/database-to-os.sh\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"91:1-91:22\">Save the Crontab file.<\/p>\n<h2 data-sourcepos=\"93:1-93:15\"><strong>Conclusion<\/strong><\/h2>\n<p data-sourcepos=\"95:1-95:412\">By leveraging the AWS CLI and the provided commands, you can seamlessly back up your MySQL databases to object storage, ensuring the security and integrity of your valuable data. Regular backups provide a safeguard against data loss, offering peace of mind and enabling you to focus on your business objectives. Embrace the power of object storage and safeguard your valuable MySQL data with ease and efficiency.<\/p>\n<\/div>\n<p data-sourcepos=\"95:1-95:412\">\n","protected":false},"excerpt":{"rendered":"<p>In the realm of data management, protecting your valuable MySQL databases is of paramount importance. Regular backups serve as a crucial line of defense against data loss, ensuring that your MySQL databases remain resilient in the face of unforeseen events. Object Storage, with its remarkable scalability and cost-effectiveness, has emerged as a favored destination for storing these backups. This comprehensive&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"kbtopic":[1099],"kbtag":[1121,1117],"class_list":["post-3929","kb","type-kb","status-publish","hentry","kbtopic-tutorials","kbtag-mysql-data","kbtag-object-storage"],"_links":{"self":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/3929","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/types\/kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/comments?post=3929"}],"version-history":[{"count":6,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/3929\/revisions"}],"predecessor-version":[{"id":6266,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/3929\/revisions\/6266"}],"wp:attachment":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/media?parent=3929"}],"wp:term":[{"taxonomy":"kbtopic","embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kbtopic?post=3929"},{"taxonomy":"kbtag","embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kbtag?post=3929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}