title: Full Disaster Recovery created at: Wed Nov 20 2024 10:15:57 GMT+0000 (Coordinated Universal Time) updated at: Sat Feb 08 2025 14:22:44 GMT+0000 (Coordinated Universal Time) --- # Full Disaster Recovery # Overview !! Warning: !! **Only** experienced system administrators should use the procedures in this document. !! WebPros International, LLC **cannot** support failed hard drives or hard drive recovery. We are **not** responsible for any data loss. In some circumstances, you may need to completely restore your server from a crashed or failed hard drive. # Prepare to restore your server If you have recent remote backups and can’t boot the failed hard drive, you can proceed to [rebuilding your server](https://docs.cpanel.net/knowledge-base/general-systems-administration/full-disaster-recovery/#rebuild-the-server) . !! Warning: !! If you don’t have recent remote backups, we strongly recommend that you rework your backup strategy to store regularly-scheduled backups in a remote location. If you **don’t** have recent remote backups but **can** boot the failed hard drive, perform one of the following actions: * If you **can** access WHM from the failed hard drive, create a backup with WHM’s [*Backup Configuration*](https://docs.cpanel.net/whm/backup/backup-configuration) interface (*WHM » Home » Backup » Backup Configuration*). * If you **can’t** access WHM from the failed hard drive, run the [`/usr/local/cpanel/scripts/pkgacct`](https://docs.cpanel.net/whm/scripts/the-pkgacct-script) script. After you complete the backup procedure, transfer the backup files to a remote location. # Rebuild the server Some data centers and hosting providers offer system restoration and imaging. Contact your hosting provider for more information. !! Important: !! The replacement cPanel & WHM server should contain identical software to the original server. This includes MySQL or MariaDB, PHP, PHP extensions, Apache, Apache extensions, and other software options. If you do not use the same version of MySQL or MariaDB on the new server, you may encounter serious errors. !! If you wish to update any of the software on the server, we **strongly** recommend that you perform the transfer or restoration first and then perform any updates. ## Manually provision the new hard drive !! Important: !! If you use an ISO, get it from the operating system’s official mirrors. Third-party drive images may cause unexpected problems. To manually provision the new hard drive, perform the following steps: 1. Install a new hard drive as the primary hard drive and make the old hard drive the secondary hard drive. 2. Install the operating system. For more information, read our [Installation Guide](https://docs.cpanel.net/installation-guide/) documentation. 3. Install cPanel & WHM with the following commands: ```bash cd /home curl -o latest -L https://securedownloads.cpanel.net/latest sh latest ``` ## Request a new hard drive and image Make sure to request that the data center installs your old hard drive as a secondary drive. After they finish this, perform one of the following actions to update cPanel & WHM to the latest version: * Run the [`/usr/local/cpanel/scripts/upcp`](https://docs.cpanel.net/whm/scripts/the-upcp-script) script. * Use WHM’s [*Upgrade to Latest Version*](https://docs.cpanel.net/whm/cpanel/upgrade-to-latest-version) interface (*WHM » Home » cPanel » Upgrade to Latest Version*). # Recover your files If you don’t have a recent remote backup and can’t boot the failed hard drive on your server, you can proceed to [restoring your files](https://docs.cpanel.net/knowledge-base/general-systems-administration/full-disaster-recovery/#restore-your-files) . In all other scenarios, perform the following steps as the `root` user to recover your files: 1. Mount the secondary drive in a `chroot` environment. To do this, run the following commands, where `sdb1` represents the device name of your secondary drive: ```bash mkdir /mnt/chroot/ mount /dev/sdb1 /mnt/chroot/ ``` !! mportant:\ You **must** mount the drive and partitions before you can bind mount the filesystems. 1. Mount the `proc`, `dev`, and `sys` filesystems in a `chroot` environment. To do this, run the following commands: ```bash mount --bind /proc /mnt/chroot/proc mount --rbind /dev /mnt/chroot/dev mount --bind /sys /mnt/chroot/sys ``` !! Note:\ We use the `rbind` command instead of the `bind` command for the `dev` directory in order to ensure that we mount the `/dev/pts` partition properly. 1. Run the `grep chroot /etc/mtab` command to verify that the system properly mounted each filesystem. Your results should resemble the following output: ```bash /dev/sdb1 /mnt/chroot none rw,bind 0 0 /mnt/chroot/proc /proc none rw,bind 0 0 /mnt/chroot/dev /dev none rw,bind 0 0 /mnt/chroot/sys /sys none rw,bind 0 0 ``` 1. Run the [`tmux` command](https://man7.org/linux/man-pages/man1/tmux.1.html) to start a `tmux` session. This lets you use the `chroot` environment in a session that you can [reconnect to if you lose your connection](https://docs.cpanel.net/knowledge-base/general-systems-administration/full-disaster-recovery/#reconnect-to-a-tmux-session) . Disconnections from sessions with `chroot` environments can cause problems for services such as MySQL, which may experience InnoDB issues. 2. Run the following commands to let the system perform as if you booted into the crashed drive: ```bash chroot /mnt/chroot /bin/bash -l export PS1="{chrooted}$PS1" ``` Your results should resemble the following output: ```javascript {chrooted}bash-4.1# ``` 1. Run the `source /etc/environment && source /etc/profile` command to recover the cPanel & WHM environment. 2. To start required services from the old hard drive, run the necessary commands to start any services that the [`/usr/local/cpanel/scripts/pkgacct`](https://docs.cpanel.net/whm/scripts/the-pkgacct-script) script will require. For example, you will need the MySQL service for Webmail databases, or the PostgreSQL service if you use that database service. To start MySQL, run the following command: ```bash /usr/sbin/mysqld --daemonize --user=mysql --pid-file=/var/run/mysqld/mysqld.pid ${MYSQLD_OPTS} ``` 1. To start `dnsadmin`, run the following command: ```bash /usr/local/cpanel/libexec/dnsadmin-startup --start ``` 1. To back up accounts from the old hard drive, run the following commands. These commands store the backups in the `/mnt/chroot/home` directory and also stores the feature lists and packages settings: ```bash cd /var/cpanel/users for i in `ls -1 *`; do /scripts/pkgacct --skipdnszones $i; done ``` !! Warning:\ We **strongly** recommend that you do **not** use the `rsync` command to back up accounts. This may cause issues with services such as MySQL. 1. To back up service configurations from the old hard drive, run the following commands: ```bash cd /usr/local/cpanel bin/cpconftool --modules=cpanel::smtp::exim,cpanel::system::backups,cpanel::system::mysql,cpanel::system::whmconf,cpanel::easy::apache,cpanel::ui::themes --backup ``` The results will resemble the following output: ```bash Backup Successful /home/whm-config-backup-configuration__to__backup-10.550000-1452006507.tar.gz ``` 1. Transfer backup files to remote storage. Use the `scp` command or the `rsync` command to copy the files to a remote storage location. !! Important:\ You can directly transfer the files from the old hard drive to the new hard drive. However, we **strongly** recommend that you transfer them to a remote location first. This protects your backup files from hardware issues that may have caused the hard drive to fail. 1. Run the following commands to stop all services in the `chroot` environment, unmount the filesystems, and exit the `chroot` environment: ```bash service mysql stop umount {/proc,/dev,/sys} exit ``` 1. To close the `tmux` session, run the `detach` command. To end the `tmux` session, run the `kill-session` command. # Restore your files To restore the content from the backup files to your new hard drive in the server, perform the following steps as the `root` user: 1. Run the `scp` command or the `rsync` command to copy the files from the remote location to the new hard drive. 2. To restore feature lists to the server, run the following commands: ```bash cd /backups tar -xzvf _var_cpanel.tar.gz var/cpanel/features tar -xzvf _var_cpanel.tar.gz var/cpanel/features ``` 1. To restore accounts to the server, run the following commands, where `BACKUPDIRECTORY/TYPE/DATE/` represents your backup directory: ```bash cd BACKUPDIRECTORY/TYPE/DATE/accounts/ for archive in `ls`; do /scripts/restorepkg $archive; done ``` !! More:\ For more information, read our [The `restorepkg` Script](https://docs.cpanel.net/whm/scripts/the-restorepkg-script) documentation. 1. Run the [`/usr/local/cpanel/bin/cpconftool`](https://docs.cpanel.net/whm/scripts/the-cpconftool-script) script to restore the configuration settings for Apache, backups, cPanel themes, Exim, MySQL, and WHM to the server. 2. If you run CloudLinux, restore CloudLinux settings to the server. # Test the server Test the websites, applications, and services on the new server. Make certain that you have successfully restored the server’s data and configuration. # Reconnect to a tmux session To reconnect to a `tmux` session, perform the following steps as the `root` user: 1. Run the `tmux ls` command to list your active sessions. Your results should resemble the following output: ```bash example: 1 windows (created Thu Sep 26 11:37:29 2024) (attached) example2: 1 windows (created Thu Sep 26 11:38:08 2024) (attached) ``` 1. Run the `tmux a -t example` command to reconnect to the session, where `example` is the session’s name.