How to backup up Ubuntu server

9/19/2025
2 min read

Why Backing Up a Server is Critical

Backing up a server is essential to safeguard your data and ensure business continuity. Without a proper backup, you risk losing critical information due to hardware failures, cyberattacks, or accidental deletions. For example, a company I worked with lost months of data after a server crash because they didn’t have a backup server strategy in place. Don’t let this happen to you—implement a reliable backup plan today.

This guide will show you how to backup a server running Ubuntu, including its files, databases, and configurations.


Step 1: Backup Server Files

To back up the entire server filesystem, use rsync:

sudo rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /path/to/backup/

Replace /path/to/backup/ with the destination path.


Step 2: Backup Configuration Files

Critical configuration files include:

  • Apache/Nginx: /etc/apache2/ or /etc/nginx/
  • PHP: /etc/php/
  • MySQL: /etc/mysql/

Compress these directories for backup:

sudo tar -czvf config-backup.tar.gz /etc/apache2 /etc/php /etc/mysql

Step 3: Backup Databases

If your server hosts databases, export them using mysqldump:

sudo mysqldump -u root -p database_name > database-backup.sql

Repeat this for each database.


Step 4: Store Backups Securely

Transfer the backups to a secure location:

scp config-backup.tar.gz database-backup.sql user@remote-server:/path/to/backup/

Step 5: Automate Server Backups

Set up a cron job to automate backups:

  1. Open the crontab editor:crontab -e
  2. Add the following lines for daily backups:0 2 * * * rsync -aAXv / /path/to/backup/ 0 2 * * * tar -czvf /path/to/backup/config-backup-$(date +\%F).tar.gz /etc/apache2 /etc/php /etc/mysql

Step 6: Restore the Server

  1. Reinstall Ubuntu Server.
  2. Restore files and configurations:sudo tar -xzvf config-backup.tar.gz -C /
  3. Restore databases:mysql -u root -p database_name < database-backup.sql

Additional Resources

If your server hosts a WordPress site, check out our WordPress Backup Guide for detailed instructions on how to back up and restore WordPress-specific data.

Volodymyr Huzii - Software Developer

About the Author

Volodymyr Huzii

Software Developer with 6+ years of full-stack experience, specializing in .NET, Vue.js, and modern web technologies. I focus on building highly secure, scalable, and performant software solutions that protect against modern cyber threats.

Skilled in developing secure SaaS applications, and integrating security best practices into every layer of the application stack. Expert in building applications that prioritize data protection and system integrity.

I work confidently across AWS and Azure environments, setting up secure CI/CD pipelines, and delivering robust, responsive, and high-performing applications with enterprise-grade security standards.

Strong collaborative mindset, proven ability to work with security teams and cross-functional teams, and a reputation for delivering secure solutions efficiently and reliably.

Safe Web Academy

Empowering individuals and organizations with cutting-edge cybersecurity knowledge and practical defense strategies.

© 2025 Safe Web Academy. All rights reserved. Securing the digital world.