AWS EC2: Restore a volume to the same server with different mount

If you accidentally delete some files in your EC2 , you don’t want to restore the whole volume, you just want to restore some files on it.

The easiest way to do this is to mount the backup volume to a different EC2 and mount it from there.

In case you want to mount that backup volume to the same server and you want to mount it to a different mount point to copy. There will be a challenge for you. Since the backup snapshot will have the same UUID with the existing file system , you will not be able to import it. You have to change the UUID

Check this link:

Restore Data Using DiskSafe for CentOS

Steps on how to Restore Data Using DiskSafe for CentOS

Refer to Protect CentOS with DiskSafe Agent to configure backup for CentOS prior continue for the restoration steps below

List all available snapshots and record the timestamp of 1584723025 (Snapshot 2)

[root@checkmk /]# dscli snapshot list sda
All snapshots of sda

Snapshot 1:
    Snapshot Timestamp    = 1584719577(2020/03/20 23:52:57)
    Snapshot Blocks Count = 18835968
    Mounted               = NO

Snapshot 2:
    Snapshot Timestamp    = 1584723025(2020/03/21 00:50:25)
    Snapshot Blocks Count = 12251136
    Mounted               = NO

Snapshot with Timestamp=1584723025 is mounted as /dev/sdd

[root@checkmk /]# dscli snapshot mount sda timestamp=1584723025
Mount snapshot with timestamp 1584723025 of sda

Snapshot mounted, get the information...

Snapshot device name: /dev/sdd
Command succeeded

How To Restore Data Using DiskSafe For CentOS From Snapshot

It is strongly recommended to study Beginner’s Guide to LVM (Logical Volume Management) to understand how Logical Volume Management (LVM) works before continue the steps below

Add Modify the /etc/lvm/lvm.conf file to include “a|^/dev/sdd2$|” in global_Filter to make the new /dev/sdd (Snapshot Disk) detected by system

vi /etc/lvm/lvm.conf

global_filter = [ "a|^/dev/disksafe/sda$|",  "a|^/dev/disksafe/sda2$|", "a|^/dev/sdd2$|", "r|.*/|" ]

/dev/sdd (Snapshot Disk) is detected as duplicate PV with the original /dev/sda

[root@checkmk /]# vgscan
  WARNING: found device with duplicate /dev/sdd2
  WARNING: Disabling lvmetad cache which does not support duplicate PVs.
  WARNING: Scan found duplicate PVs.
  WARNING: Not using lvmetad because cache update failed.
  Reading all physical volumes.  This may take a while...
  WARNING: Not using device /dev/sdd2 for PV H1ADa4-G7KT-h3MR-O8as-TEv3-368I-y77wVr.
  WARNING: PV H1ADa4-G7KT-h3MR-O8as-TEv3-368I-y77wVr prefers device /dev/disksafe/sda2 because of previ                                                                          ous preference.
  Found volume group "centos" using metadata type lvm2

[root@checkmk /]# pvdisplay
  WARNING: Not using lvmetad because duplicate PVs were found.
  WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
  WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
  WARNING: Not using device /dev/sdd2 for PV H1ADa4-G7KT-h3MR-O8as-TEv3-368I-y77wVr.
  WARNING: PV H1ADa4-G7KT-h3MR-O8as-TEv3-368I-y77wVr prefers device /dev/disksafe/sda2 because device is used by LV.
  --- Physical volume ---
  PV Name               /dev/disksafe/sda2
  VG Name               centos
  PV Size               <9.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2303
  Free PE               0
  Allocated PE          2303
  PV UUID               H1ADa4-G7KT-h3MR-O8as-TEv3-368I-y77wVr

Resolve the duplicate PV issue with vgimportclone

[root@checkmk /]# vgimportclone /dev/sdd2
  WARNING: Not using device /dev/sdd2 for PV H1ADa4-G7KT-h3MR-O8as-TEv3-368I-y77wVr.
  WARNING: PV H1ADa4-G7KT-h3MR-O8as-TEv3-368I-y77wVr prefers device /dev/disksafe/sda2 because device i                                                                          s used by LV.
