How to create a PlanetScale database backup

SimpleBackups developer

Nour Sofanati

Developer, SimpleBackups

September 1, 2023

In this tutorial, we will guide you through creating a backup of your PlanetScale MySQL database using SimpleBackups. We will cover everything from obtaining your PlanetScale database credentials to creating and restoring backups. By following these steps, you can ensure the safety and security of your valuable data.

Prerequisites:

  • Register for a SimpleBackups account, this tutorial uses SimpleBackups as a backup provider.
  • An active PlanetScale account with a database to backup

Step 1: Grab your PlanetScale’s database credentials

You’ll need an active PlanetScale account with a database you have access for. SimpleBackups requires your Connection String, which you can find by going to your PlanetScale’s dashboard, then clicking on the database you want to backup.

Planetscale Dashboard

Then click on Connect to display your connection string, and copy the connection string displayed bellow

PlanetScale database connect button

Step 2: Create a backup on SimpleBackups

After creating your SimpleBackups account, head to your Create Backups page by clicking on the Create, then select Database backup.

PlanetScale database connection string

You’ll be greeted by a page where you can connect your database using the connection string, click on Paste in connection string instead, fill in your connection string, uncheck Database Backup Streaming, and check Large Database Backup. then click on Validate Connection.

SimpleBackups backup creation options

Select a name for your backup name, set a Schedule and a Storage to store your backup, then click on Create backup.

SimpleBackups backup retention, schedule and storage.

You’ll be redirected to your backup job’s page, click on Run now to test this backup, once the backup runs successfully, you’ll be able to see a Backup success indicator.

SimpleBackups success indicator

How to restore your backups:

Step 1: Download the PlanetScale / Vitess Backup File

First, locate the URL of your backup, and download it to your local system:

wget 'http://example.com/path/to/your-planetscale-vitess-backup.tar.gz' -O backup.tar.gz

Step 2: Extract the Backup File

Extract the downloaded file containing your PlanetScale / Vitess MySQL backup:

tar -xzvf backup.tar.gz

Navigate into the extracted directory:

cd your_backup_folder

Step 3: Identify and Import Schema Files

Schema files ending in -schema.sql can be imported as follows:

for filein *-schema.sql;do
  mysql -u username -p'password' -h host -P port < "$file"
done

Step 4: Identify and Import Data Files

Import all other .sql files, excluding the schema files, as data files with these commands:

for filein *.sql;doif [[ ! "$file" == *-schema.sql ]];then
    mysql -u username -p'password' -h host -P port < "$file"
fidone

Wrapping up.

We’ve gone through the steps to create a PlanetScale MySQL database backup using SimpleBackups. We covered how to grab your PlanetScale's database credentials, create a backup on SimpleBackups, and how to restore your backups. By following these steps, you can ensure that your database is safe and secure.



Back to blog

Stop worrying about your backups.
Focus on building amazing things!

Free 7-day trial. No credit card required.

Have a question? Need help getting started?
Get in touch via chat or at [email protected]

Customer support with experts
Security & compliance
Service that you'll love using