Backup cPanel and Restore to Another Server
Posted by Tegan King on 22 December 2016 03:45 PM
Backup cPanel and Restore to Another Server
Making a Backup in cPanel
To create a full backup:
1. Select Backup from the first page.
You can store the files in your home directory on your web server by selecting Home Directory from the pull-down menu.
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:
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:
**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
Warning: mysql_connect(): Access denied for user: 'db_username@localhost' (Using password: YES) in /home/username/public_html/includes/db.php on line 19
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.
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.
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.
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:
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.
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: