Introduction

Website files and a database are the two primary parts of a website.

  • website files: All static content, including code, images, themes, and plugins. Usually, the server’s public_html folder contains these files. Websites won’t load or display properly without these.
  • Database: Posts, pages, comments, user data, and other dynamic content are all stored in the database. MySQL is used by most websites to handle this data.

It’s crucial to regularly back up your website. It facilitates the process of transferring a website to a different server or hosting provider and helps guard against unintentional deletions, server crashes, and hacking attempts.

Methods of Backup

1. Backup Website Files

Option A – Using cPanel (File Manager)

cPanel is a web hosting control panel that simplifies managing your website. To back up your website files:

  1. Log in to cPanel.
  2. Open File Manager.
  3. Navigate to the public_html folder (or your domain folder).
  4. Select all files and click Compress, then choose the .zip format.
  5. Download the compressed file to your computer.

This method creates a backup of all website files in a single archive, making it easy to store and transfer.

Option B – Using Command Line (SSH)

SSH (Secure Shell) allows you to connect to your server using the command line. It’s useful for more advanced users who prefer direct server access.

  • Using Command line (SSH) :

cd /home/username/public_html

tar -czvf website-files-backup.tar.gz *

  • cd /home/username/public_html – navigates to your website directory.
  • tar -czvf website-files-backup.tar.gz * – compresses all files in the folder into a .tar.gz archive.

2. Backup Database

Option A – Using phpMyAdmin

phpMyAdmin is a web-based tool to manage MySQL databases. To back up your database:

  1. Log in to cPanel and open phpMyAdmin.
  2. Select your website’s database.
  3. Click Export, choose Quick + SQL, and download the file.

This creates a .sql file containing all your database tables and content, which is essential for restoring your website fully.

Option B – Using Command Line (SSH)

For command-line users, mysqldump is a reliable tool to export a database:

mysqldump -u DB_USER -p DB_NAME > database-backup.sql

  • Replace DB_USER with your MySQL username.
  • Replace DB_NAME with your database name.
  • database-backup.sql will contain all tables, records, and the structure of your database.

Methods of Restoration

1. Restore Website Files

Option A – Using cPanel (File Manager)

  1. Open File Manager in cPanel.
  2. Upload your .zip backup file to public_html/.
  3. Extract it inside the folder.

This restores your website files exactly as they were at the time of backup.

Option B – Using Command Line (SSH)

cd /home/username/public_html

tar -xzvf website-files-backup.tar.gz

This command extracts the .tar.gz backup, restoring all files to the website directory.

2. Restore Database

Option A – Using phpMyAdmin

  1. Open phpMyAdmin and create a new database (or select the old one).
  2. Go to Import, upload your database-backup.sql file, and click Go.

Option B – Using Command Line (SSH)

mysql -u DB_USER -p DB_NAME < database-backup.sql

This restores all your database content, including posts, pages, comments, and user accounts.

3. Update Configuration File (if needed)

If database credentials (name, username, or password) have changed, update your configuration file (wp-config.php for WordPress) so your website can connect to the database:

define(‘DB_NAME’, ‘yourdbname’);

define(‘DB_USER’, ‘yourdbuser’);

define(‘DB_PASSWORD’, ‘yourdbpassword’);

define(‘DB_HOST’, ‘localhost’);

 

4. Fix File Permissions

Correct file permissions are critical for both security and functionality.

  • Directories → 755

find /home/username/public_html -type d -exec chmod 755 {} \;

  • Files → 644

find /home/username/public_html -type f -exec chmod 644 {} \;

  • Check ownership

chown -R username: username /home/username/public_html

These commands ensure directories and files are accessible to the server while restricting unauthorised modifications.

5. Test Your Website

  • After restoration, test your website in a browser:

http://yourdomain.com

  • Ensure that pages, images, plugins, and database content load correctly.

Conclusion

A crucial component of efficient website management is backing up and restoring your website. Speciality at ServerAdminz is assisting companies in safeguarding the most important information, quickly recovering from server failures or unforeseen problems, and keeping a safe, dependable, and operational online presence. Businesses can minimise downtime, guarantee business continuity, and concentrate on expansion without having to worry about technical difficulties or data loss.