Login

The Process To Take Backup On A Dedicated Server Using An SSH Connection

Backup On A Dedicated Server

If your dedicated server doesn’t have a control panel, or you just prefer working from the command line, SSH gives you full control over backing up both your files and your databases. Here’s how to do it properly, that’s actually usable if you ever need to restore from it.

Before You Start

Connect to your server via SSH using your terminal (Mac/Linux) or a client like PuTTY (Windows):

bash
ssh username@your-server-ip

A quick security note: logging in directly as root works, but it’s better practice to SSH in as a regular sudo-enabled user and use sudo for privileged commands. If your server still only allows root login, consider setting up a separate admin user and disabling direct root SSH access once you’re comfortable with the process.

How to Back Up a MySQL/MariaDB Database

Export database to .sql file via mysqldump:

bash
mysqldump -u your_username -p your_database_name > backup_$(date +%F).sql

You’ll be prompted for your MySQL password. The $(date +%F) part of commands automatically adds today’s date at the end of the filename, for example, backup_2026-08-07.sql. Due to which you can easily find the right backup later.

To back up every database on the server at once:

bash
mysqldump -u your_username -p –all-databases > all_databases_$(date +%F).sql

Backing Up Website Files

A database backup alone doesn’t back up your actual website files, uploads, or configuration. Use tar to archive a directory:

bash
tar -czvf website_backup_$(date +%F).tar.gz /var/www/html

This compresses everything in /var/www/html (adjust the path to wherever your website actually lives) into a single .gz file.

Move the Backup Off the Server

This is the step the original process skipped, and it’s the one that actually matters. A backup that lives only on the same server doesn’t protect you if that server has a hardware failure, gets compromised, or is lost entirely. Copy backups somewhere else using scp or rsync:

bash
scp backup_2026-08-07.sql user@remote-server:/path/to/backup/folder/

Or sync a whole backup directory with rsync:

bash
rsync -avz /home/backups/ user@remote-server:/backups/

Automate It With a Cron Job

Manual backups get forgotten so automate the backup process:

bash
crontab -e

Add a line to run a database backup daily at 2 AM:

bash
0 2 * * * mysqldump -u your_username -p’your_password’ your_database > /home/backups/db_$(date +\%F).sql

Note: storing a plaintext password in a cron job isn’t ideal from a security standpoint. Therefore, store credentials in a .my.cnf file with restricted permissions (chmod 600) and omit the password from the command entirely, because it is a more secure approach for it.

Restoring From a Backup

Database:
bash
mysql -u your_username -p your_database_name < backup_2026-08-07.sql

Files:
bash
tar -xzvf website_backup_2026-08-07.tar.gz -C /var/www/html

Best Practices

  • Follow the 3-2-1 rule: 3 copies of your data, on 2 different types of storage, with at least 1 copy offsite.
  • Verify your backups occasionally by actually restoring one in a test environment since a backup you’ve never tested is a backup you can’t fully trust.
  • Back up files and databases separately but on the same schedule, so they stay in sync with each other.
  • Set a retention policy. Always keep only your recent backups and delete older ones automatically to free up disk space.
  • Consider a managed option if scripting this yourself isn’t ideal — our Backup Solutions service handles automated, offsite, encrypted backups without any manual scripting.

Need Help?

If you are unsure about how to back up your data properly, or facing issues while backing up your data, then reach out to our support team or chat with us.

Sarang Khedkar

The Process To Take Backup On A Dedicated Server Using An SSH Connection
Table of Contents
    ×