Restore Account Data from Backups Print

  • 0

The following is the procedure for restoring a Cpanel/WHM account from backup, with domain/account customer.biz as example:-

I. Simple Restore (From CPanel Backup)

1. Check where the account/domain is hosted, in WHMCS (Note down "Server" and "Username" in product/service item). For customer.biz:-
https://www.nocser.net/clients/admin/clientsservices.php?userid=208&id=246
( Server: bizvm.nocser.net , Username: customerbiz ).

2. Go to the hosting server's WHM --> Backup Configuration. Scroll down to "Additional Destinations", and edit the destination. Note down the "Remote Host", "Remote Account Username" and "Backup Directory". ( Example: for bizvm.nocser.net, host: 42.0.20.33, username: ftpbackup, directory: /bizvm.nocser.net )

3. SSH to the "Remote Host" via credentials in tech.nocser.net. Then
# cd ~<remote account username>
( Example: for bizvm.nocser.net, # cd ~ftpbackup )
# cd <Backup Directory without leading slash (/)>
( Example: for bizvm.nocser.net, # cd bizvm.nocser.net )

4. Find available backup snapshots for this account/domain.
# find . -iname "<Username>.*"
( Example: for customer.biz: # find . -iname "customerbiz.*" )
- Locate the latest/required available backup file
- Copy the file to the original server's home directory via scp:-
# cd <path-to-file>
# scp -vrpP 22222 <Username>.tar <hosting-server>:/home/
[ If backup file not found, the account might have been terminated/suspended for some time. Proceed to II. Restore from VM Backup ]

5. Go to hosting server's WHM --> Restore a Full Backup/cpmove File
- Enter account name ( eg customerbiz )
- Click "Restore". Wait for restoration to complete.
- If restoration failed due to existing account with same name, verify that the account is the one required for restore, then either:-
i) repeat restore using WHM --> Backup Restoration or ii) Delete the account and retry restore using above method.


II. Restore From VM Backup
- Only use this step if above procedure fails. In the case of customer.biz, the account was suspended/terminated for some time such that no cpanel backup exists.

1. Go to SolusVM and search for the hosting server's VM entry. (Example: In customer.biz case: bizvm.nocser.net)
- In VM details, take note of "ID:" ( for bizvm.nocser.net: ID: kvm000 ), and "Disk Space" ( for bizvm.nocser.net: 320GB ), and click on "Host node" ( Example: for bizvm.nocser.net: server00 )

2. In node details, click on "Auto FTP Backup". Take note the "IP or hostname", "Username", and "Directory". ( Example: for server00, IP: 10.0.20.33, Username: ftpbackup2 , Directory: /solus-node-backup ).

3. SSH to the backup server IP. If IP starts with 10.0.x.x, change the 1st part to 42 ( Example: 10.0.20.33 --> 42.0.20.33 ), using credentials found in tech.nocser.net . Then:-
# cd ~<Username>
( Example: # cd ~ftpbackup2 )
# cd <Directory without leading slash>
( Example: # cd solus-node-backup )

4. Find available backup snapshots for this VM.
# find . -iname "*<VM ID>*.bz -exec ls -lh {} \;"
( Example: for bizvm.nocser.net: # find . -iname "*kvm000*.bz -exec ls -lh {} \;" )
- Locate the latest available backup file, and take note of its size ( Example: for kvm000, size is 105GB )
# pwd
( Take note of path to backup file )

5. SSH to hosting node ( Example: for bizvm.nocser.net: server00 )

6. Check available space:-
# vgdisplay
- Take note of "VG Name" ( Example: for server00: VG Name: vg_server00 )
- Look for "Free PE / Size", make sure available size is at least the same as "Disk Space" in the VM details + backup file size.
( Example: server00: Free PE / Size 257476 / 1005.77 GiB , backup file size is 105GB, bizvm.nocser.net's Disk Space is 320GB)

7. Create temporary LV for backup file:-
# lvcreate -L<Backup File Size>G -n lv_restore_snapshot <VG Name>
( Example: for bizvm.nocser.net, in server00 run: # lvcreate -L 120G -n lv_restore_snapshot vg_server00 )
- Make sure LV is created OK:-
# lvdisplay
(Look for lv_restore_snapshot and check the details).
- Prepare ext filesystem ( if CentOS 5.x, use ext3. If CentOS 6.x, use ext4 ):-
# mkfs.ext4 /dev/<VG Name>/lv_restore_snapshot>
( Example: for server00: # mkfs.ext4 /dev/vg_server00/lv_restore_snapshot )

8. Mount temporary LV to a temporary directory:-
# mkdir /mnt/lv_restore_snapshot
# mount /dev/<VG Name>/lv_restore_snapshot /mnt/lv_restore_snapshot
( Example: for server00: # mount /dev/vg_server00/lv_restore_snapshot /mnt/lv_restore_snapshot )
- Make sure LV is mounted OK:-
# df -h
(Look for lv_restore_snapshot and check the details).

9. In node (eg server00), copy backup file from backup server to mounted temporary directory:-
# screen
# cd /mnt/lv_restore_snapshot
# scp -vrpP 22222 <Backup Server IP>:<Path to Backup File>/<Backup File> .
( Example: for bizvm.nocser.net @ server00: # scp -vrpP 22222 10.0.20.33:/export/solusvm/backups/solus-node-backup/361-kvm-kvm000-2.bz .

10. Create temporary LV for restoration:-
# lvcreate -L<VM Disk Space>G -n lv_restore <VG Name>
( Example: for bizvm.nocser.net, in server00 run: # lvcreate -L 320G -n lv_restore vg_server00 )
- Make sure LV is created OK:-
# lvdisplay
(Look for lv_restore and check the details).

11. Restore the downloaded backup file into the temporary LV (may take a long time depending on size of VM Disk Space):-
# bunzip2 -c <Backup File> | dd of=/dev/<VG Name>/lv_restore
( Example: for bizvm.nocser.net, in server00 run: # bunzip2 -c 361-kvm-kvm000-2.bz | dd of=/dev/vg_server00/lv_restore

12. Make sure partition table in restored LVM is intact:-
# fdisk -l /dev/<VG Name>/lv_restore
( Example: for server00 run: # fdisk -l /dev/vg_server00/lv_restore )

13. In order to mount the "LVM with LVM" for data extraction, use kpartx:-
# yum install kpartx
- Make partitions within LVM available
# kpartx -av /dev/<VG Name>/lv_restore
( Example: for server00 run: # kpartx -av /dev/vg_server00/lv_restore
add map vg_server00-lv_restore1 (253:10): 0 1024000 linear /dev/vg_server00/lv_restore 2048
add map vg_server00-lv_restore2 (253:11): 0 670062592 linear /dev/vg_server00/lv_restore 1026048
)
- Scan and expose all LVM volume groups within the LVM for mounting:-
# vgscan
( Example: for server00:-
Found volume group "vg_bizvm" using metadata type lvm2
Found volume group "vg_server00" using metadata type lvm2
)
- Make all LVM volumes active and ready for use
# vgchange -ay
( Example: for server00:-
3 logical volume(s) in volume group "vg_bizvm" now active
8 logical volume(s) in volume group "vg_server00" now active
)
- List available mountable LVMs inside the additional volume group found
# ls -l /dev/mapper/<Newly discovered VG Name>*
( Example: for server00, vg_bizvm is the new volume group found, to list:-
# ls -l /dev/mapper/vg_bizvm*
lrwxrwxrwx. 1 root root 8 Jan 8 10:09 /dev/mapper/vg_bizvm-lv_home -> ../dm-13
lrwxrwxrwx. 1 root root 8 Jan 8 10:09 /dev/mapper/vg_bizvm-lv_root -> ../dm-12
lrwxrwxrwx. 1 root root 8 Jan 8 10:09 /dev/mapper/vg_bizvm-lv_swap -> ../dm-14
)

14. Mount the desired partition(s) to temporary directory(ies) e.g:-
# mkdir /mnt/lv_restore
# mount /dev/mapper/<Newly discovered VG Name>-<Desired lv> /mnt/lv_restore
( Example: for server00: # mount /dev/mapper/vg_bizvm-lv_home /mnt/lv_restore )
- Make sure LV is mounted OK:-
# df -h
(Look for lv_restore and check the details).

15. Locate the desired data to be restored and manually copy to the VM.
( Example: to recover account 'customerbiz' to bizvm.nocser.net:-
- Go to WHM @ bizvm, create account customerbiz matching the details in WHMCS.
- SSH bizvm, and rename the directory: # cd /home; mv -vi customerbiz customerbiz.orig
- SSH back to server00, and copy over the files from backup:-
# cd /mnt/lv_restore/
- Copy home directory:-
# rsync -ave 'ssh -p 22222' customerbiz bizvm.nocser.net:/home/
- Copy databases to temp directory in bizvm:-
# umount /mnt/lv_restore/
# mount /dev/mapper/vg_bizvm-lv_root /mnt/lv_restore/
# cd /mnt/lv_restore
# rsync -ave 'ssh -p 22222' var/lib/mysql/customerbiz* bizvm.nocser.net:/root/
- SSH bizvm, and correct permissions:-
# cd /home
# chown -R customerbiz:customerbiz customerbiz
# chgrp -R mail customerbiz/etc
# chgrp nobody customerbiz/public_html
- Test browse http://customer.biz and correct database permissions following config
files in /home/customerbiz/public_html:-
- In WHM -> List Accounts -> customerbiz --> CPanel --> MySQL Database Wizard
- Recreate each restored database which was copied in /root/, following
credentials in config files in /home/customerbiz/public_html (look for config files
or # grep -r "customerbiz_" /home/customerbiz/public_html and open the file ).

16. Clean up when done (Important! Otherwise will occupy space in server)
# umount /mnt/lv_restore
vgchange -an <Newly discovered VG Name>
( Example: for server00: # vgchange -an vg_bizvm )
# kpartx -d /dev/<VG Name>/lv_restore
( Example: for server00: # kpartx -d /dev/vg_server00/lv_restore )
# lvremove <VG Name>/lv_restore
( Example: for server00: # lvremove vg_server00/lv_restore )
# lvremove <VG Name>/lv_restore_snapshot
( Example: for server00: # lvremove vg_server00/lv_restore_snapshot )
- Verify temporary LVs no longer exist.
# lvdisplay
- Verify volume group free space back to normal
# vgdisplay

DONE.

APPENDIX

1. Sometimes you may encounter the following error during bunzip2 of backup file:-

[root@server00 lv_restore_snapshot]# bunzip2 -c 361-kvm-kvm000-1.bz | dd of=/dev/vg_server00/lv_restore

bunzip2: Compressed file ends unexpectedly;
perhaps it is corrupted? *Possible* reason follows.
bunzip2: Success
Input file = 361-kvm-kvm000-1.bz, output file = (stdout)

It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.

You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.

350676796+1 records in
350676796+1 records out
179546520000 bytes (180 GB) copied, 18613.1 s, 9.6 MB/s
[root@server00 lv_restore_snapshot]#

- Ignore the error and resume with the steps following it. You might be able
to still mount the needed partition. (If cannot mount later, use another
backup file)

 


Was this answer helpful?

« Back