Backup cPanel and Restore to Another Server Print

  • 0

Backup cPanel and Restore to Another Server

Making a Backup in cPanel

To create a full backup:

1. Select Backup from the first page.
2. Select Full Backup from the second page.
3. Select the destination for the backup files. You have 3 options:

You can store the files in your home directory on your web server by selecting Home Directory from the pull-down menu.
cPanel can also utilize FTP or SCP to store the files to a remote machine. To do this, fill in the appropriate information and select the method for file transfer from the pull-down menu.
If you wish to download the file to your computer, skip to the next step.

4. Ensure you specify an email address here. By doing so the backup process will email you once it is complete and you won't have to keep coming back to check teh backup process progress.

5. Click Generate Backup.

If FTP or SCP was used, an email will be sent to the email address that you specified at the beginning of the process.

6. To download a copy of the backup file to your computer, click the filename under Backups Available for Download.

The date the backup was created appears in the filename (which begins with backup-MM-DD-YYYY). The file will be stored as a “tar ball,” or compressed data file, with the filename extension .tar.gz in the /home/cpanel_username directory. You can access this directory through file manager or via ssh if you have ssh access to the server.

Note: You cannot use a full backup to restore your site via the cPanel interface. The file must be downloaded and decompressed prior to restoration. Once the file has been decompressed, you will be able to upload and restore individual pieces of your website contained within the full backup.

Restoring From Backup

To restore a full backup created from a cPanel server you must transfer the archive file to the server you want to retore it to and save it in the /home folder. Transferring this file is best done via SCP, if your transferring from server to server and have access to the ssh interface for both servers you can use the command line scp command like this on the server you backed up:

#scp filename user@ipaddress:/home

If you do not have ssh access to both servers you should use your FTP credentials to move the file from the server you backed up to the new server or to your desktop for transfer to the new server via WinSCP (See article titled "Uploading Content to Your Server"). Or you can use file manager in cPanel to move the file to the public_html directory of your website (/home/cpanel_username/public_html) and download it using your browser at http://website_name/backup_filename or via wget on the server you are transferring the data to with wget http://website_name/backup_filename. Ensure your present working directory is appropriate for the download. The restorepkg script will search for the archive file in the following locations:

/home
/home2
/home3
/root
/usr
/usr/home
/web

Once the archive file is fully transferred and located in /home, login to the server you are restoring the account to via ssh (see article "Getting Conencted to Your Server"), and run this series of commands:

cd /home
/scripts/restorepkg username

**Please note that if you already created the user account you are trying to restore this method will fail with errors and corrupt data you may have already uploaded or created. To bypass this error and destroy all data on the previously created account use the --force switch before the username (/scripts/restorepkg --force username).

Configure Changes for cPanel

After the restore is compelted your website should be viewable. However there are some errors you may see instead. Here are some common items that may need to be reconfigured to bring your site online:

1. If you receive a database related error such as:

Error establishing a database connection

or

Warning: mysql_connect(): Access denied for user: 'db_username@localhost' (Using password: YES) in /home/username/public_html/includes/db.php on line 19
Unable to connect to database server!

This means is that your website cannot communicate with your database due to user account credentials. You need to assign a database username and reconfigure your website's database settings.

Login to your cPanel and click the "MySQL Databases" icon.
Scroll down untill you see MySQL Users > NewUser.
The username can be any username.
Pick any random password. Copy the password and keep it ready.
Enter the password twice and then press the "Create User" button.

The user has now been added, but it has not been assigned to a database.

In the same area under MySQL Users you will see a second section called Add User To Database.
Choose the username you just created from the drop down. (Notice that cPanel will automatically prepend your database name with your cPanel username. Copy this username and keep it ready.
Next, choose the name of your database and click the "Submit" button. If you don't know which database name to use, skip this step for now.

Now you need to locate your database configuration file.

If you have a general error message like the first example, then contact your we developer to determine the location.
If you have a specific error message like the second example, then the error tells us the location. In our example the error says "in /home/username/public_html/includes/db.php on line 19". That is where you need to go.

It is time to reconfigure your website's database settings.

1. Go to the configuration file and choose to Edit.

2. Look in the code for a place where your database name is defined. Here is the example of what we see:

define('DB_NAME', 'db_name');
define('DB_USER', 'db_username');
define('DB_PASSWORD', 'db_user_password');
define('DB_HOST', 'localhost');

3. The database name is very important; it must have your new cPanel name in the first part. Update the part before the underscore, but change nothing after the underscore.

4. Next, get the database username and password you set aside and replace the ones in the file.

5. Save the file and you are done! Refresh your webpage to see if it works.

**Note

It is not uncommon that some configuration changes may be required to database configuration file. Here is a short list of some common database applications that may need some changes and their associated configuration files:

WordPress: wp-config.php
Joomla: configuration.php
Magento: app/etc/local.xml


Was this answer helpful?

« Back