[root@checkmk /]# vgimportclone /dev/sdd2
[root@checkmk /]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/disksafe/sda2
  VG Name               centos
  PV Size               <9.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2303
  Free PE               0
  Allocated PE          2303
  PV UUID               H1ADa4-G7KT-h3MR-O8as-TEv3-368I-y77wVr

  --- Physical volume ---
  PV Name               /dev/sdd2
  VG Name               centos11
  PV Size               <9.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2303
  Free PE               0
  Allocated PE          2303
  PV UUID               AkVEuf-8I4B-Rsl4-JPo9-WMt0-3fev-fjq8uZ

Rescan the VG & LV

[root@checkmk /]# vgscan
  Reading volume groups from cache.
  Found volume group "centos" using metadata type lvm2
  Found volume group "centos11" using metadata type lvm2
[root@checkmk /]# lvscan
  ACTIVE            '/dev/centos/swap' [1.00 GiB] inherit
  ACTIVE            '/dev/centos/root' [<8.00 GiB] inherit
  inactive          '/dev/centos11/swap' [1.00 GiB] inherit
  inactive          '/dev/centos11/root' [<8.00 GiB] inherit

Activate the Logical Volume (LV) that we are going to mount later

[root@checkmk /]# lvchange -ay /dev/centos11/root
[root@checkmk /]# lvscan
  ACTIVE            '/dev/centos/swap' [1.00 GiB] inherit
  ACTIVE            '/dev/centos/root' [<8.00 GiB] inherit
  inactive          '/dev/centos11/swap' [1.00 GiB] inherit
  ACTIVE            '/dev/centos11/root' [<8.00 GiB] inherit

Trying to mount the new Logical Volume (/dev/centos11/root) and get the duplicate UUID error below

[root@checkmk lvm]# mount /dev/centos11/root /mnt
mount: wrong fs type, bad option, bad superblock on /dev/mapper/centos11-root,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

[root@checkmk]dmesg
[10811.766108] XFS (dm-4): Filesystem has duplicate UUID 0623d025-0721-419a-8ce2-e8e9adc318d3

Mount the volume without UUID specified

[root@checkmk /]# mount -o nouuid /dev/centos11/root /mount
[root@checkmk /]# ls /mount
bin   dev  home  lib64  mnt    omd  proc  run   srv  tmp  var
boot  etc  lib   media  mount  opt  root  sbin  sys  usr

The snapshot is mounted successfully, and you can start to restore manually the data from the mounted volume

Remove the mounted snapshot volume once the data restoration is completed

[root@checkmk /]# lsblk
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0   10G  0 disk
├─sda1              8:1    0    1G  0 part
└─sda2              8:2    0    9G  0 part
sdb                 8:16   0   10G  0 disk
sdd                 8:48   0   10G  0 disk
├─sdd1              8:49   0    1G  0 part
└─sdd2              8:50   0    9G  0 part
  └─centos11-root 253:3    0    8G  0 lvm  /mount
sr0                11:0    1  942M  0 rom
disksafe!sda      188:0    0   10G  0 disk
├─disksafe!sda1   188:1    0    1G  0 part /boot
└─disksafe!sda2   188:2    0    9G  0 part
  ├─centos-swap   253:0    0    1G  0 lvm  [SWAP]
  └─centos-root   253:1    0    8G  0 lvm  /
[root@checkmk /]# umount /mount
[root@checkmk /]# dscli snapshot unmount sda timestamp=1584723025
Dismount snapshot with timestamp 1584723025 of sda

Command succeeded

Timeview In Management Console

Timeview (Snapshot Disk) is created from Timemark and assigned to CentOS host via ISCSI connection

Restore Data using DiskSafe for CentOS

Leave a Reply

Your email address will not be published. Required fields are marked *