The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Guide: Create account backups from a crashed hard drive

Discussion in 'Workarounds and Optimization' started by cPanelChrisI, Aug 7, 2014.

  1. cPanelChrisI

    cPanelChrisI Technical Analyst
    Staff Member

    Joined:
    Mar 24, 2014
    Messages:
    2
    Likes Received:
    3
    Trophy Points:
    3
    cPanel Access Level:
    Root Administrator
    CPANEL IS NOT ABLE TO SUPPORT FAILING HARD DRIVES OR HARD DRIVE RECOVERY. THIS IS ONLY A GUIDE. PLEASE TAKE CARE WITH YOUR DATA AND WE ARE NOT RESPONSIBLE FOR ANY DATA LOSS.


    Sometimes there are cases when you do not have backups available and your hard drive has crashed. This page is meant to help as a guide in using pkgacct to backup the files from the failed drive.


    Steps:

    1) Setup old root directory in chroot.
    2) Mount /proc, /dev and /sys into the chroot.
    3) Enter the chroot in screen
    4) Get environmental information from the old server
    5) Start services needed by pkgacct
    6) Package the accounts
    7) Exit chroot and clean up
    8) Done!



    1) The first step is to get the old server's root directory set up. Any directory is fine as long as the /home and other system partitions are mounted correctly within.

    The following will help you mount a secondary drive. You must mount the drive and partitions first, before you can bind mount the filesystems. Please note your drive name and partition may be named differently than below. You can use "fdisk -l" to get a list of your drives and partitions.

    Code:
    -bash-4.1# mount /dev/sdb1 /mnt/chroot/ 
    For the example, below assumes that the crashed root filesystem is mounted on /mnt/chroot/, and the home partition is mounted in /mnt/chroot/home. If the drive has more system partitions they also need to be mounted. You should be able to make sure those are mounted by using these commands.

    Code:
    -bash-4.1# mount --bind /mnt/chroot/ /
    -bash-4.1# mount --bind /mnt/chroot/home/ /home 
    Check /etc/mtab to ensure that system partitions are mounted correctly inside the chroot folder (ie. /mnt/chroot/).

    Code:
    -bash-4.1# grep chroot /etc/mtab
    /mnt/chroot / none rw,bind 0 0
    /mnt/chroot/home /home none rw,bind 0 0
    
    2) Mount the proc, dev, and sys filesystems into the chroot folder:

    Code:
    -bash-4.1# mount --bind /mnt/chroot/proc /proc
    -bash-4.1# mount --bind /mnt/chroot/dev /dev 
    -bash-4.1# mount --bind /mnt/chroot/sys /sys 
    Then verify that everything is mounted.

    Code:
    -bash-4.1# grep chroot /etc/mtab
    /mnt/chroot / none rw,bind 0 0
    /mnt/chroot/home /home 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
    3) Enter a chroot and use screen. Screen is a tool that will allow you to run a command and allow it to continue without killing it in the case that you lose your connection. That will help prevent your recovery process from being stopped in the middle or causing you to lose your chroot enviornment if you are disconnected. If mysql is running in the chroot, leaving it unexpectedly by not using screen could cause INNODB issues. If you do get disconnected, you are able to log back in, then run 'screen -ls' to list your active screens.

    Code:
    -bash-4.1# screen -ls
    There are screens on:
        12565.screen1   (Detached)
        12568.screen2   (Detached)
    2 Sockets in /var/run/screen/S-root.
    Then, you can reattach to the screen using 'screen -x screenname' in the case that you do get disconnected. For example:

    Code:
    -bash-4.1# screen -x 12565.screen1
    The chroot will now make /mnt/chroot/ into / as if you were booted into the crashed disk.

    Code:
    bash-4.1# screen
    bash-4.1# chroot /mnt/chroot /bin/bash -l
    bash-4.1# export PS1="{chrooted}$PS1"
    {chrooted}bash-4.1#
    4) Now that were inside the chroot we need to get our environmental information from the old server. This is accomplished with the following command.

    Code:
    {chrooted}bash-4.1# source /etc/environment && source /etc/profile
    5) Start any services needed for pkgacct. At a minimum, this requires that MySQL be started otherwise the webmail databases will cause pkgaccct to fail. People using PGSQL will also need that started as well.

    Code:
    {chrooted}bash-4.1# service mysql start
    Starting MySQL SUCCESS!
    6) Now, we can package the accounts. Make sure that at least two times the used space is free. If not you may run into a full disk situation by packaging the accounts.

    Code:
    {chrooted}bash-4.1# cd /var/cpanel/users
    {chrooted}bash-4.1# for i in `ls -1 *`; do /scripts/pkgacct $i; done
    It should place the backups in /mnt/chroot/home/.

    7) Thats it! Now, you should just need to scp or rsync them over to the new server or disk and restore them. Then, it's time to clean up. To leave the chroot, stop MySQL and PgSQL so that they exit cleanly. Then leaving bash should exit the chroot, allowing you to end the session.

    Code:
    {chrooted}bash-4.1# service mysql stop
    {chrooted}bash-4.1# umount {/proc,/dev,/sys}
    {chrooted}bash-4.1# exit
    logout
    bash-4.1# exit
    [screen is terminating]
    
    8) You're done!
     
    #1 cPanelChrisI, Aug 7, 2014
    Last edited by a moderator: Jun 4, 2015
    cPanelJesse likes this.
Loading...

Share This Page