# Creating Manual Backups

Regular backups are a key part of managing a MySQL deployment. While Elestio provides automated backups by default, you may want to perform manual backups for specific reasons, such as preparing for a major change, keeping a local copy, or testing backup automation. This guide walks through how to create MySQL backups on Elestio using multiple approaches. It covers manual backups through the Elestio dashboard, using MySQL CLI tools, and Docker Compose-based setups. It also includes advice for backup storage, retention policies, and automation using scheduled jobs.

## **Manual Service Backups on Elestio**

If you’re using Elestio’s managed MySQL service, the easiest way to create a manual backup is through the dashboard. This built-in method creates a full snapshot of your current database state and stores it within Elestio’s infrastructure. These backups are tied to your service and can be restored through the same interface. This option is recommended when you need a quick, consistent backup without using any terminal commands.

### **To trigger a manual backup from the Elestio dashboard:**

- Log in to the Elestio dashboard and navigate to your MySQL service/cluster.
- Click the <span class="s1">**Backups**</span> tab in the service menu.
- Select <span class="s1">**Back up now**</span> to generate a snapshot.

[![Screenshot 2025-04-30 at 11.34.34 AM.jpg](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/screenshot-2025-04-30-at-11-34-34-am.jpg)](https://docs.elest.io/uploads/images/gallery/2025-04/screenshot-2025-04-30-at-11-34-34-am.jpg)

## **Manual Backups Using MySQL CLI**

MySQL provides a set of command-line tools that are useful when you want to create backups from your terminal. These include `<span class="s2">mysqldump</span>` for exporting databases and <span class="s2">mysql</span> for connectivity and basic queries. This approach is useful when you need to store backups locally or use them with custom automation workflows. The CLI method gives you full control over the backup format and destination.

### **Collect Database Connection Info**

To use the CLI tools, you’ll need the database host, port, name, username, and password. These details can be found in the <span class="s3">**Overview**</span> section of your MySQL service in the Elestio dashboard.

[![Screenshot 2025-04-30 at 11.47.37 AM.jpg](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/screenshot-2025-04-30-at-11-47-37-am.jpg)](https://docs.elest.io/uploads/images/gallery/2025-04/screenshot-2025-04-30-at-11-47-37-am.jpg)

### **Back Up with mysqldump**

Use <span class="s2">mysqldump</span> to export the database to a <span class="s2">.sql</span> file. This file can later be used to recreate the database or specific tables.

```
mysqldump -h <host> -P <port> -u <username> -p<password> <database_name> > <output_file>.sql
```

- Replace the placeholders with actual values from your Elestio dashboard.
- The <span class="s1">-p&lt;password&gt;</span> flag must not have a space between <span class="s1">-p</span> and the password.

Example:

```
mysqldump -h mysql-example.elestio.app -P 24306 -u elestio -pelestioPass mydb > mydb_backup.sql
```

You can add the `<span class="s1">--single-transaction</span>` flag for InnoDB tables to ensure consistency during the dump.

## **Manual Backups Using Docker Compose**

If your MySQL database is deployed through a Docker Compose setup on Elestio, you can run the <span class="s1">mysqldump</span> command from within the running container. This is useful when the tools are installed inside the container environment and you want to keep everything self-contained. The backup can be created inside the container and then copied to your host system for long-term storage or transfer.

### **Access Elestio Terminal**

Head over to your deployed MySQL service dashboard and go to <span class="s3">**Tools &gt; Terminal**</span>. Use the credentials provided there to log in to your terminal.

[![image.png](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/FNYimage.png)](https://docs.elest.io/uploads/images/gallery/2025-04/FNYimage.png)

Once you are in your terminal, navigate to the correct directory:

```
cd /opt/app/
```

### **Run mysqldump Inside the Container**

Use this command to run the backup from within the MySQL container. Ensure environment variables like `<span class="s2">MYSQL_USER</span>`, `<span class="s2">MYSQL_PASSWORD</span>`, and `<span class="s2">MYSQL_DATABASE</span>` are defined, or replace them with actual values.

```
docker-compose exec mysql \
  bash -c "mysqldump -u \$MYSQL_USER -p\$MYSQL_PASSWORD \$MYSQL_DATABASE > /tmp/manual_backup.sql"
```

This command saves the backup to <span class="s1">/tmp/manual\_backup.sql</span> inside the container.

### **Copy Backup to Host**

Once the backup is created inside the container, use the following command to copy it to your host system:

```
docker cp $(docker-compose ps -q mysql):/tmp/manual_backup.sql ./manual_backup.sql
```

This creates a local copy of the backup file, which you can then upload to external storage or keep for versioned snapshots.

## **Backup Storage &amp; Retention Best Practices**

Once backups are created, they should be stored securely and managed with a clear retention policy. Proper naming, encryption, and rotation reduce the risk of data loss and help during recovery. Use timestamped filenames to identify when the backup was created. External storage services such as AWS S3, Backblaze B2, or an encrypted server volume are recommended for long-term storage.

##### **Guidelines to follow:**

- <span class="s1">**Name backups clearly:**</span> `mydb_backup_2025_04_29.sql`
- **Store in secure, off-site storage**<span class="s1"> if possible.</span>
- **Retain 7 daily backups, 4 weekly backups, and 3–6 monthly backups.**
- <span class="s1">**Remove old backups automatically**</span> to save space using automation or scripts.

By combining storage hygiene with regular scheduling, you can maintain a reliable backup history and reduce manual effort.

## **Automating Manual Backups (cron)**

Manual backup commands can be scheduled using tools like <span class="s2">cron</span> on Linux-based systems. This allows you to regularly back up your database without needing to run commands manually. Automating the process also reduces the risk of forgetting backups and ensures more consistent retention.

#### **Example: Daily Backup at 2 AM**

Open your crontab file for editing:

```
crontab -e
```

Then add a job like the following:

```
0 2 * * * mysqldump -h db.vm.elestio.app -P 24306 -u elestio -pelestioPass mydatabase > /backups/backup_$(date +\%F).sql
```

- This will create a timestamped <span class="s1">.sql</span> file every day at 2 AM.
- Make sure the <span class="s1">/backups/</span> directory exists and is writable by the user running the cron job.

You can also compress the backup or upload it to cloud storage in the same script using tools like <span class="s2">gzip</span>, <span class="s2">rclone</span>, or <span class="s2">aws-cli</span>.