Backup and Restore MySQL databases through Jump servers

The import of MySQL databases using backup files is supported by Amazon RDS. You can back up your database, save it on Amazon S3, and then use that backup file to restore your database onto a fresh Amazon RDS DB instance running MySQL. The databases can be backed up and restored using this method if the VPC (virtual private cloud) is different and unable to peer both bastion servers.

You can connect to your RDS instances that are located in several VPCs using leap servers or bastion servers by using the method described below.

Step1:
Connect to the Instance where your database resides. Take a backup.

mysqldump –no-create-db mydbName –single-transaction –compress –host myInstance.rds.amazonaws.com -u myUserName -pMyPassword > MyBackupFile.sql

Step2:
Move the backup file to S3

aws s3  mv  MyBackupFile.sql   s3://backup.folder/dbbackups2023/

Step3:
Connect to the instance where you want the database to be restored.

Step4:

Either you can copy the backup file from S3 to the local instance for a faster restoration process. Or you can simply use the file from S3.

Restore from S3

mysql -u myUserName -pMyPassword DBName < aws s3 cp s3://backup.folder/dbbackups2023/MyBackupFile.sql 

Restore from local. Copy the backup file from S3 to the local instance, and restore.

aws s3 cp  s3://backup.folder/dbbackups2023/MyBackupFile.sql  /home/some-user

mysql -u myUserName  -pMyPassword  DBName < MyBackupFile.sql 

Hope this helps.

Leave a Reply