Restoring cPanel Backups Via SSH

Well, if you already read our previous article to restore cPanel backup from WHM and looking for an SSH method to restore bulk cPanel backups at once, you’re at the right place. Here, in this tutorial, we’re gonna talk about two different ways to restore your cPanel accounts via SSH.

Let’s directly dive right in!!

Restoring cPanel Backup From SSH
Restoring cPanel Backup From SSH

There are two methods by which you can easily restore bulk cPanel backups in SSH with root access.

  1. Restore Backup From .sh File
  2. Restore Backup Using Linux Commands

1:  Restore Backup From .sh File

Let me tell you briefly what we’re gonna do next. Suppose you have a backup file (something.tar.gz) that contains 100 cPanel backups. Now, you can do it by creating a shell script. What you have to do is to create a shell script with the .sh extension, enter the command we mentioned below, save the file, and hit that file from the root end whenever you want to restore the backup.

Also See: Transfer Files using WinSCP

Other than explaining it in a complex way, you can follow the below steps to do it practically.

  • First of all, log into your SSH as a root.
Log into SSH
Log in to SSH
  • Create a new .sh file using the below command.
[root@test ~]# touch testbackup.sh
  • Open the newly created file using the below command.
[root@test ~]# vi testbackup.sh
  • Paste the below script in the testbackup.sh file.
#!/bin/bash

LBLUE='\033[1;34m'
LCYAN='\033[1;36m'
LGREEN='\033[1;32m'
LPURP='\033[1;35m'
LRED='\033[1;31m'
NC='\033[0m'

for files in /home/username/public_html/backup/*; do
 if [ -f "$files" ]
 then
 /usr/local/cpanel/scripts/restorepkg "$files"
 printf "${LGREEN} $files Done \n${NC}"
 else
 printf "${LRED} $files Not Done \n${NC}"
 fi
done
  • Do not forget to change the path with the path where the file is present that needs to be restored.
SSH Shell Script Command
SSH Shell Script Command
  • Once done with the modification, press the ESC button on your keyboard and then type :wq! to Save and Close the file.
wq! command to save and close file
wq! command to save and close the file
  • Once you hit the command, the editing window will be closed, and you’re all set to hit the file to execute the backup restoration process.
  • Use the below command to hit the newly edited file.
[root@test ~]# ./testbackup.sh

Note: To perform this command, you’ll have to make sure that you’re in the working directory of the .sh file. Otherwise, you’ll have to type the full path of the shell script.

That’s it.

Once you hit the file, the command will execute and restore the backup present inside the given directory.

2:  Restore Backup Via Linux Commands

Other than restoring the backups from the Shell script, you can also use simple Linux commands to perform the same task.

Let me assume that you already have the backup file as you might have because that’s why you’re looking to restore that backup file. However, before performing this task, it’s recommended to backup your existing cPanel account and transfer it to a different server using FTP or any other method. Well, you can easily backup your existing cPanel by following the below command:

[root@test ~]# /scripts/pkgacct username

Change the username with the cPanel username you want to backup and package it into a single file.

Let’s move ahead to the restoration section of the backup.

Now, that you already have the backup file transferred to the new server, you can easily restore it by following the below command:

[root@test ~]# /scripts/restorepkg username

Again, change the username with your cPanel username. Other than this, you can also restore the cPanel backup using the file path. To perform this task, the backup file must be present inside your server. So, if the backup file is located anywhere else, transfer it to your server, and follow the below command:

[root@test ~]# /scripts/restorepkg /root/user/backup/file.tar.gz

From the above command:

Change the restoration path /root/user/backup/file.tar.gz with your custom path.

Change the file name (file.tar.gz) with your custom file name.

Once you hit the above command, the restoration process will begin and you can view the output as it’ll restore all the cPanel accounts present in your tar.gz file. Once the process is finished, you’ll again see the command prompt.

That’s it.

I hope now you can restore your bulk cPanel backups from Shell Script and Linux Command. I hope this article helps you. If not, you can simply hit the comment section or contact us on Redserverhost.com where we offer various Web Hosting Services such as Reseller Hosting, Dedicated Hosting, Shared Hostingand also FFmpeg Hosting which is kind of rarely used but most effective web hosting solution for those who want tremendous disk space in their website.

Other than this, you can contact us on Facebook Twitter for any further inquiries or suggestions. We always appreciate suggestions.

Scroll to Top