How to back up and restore a website on Linux – TechRepublic

Register for your free TechRepublic membership or if you are already a member, sign in using your preferred method below.
We recently updated our Terms and Conditions for TechRepublic Premium. By clicking continue, you agree to these updated terms.
Invalid email/username and password combination supplied.
An email has been sent to you with instructions on how to reset your password.
By registering, you agree to the Terms of Use and acknowledge the data practices outlined in the Privacy Policy.
You will also receive a complimentary subscription to TechRepublic’s News and Special Offers newsletter and the Top Story of the Day newsletter. You may unsubscribe from these newsletters at any time.
Username must be unique. Password must be a minimum of 6 characters and have any 3 of the 4 items: a number (0 through 9), a special character (such as !, $, #, %), an uppercase character (A through Z) or a lowercase (a through z) character (no spaces).
How to back up and restore a website on Linux
Your email has been sent
Ever wonder how to back up a website on Linux? Jack Wallen shows you how easy it can be.
Disaster happens. Or, if disaster has yet to strike, you might find yourself in a situation wherein you need to migrate a website from one server or host to another. When either thing happens, what do you do? Panic? No. You follow through with your backup and restore plan. You have one, right? No? Okay, let’s fix that.
I’m going to walk you through the process of backing up and restoring a website that is housed on Linux. Understand, this process won’t work for every site (because all things are not equal), but it should give you a foundation from which to work.
With that said, let’s get going.
I’m going to assume your website depends on a MySQL database, runs on Apache, and /var/www/html is your document root. To make this backup/restore happen, you’ll need a user with root privileges.
SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)
First, I’m going to demonstrate using WordPress. Let’s say our database is wordpressdb. We have to create a backup of that before we do anything else. You might want to consider putting your site into maintenance mode (so users aren’t actively on the site and less data will be written to the database). You can put your WordPress site in maintenance mode with third-party plugins such as WP Maintenance Mode or SeedProd.
Once your site is in maintenance mode, back up the database by logging into the hosting server and issuing the command:
sudo mysqldump wordpressdb > wordpressdb-backup.sql
You might also want to add the date to the backup filename, such as wordpress-backup-DEC302021.sql.
Now that your database is backed up, it’s time to back up the WordPress directory. Let’s assume that directory is /var/www/html/wordpress. To back up that directory, issue the command:
sudo tar -cpvzf wordpress-backup.tar.gz /var/www/html/wordpress
The above options are:
At this point you have the two files:
Next, you’ll want to make a copy of your Apache configuration file. Assuming that file is wordpress.conf, make a copy of it with:
sudo cp /etc/apache2/sites-available/wordpress.conf ~/wordpress.conf
Finally, if you’re using SSL certificates on your server, you’ll want to copy them as well.
Okay, it’s now time for the restoration. I’m going to assume we’re restoring to the same server. If you’re restoring to a new server, you’ll need to start by making sure you have all of the dependencies installed (the full LAMP stack) with a command like:
sudo apt install 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 assume you have everything WordPress requires installed. The first thing we’ll then do is restore the database with the command:
sudo mysql wordpressdb < wordpressdb-backup.sql
Next, we'll restore the backup directory to the Apache document root with:
tar -xzvf wordpress-backup.tar.gz
sudo mv wordpress /var/www/html/

Move your apache configuration file with:
sudo mv wordpress.conf /etc/apache2/sites-available/
Enable the site with:
sudo a2ensite wordpress
You should now be able to access the WordPress site as you did before. If you put the site in maintenance mode before you backed it up, you'll need to take it out of maintenance mode so users can access it.
And that's all there is to backing up and restoring a website in Linux. Of course, this is very basic. If you have a much more complicated site, there will probably be more steps involved. However, this will at least give you a general understanding of how the process works.
Subscribe to TechRepublic's How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

You don't want to miss our tips, tutorials, and commentary on the Linux OS and open source applications.
How to back up and restore a website on Linux
Your email has been sent
Your message has been sent
TechRepublic Premium content helps you solve your toughest IT issues and jump-start your career or next project.
These 11 cloud-to-cloud solutions back up your organization’s data so you’ll be covered in the event of deletions, malware or outages. Compare the best online cloud backup services now.
You can use a mobile device to speak with another person directly through the Teams app. Lance Whitney shows you how to use this handy feature.
A phishing technique called Browser in the Browser (BITB) has emerged, and it’s already aiming at government entities, including Ukraine. Find out how to protect against this new threat.
With so many project management software options to choose from, it can seem daunting to find the right one for your projects or company. We’ve narrowed them down to these nine.
Start-ups, DARPA and Accenture Ventures announce research partnerships, new hardware and strategic investments.
Procuring software packages for an organization is a complicated process that involves more than just technological knowledge. There are financial and support aspects to consider, proof of concepts to evaluate and vendor negotiations to handle. Navigating through the details of an RFP alone can be challenging, so use TechRepublic Premium’s Software Procurement Policy to establish ...
Recruiting a Security Analyst with the right combination of technical expertise and experience will require a comprehensive screening process. This hiring kit from TechRepublic Premium includes a job description, sample interview questions and a basic want ad that you can customize for your business to find, interview, recruit and hire the best candidates for a ...
Recruiting a DevOps engineer with the right combination of technical expertise and experience will require a comprehensive screening process. This hiring kit from TechRepublic Premium includes a job description, sample interview questions and a basic want ad that you can customize for your business to find, interview, recruit and hire the best candidates for a ...
Video game writing jobs are in demand. Recruiting a video game/quest writer with the right combination of technical expertise and experience will require a comprehensive screening process. This hiring kit from TechRepublic Premium includes a job description, sample interview questions and a basic want ad that you can customize for your business to find, interview, ...

source

We will be happy to hear your thoughts

Leave a reply

LINXGO
Logo
Compare items
  • Total (0)
Compare