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:

 
 
 
 
 
 
Shell
 
 
mysqldump --opt -u DB_USER -p DB_NAME > backup.sql
 
 
 

Example

 
 
 
 
 
 
Shell
 
 
mysqldump --opt -u firstserv_user -p firstserv_db > backup.sql
 
 

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

 
 
 
 
 
 
Shell
 
 
/usr/bin/mysqldump --opt -u DB_USER -pPASSWORD DB_NAME > /home/cpanelusername/backup.sql
 
 
 

Example with Real Values

 
 
 
 
 
 
Shell
 
 
/usr/bin/mysqldump --opt -u firstserv_user -pMyPassword firstserv_db > /home/username/backup.sql
 
 

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:

 
 
 
 
 
 
Shell
 
 
/usr/bin/mysqldump --opt -u firstserv_user -p'MyP@ssw0rd!' firstserv_db > /home/username/backup.sql
 
 

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.

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Managing Disk Usage in cPanel

Managing Disk Usage in cPanel (Firstserv Guide) Running low on storage can be stressful—but...

Get a free Let's Encrypt SSL for your website

An SSL (Secure Sockets Layer) certificate ensures that the connection between your website...

Importing Large MySQL Databases

Importing Large MySQL Databases (Firstserv Guide) If your database is too large to...

What happens if I exceed my disk space allowance?

Disk Space & Mailbox Usage (Firstserv Guide) Managing your disk space is essential to...

Database Not Showing in phpMyAdmin

Database Not Showing in phpMyAdmin (Firstserv Guide) If you’ve just created a new database...