KNOWNHOST WIKI

User Tools

Site Tools


control-panels:cpanel-whm:how-to-extract-data-from-cpanel-backup

Extracting Only Certain Data From a cPanel Backup

The following assumes that you have root access via SSH to the server. This guide is intended for those that only need to extract certain data from a cPanel backup to restore manually, such as a single MySQL database. This will allow the user to restore the single SQL backup rather than the entire cPanel account, thus avoiding the loss of important data such as emails received since the last backup was taken.


1. Determine The Backup File's Structure

In the same directory as the cPanel backup, run tar -tf against the file to see what it contains.

  [root@host ]# tar -tf  cpmove-cPusername.tar.gz *mysql*sql
  backup-8.21.2019_20-27-03_cPusername/mysql.sql
  backup-8.21.2019_20-27-03_cPusername/mysql/cPuserna_wp21.sql
  backup-8.21.2019_20-27-03_cPusername/mysql/cPuserna_sfsdaf445yt5y5.sql
  backup-8.21.2019_20-27-03_cPusername/mysql/cPuserna_sealff_org.sql
  backup-8.21.2019_20-27-03_cPusername/mysql/roundcube.sql
  backup-8.21.2019_20-27-03_cPusername/mysql/cPuserna_wp.sql
  backup-8.21.2019_20-27-03_cPusername/mysql/cPuserna_shop.sql
  backup-8.21.2019_20-27-03_cPusername/mysql-timestamps/mysql


2. Craft Your Extraction Command Based Off Of the Structure

Using what you know now of the tar.gz file's structure, you can now craft your command to extract only the content you need.

The following example demonstrates the extraction of a wp-config.php file from a cPanel backup:

  [root@host]# tar -zxvf cpmove-cPusername.tar.gz backup-8.21.2019_20-27-03_cPusername/homedir/public_html/wp-config.php
  backup-8.21.2019_20-27-03_cPusername/homedir/public_html/wp-config.php

Alternatively, if you have an idea of the naming structure of the file you are looking for, you can use wildcards to help find it. The following is particularly useful for finding SQL files located in the cPanel cpmove- backup's mysql/ directory:

  tar -zxvf /home/cpmove-cPusername.tar.gz *mysql*sql

This may result in output like this:

  [root@host]$ tar -tf  cpmove-cPusername.tar.gz *mysql*sql
  cpmove-cPusername/mysql/cPusername_wp.sql
  cpmove-cPusername/mysql/roundcube.sql
  cpmove-cPusername/mysql-timestamps/mysql
  cpmove-cPusername/mysql.sql
  cpmove-cPusername/homedir/public_html/vendor/yiisoft/yii2/log/migrations/schema-mysql.sql
  cpmove-cPusername/homedir/public_html/vendor/yiisoft/yii2/caching/migrations/schema-mysql.sql
  cpmove-cPusername/homedir/public_html/vendor/yiisoft/yii2/rbac/migrations/schema-mysql.sql
  cpmove-cPusername/homedir/public_html/vendor/yiisoft/yii2/web/migrations/schema-mysql.sql
  cpmove-cPusername/homedir/public_html/vendor/yiisoft/yii2/i18n/migrations/schema-mysql.sql
  cpmove-cPusername/homedir/public_html/vendor/codeception/base/tests/data/dumps/mysql.sql
  [root@host]$ 

Now, you should be able to access the extracted data in the path that was shown in the output of tar -tf. So, the cPusername_wp.sql file will be located at ./cpmove-cPusername/mysql/cPusername_wp.sql (relative to the location from which the extraction command was executed, and in this case, the present working directory):

  [root@host]$ ll cpmove-cPusername/mysql/cPusername_wp.sql
  -rw-r--r-- 1 cPusername  cPusername  8697319 Jan 19 00:56  cpmove-cPusername/mysql/cPusername_wp.sql
  [root@host]$


3. Restore the Extracted Data

Lastly, you just need to restore the extracted data. If you needed to restore the public_html, just move the contents of the extracted public_html directory into place and overwrite the existing public_html contents.

Something like this could be used:

  mv -f cpmove-cPusername/homedir/public_html/*  /home/cPusername/public_html/

If you needed to restore a database, just drop (delete) and recreate the database (to ensure it is empty) and then import the sql file into the empty database. You can delete and recreate a database via cPanel's MySQL Databases interface, or you can use the following uapi commands via a root ssh shell:

  uapi --user=cPusername  Mysql delete_database name=cPusername_wp
  uapi --user=cPusername  Mysql create_database name=cPusername_wp
  uapi --user=cPusername Mysql set_privileges_on_database user=dbuser database=cPusername_wp privileges=ALL

Note: that you should be able to find your database user credentials in the site's database configuration file if you are unsure what to put for the 'dbuser' option in the last command above.

After you have deleted and recreated the database, you can just import the sql file into it.

  mysql cPusername_wp < cpmove-cPusername/mysql/cPusername_wp.sql

That's it! If you have any trouble whatsoever, open a support ticket with your KnownHost support team and we'll be happy to help! :)

control-panels/cpanel-whm/how-to-extract-data-from-cpanel-backup.txt · Last modified: 2020/06/02 08:15 by Karson N.