Backing Up Databases via SSH (Firstserv Guide)
This guide explains how to create MySQL database backups using the command line via SSH. This is especially useful for large databases or when you want to automate regular backups.
Before You Begin
Make sure you have:
- ✅ SSH access to your hosting account/server
- ✅ Your database name
- ✅ Your database username and password
- ✅ Basic familiarity with file paths and directories
Creating a One-Off Backup (Manual via SSH)
Step 1: Connect via SSH
- Connect to your server using:
- Terminal (Mac/Linux)
- PuTTY or similar (Windows)
Step 2: Run the Backup Command
Use the following command:
Example
What Happens
- You will be prompted to enter your database password
- The backup file (backup.sql) will be created in your current directory
Important Notes
- Large databases may take time to complete
- Wait until the process finishes before closing your session
Automating Backups (Cron Job or Script)
You can automate backups using a cron job or script so they run regularly without manual input.
Example Command
Example with Real Values
Important Configuration Notes
✅ Specify Full Paths
- /usr/bin/mysqldump → Full path to the MySQL tool
- /home/username/backup.sql → Full path to save the backup file
👉 This ensures the cron job works reliably in the background
✅ Password Formatting
- There must be no space between -p and the password
If Using Special Characters
If your password contains symbols (e.g. $, @, &), wrap it in quotes:
Where Backups Are Stored
- By default, backups are saved in the directory you specify
- Example:
/home/username/backup.sql
✅ You can then:
- Download the file via FTP or File Manager
- Move it to external storage
Best Practices
- ✅ Store backups off-server to save space
- ✅ Schedule regular backups using cron
- ✅ Verify backup files occasionally
- ✅ Avoid storing sensitive credentials in insecure locations
Summary
- Use mysqldump via SSH to back up databases
- Manual backups are quick and reliable
- Automate backups with cron jobs for convenience
- Always specify full paths and handle passwords carefully
Need Help?
If you need assistance setting up SSH access or configuring automated backups, the Firstserv support team is always happy to help.
