How to back up and restore a website on Linux

2 years ago 419

Ever wonderment however to backmost up a website connected Linux? Jack Wallen shows you however casual it tin be.

Website design. Developing programming and coding technologies.

Image: scyther5, Getty Images/iStockphoto

Disaster happens. Or, if catastrophe has yet to strike, you mightiness find yourself successful a concern wherein you request to migrate a website from 1 server oregon big to another. When either happening happens, what bash you do? Panic? No. You travel done with your backup and reconstruct plan.

You person one, right? 

No?

Okay, let's hole that. 

I'm going to locomotion you done the process of backing up and restoring a website that is housed connected Linux. Understand, this process won't enactment for each tract (because each things are not equal), but it should springiness you a instauration from which to work.


With that said, let's get going.

What you'll request

I'm going to presume your website depends connected a MySQL database, runs connected Apache, and /var/www/html is your papers root. To marque this backup/restore happen, you'll request a idiosyncratic with basal privileges.

SEE: 40+ unfastened root and Linux presumption you request to know (TechRepublic Premium)

How to backmost up your database

First, I'm going to show utilizing WordPress. Let's accidental our database is wordpressdb. We person to make a backup of that earlier we bash thing else. You mightiness privation to see putting your tract into attraction mode (so users aren't actively connected the tract and little information volition beryllium written to the database). You tin enactment your WordPress tract successful attraction mode with third-party plugins specified arsenic WP Maintenance Mode oregon SeedProd

Once your tract is successful attraction mode, backmost up the database by logging into the hosting server and issuing the command:

sudo mysqldump wordpressdb > wordpressdb-backup.sql

You mightiness besides privation to adhd the day to the backup filename, specified arsenic wordpress-backup-DEC302021.sql.

How to backmost up WordPress

Now that your database is backed up, it's clip to backmost up the WordPress directory. Let's presume that directory is /var/www/html/wordpress. To backmost up that directory, contented the command:

sudo tar -cpvzf wordpress-backup.tar.gz /var/www/html/wordpress

The supra options are:

  • c - make an archive
  • p - sphere permissions
  • v - amusement verbose output
  • z - compress the archive
  • f - make a file

At this constituent you person the 2 files:

  • wordpressdb-backup.sql
  • wordpress-backup.tar.gz

Next, you'll privation to marque a transcript of your Apache configuration file. Assuming that record is wordpress.conf, marque a transcript of it with:

sudo cp /etc/apache2/sites-available/wordpress.conf ~/wordpress.conf

Finally, if you're utilizing SSL certificates connected your server, you'll privation to transcript them arsenic well.

How to reconstruct WordPress

Okay, it's present clip for the restoration. I'm going to presume we're restoring to the aforesaid server. If you're restoring to a caller server, you'll request to commencement by making definite you person each of the dependencies installed (the afloat LAMP stack) with a bid like:

sudo apt instal apache2 ghostscript libapache2-mod-php mysql-server php php-bcmath php-curl php-imagick php-intl php-json php-mbstring php-mysql php-xml php-zip -y

Let's presume you person everything WordPress requires installed. The archetypal happening we'll past bash is reconstruct the database with the command:

sudo mysql wordpressdb < wordpressdb-backup.sql

Next, we'll reconstruct the backup directory to the Apache papers basal with:

tar -xzvf wordpress-backup.tar.gz sudo mv wordpress /var/www/html/

Move your apache configuration record with:

sudo mv wordpress.conf /etc/apache2/sites-available/

Enable the tract with:

sudo a2ensite wordpress

You should present beryllium capable to entree the WordPress tract arsenic you did before. If you enactment the tract successful attraction mode earlier you backed it up, you'll request to instrumentality it retired of attraction mode truthful users tin entree it.

And that's each determination is to backing up and restoring a website successful Linux. Of course, this is precise basic. If you person a overmuch much analyzable site, determination volition astir apt beryllium much steps involved. However, this volition astatine slightest springiness you a wide knowing of however the process works.

Open Source Weekly Newsletter

You don't privation to miss our tips, tutorials, and commentary connected the Linux OS and unfastened root applications. Delivered Tuesdays

Sign up today

Also spot

Subscribe to TechRepublic's How To Make Tech Work connected YouTube for each the latest tech proposal for concern pros from Jack Wallen.

Read Entire Article