Question
Is it possible to manually extract a particular file or directory from a cPanel backup file?
Answer
Yes, cPanel backup files are compressed with 'tar' and 'gzip'. It is possible to extract data from them without "expanding' them.
The steps below are general guidelines. The guide assumes you are logged into the server as 'root', using SSH. Or using the WHM Terminal Feature.
For our example, we will use the following information:
Backup file: /backup/2020-08-16/accounts/cptest.tar.gz
Directory to extract from .tar.gz file: public_html
Temporary directory: /temp_location
First, you will want to know the 'path' inside the file to extract.
From the command-line, use 'tar tfz' to list the data inside the .tar.gz file.
Listing from inside .tar.gz file:
# tar tfz /backup/2020-08-16/accounts/cptest.tar.gz | grep public_html | head -n 1
cptest/homedir/public_html/ <-- this one
cptest/homedir/public_html/cgi-bin/
cptest/homedir/public_html/directory_name/
cptest/homedir/public_html/directory_name/cgi-bin/
In our output, the first response shows the 'path' for the 'public_html' directory.
Output: cptest/homedir/public_html/
Next, create a directory to put the data into and change into that directory:
[root@centos-77 ~]# mkdir /temp_location
[root@centos-77 ~]# cd /temp_location/
[root@centos-77 temp_location]#
Once inside the temporary location, use 'tar xfvz' to extract the directory from the .tar.gz file.
Extracting directory with files inside:
# tar xfvz /backup/2020-08-16/accounts/cptest.tar.gz cptest/homedir/public_html
cptest/homedir/public_html/
cptest/homedir/public_html/cgi-bin/
cptest/homedir/public_html/directory_name/
cptest/homedir/public_html/directory_name/cgi-bin/
The extraction command must use the 'path' seen earlier.
And now, the extracted directory will be present inside your temporary directory.
Navigate to the temporary location + 'path', and you will see the directory.
Change directory to extract 'public_html':
# cd /temp_location/cptest/homedir/public_html/
# pwd
/temp_location/cptest/homedir/public_html
# ls -al
total 0
drwxr-x--- 4 cptest cptest 43 Aug 13 08:35 .
drwxr-xr-x 3 root root 25 Aug 17 12:50 ..
drwxr-xr-x 2 cptest cptest 6 Aug 13 08:35 cgi-bin
drwxr-x--- 3 cptest cptest 21 Aug 13 08:35 directory_name
The file/directory is now extracted and placed in the temporary location for you to copy or move at your leisure.
That's it.