How to backup and restore AIX volume group other than rootvg

root's picture

In this tutorial you can see how to backup a volume group, move a volume group from one system to another, convert jfs to jfs2, shrink and mirror/unmirror filesystems.

In our example, the VG to backup is datavg and we will try to make an image of it from source machine and restore it to target machine.

1. Backup datavg from source machine with savevg command:

NOTE: The option "i" is needed if you want savevg to execute the command mkvgdata and create the data file /tmp/vgdata/datavg/datavg.data. You need that if you want to alter the modification of datavg (e.g. convert jfs to jfs2, modify PP size, transform mirrored vg to normal one, etc.).
source# savevg -eiXf /backups-tmp/source-datavg.sysb datavg

Creating information file for volume group datavg.

Creating list of files to back up 
Backing up 17517 files..............................
3790 of 17517 files backed up (21%)...........................

17517 of 17517 files backed up (100%)
0512-038 savevg: Backup Completed Successfully.

2. Verify and validate the backup image before copying it:

source# restbyname -T -q -v -f /backups-tmp/source-datavg.sysb 1>/dev/null
New volume on /backups-tmp/source-datavg.sysb:
 Cluster 51200 bytes (100 blocks).
    Volume number 1
    Date of backup: Wed Dec 17 11:05:58 2014
    Files backed up by name
    User root
    files archived: 17517
source# ls -la /backups-tmp/source-datavg.sysb
-rw-------    1 root     system   5392998400 Dec 17 11:15 /backups-tmp/source-datavg.sysb

3. Transfer the backup image to the target machine. You can use ssh, scp, ftp, wget, whatever. I leave it to you. The most important is at step 4 to have the image on target machine.

source# scp target:/backups-tmp/source-datavg.sysb .
target's password: 
source-datavg.sysb                             100% 5143MB 10MB/s 0:08:58    

4. In order to restore a volume group, you need free disk(s). You can restore it to as many disks as you want. The most important is to have at least the same total size as the previously backed up volume group. For example, if you want just to restore datavg to hdisk1 and hdisk2, use the following command:

target# restvg -f /tmp/source-datavg.sysb hdisk1 hdisk2

IF YOU ARE SATISFIED WITH YOUR RESTORE, THERE IS NO NEED TO READ FORWARD, UNLESS YOU ARE INTERESTED OR SIMPLY CURIOUS!!!


Let's say you have a jfs filesystem on source and you want it to be recreated as jfs2 on the target machine. For that, you have 2 possibilities:

A. Go back to the source machine, edit the files /tmp/vgdata/datavg/datavg.data /tmp/vgdata/datavg/filesystems and run again savevg command but this time without the option "i".


PS: If you do not know what exactly to modify in the mentioned files, look for a bit of explanation at the end of this article (section X).
source# savevg -eXf /backups-tmp/source-datavg.sysb datavg

Obviously, you will have to copy again the backup image from source to target server and execute the restore command below without extra options:
target# restvg -f /tmp/source-datavg.sysb hdiskX hdiskY

B. Sometimes it is no more possible to go back to source machine from various reasons so you have to do everything with the existing backup image. For that, prior to restvg command, you have to restore the needed files from the same backup image. Read on.

List and restore the needed files from the backup image:

target# listvgbackup -f /tmp/source-datavg.sysb | grep -E "datavg.data|filesystems"
New volume on /tmp/source-datavg.sysb:
 Cluster 51200 bytes (100 blocks).
    Volume number 1
    Date of backup: Wed Dec 17 11:05:58 2014
    Files backed up by name
    User root
        3393 ./tmp/vgdata/datavg/filesystems
        8941 ./tmp/vgdata/datavg/datavg.data
    files archived: 17517

target# restorevgfiles -r -f /tmp/source-datavg.sysb ./tmp/vgdata/datavg/filesystems
New volume on /tmp/source-datavg.sysb:
 Cluster 51200 bytes (100 blocks).
    Volume number 1
    Date of backup: Wed Dec 17 11:05:58 2014
    Files backed up by name
    User root
x         3393 ./tmp/vgdata/datavg/filesystems
    total size: 3393
    files restored: 1

target# restorevgfiles -r -f /tmp/source-datavg.sysb ./tmp/vgdata/datavg/datavg.data
New volume on /tmp/source-datavg.sysb:
 Cluster 51200 bytes (100 blocks).
    Volume number 1
    Date of backup: Wed Dec 17 11:05:58 2014
    Files backed up by name
    User root
x         8941 ./tmp/vgdata/datavg/datavg.data
    total size: 8941
    files restored: 1

The files will be saved with their full path starting from the directory you are in (if you were in /tmp, your files will be here: /tmp/tmp/vgdata/datavg/) so copy them to /tmp/datavg and edit them as you want. Refer to section X (at the end of this article) for that.

Now here is the tricky part. The command restvg have the option "-d" which allows you to specify a custom data vg file (e.g. /tmp/datavg.data or whatever), but you cannot specify the filesystems file and your jfs2 filesystems will not mount because the /etc/filesystems file will be updated with the information restored from the backup image in /tmp/vgdata/datavg/filesystems and you will get error when executing the restore command.

target# restvg -d /tmp/datavg.data -f /tmp/source-datavg.sysb hdisk1

  Will create the Volume Group: datavg
  Target Disks: hdisk1
  Allocation Policy:
        Shrink Filesystems:     yes
        Preserve Physical Partitions for each Logical Volume:   no


Enter y to continue: y
datavg
lv00
loglv02
fslv00
fslv01
fslv04

0512-035 restvg: Failed Mounting the Filesystem /jfs/mount.  Restore of Volume Group canceled.

Trying to mount manually the filesystem will reveal the "why":

target# mount /jfs/mount
mount: Stat of log device ("/dev/loglv01") failed

And by looking inside /etc/filesystems you will see more exactly why:

target# grep -p /jfs/mount /etc/filesystems
/jfs/mount:
        dev             = /dev/lv00
        vfs             = jfs
        log             = /dev/loglv01
        mount           = true
        options         = rw
        account         = false

Furthermore, if you specify with "-d" the file in it's original location /tmp/vgdata/datavg/datavg.data, assuming you will get the modified filesystem file too from the same path, both will be overwritten automatically with the ones from the backup image so you will arrive nowhere.
In this situation, we forget about "-d" option and follow the steps below (unofficial, probably unsupported but it simply works):

Run the command restvg but DO NOT TYPE "y"+"ENTER" when you are asked to:

target# restvg -f /tmp/source-datavg.sysb hdisk1

  Will create the Volume Group: datavg
  Target Disks: hdisk1
  Allocation Policy:
        Shrink Filesystems:     no
        Preserve Physical Partitions for each Logical Volume:   no


Enter y to continue:  <- STOP HERE

Instead, open another terminal and copy the modified files over the ones restored from the image:

target# ls -la /tmp/datavg
total 48
drwx------    2 root     system          256 Dec 18 09:45 .
drwxrwxrwt   40 bin      bin            8192 Dec 18 10:45 ..
-rw-------    1 root     system         8596 Dec 18 09:45 datavg.data
-rw-------    1 root     system         3395 Dec 18 09:45 filesystems
target# cp /tmp/datavg/datavg.data /tmp/vgdata/datavg/datavg.data
target# cp /tmp/datavg/filesystems /tmp/vgdata/datavg/filesystems
target# ls -la /tmp/vgdata/datavg/datavg.data /tmp/vgdata/datavg/filesystems
-rw-------    1 root     system         8596 Dec 18 10:46 /tmp/vgdata/datavg/datavg.data
-rw-------    1 root     system         3395 Dec 18 10:46 /tmp/vgdata/datavg/filesystems

Now go back to the terminal where you initiated restvg command and move forward (by typing y and ENTER).
Magically, the restore will go trough and you will have the desired jfs2 filesystems:

target# restvg -f /tmp/source-datavg.sysb hdisk1

  Will create the Volume Group: datavg
  Target Disks: hdisk1
  Allocation Policy:
        Shrink Filesystems:     no
        Preserve Physical Partitions for each Logical Volume:   no


Enter y to continue: y
datavg
lv00
loglv02
fslv00
fslv01
fslv04
New volume on /tmp/source-datavg.sysb:
 Cluster 51200 bytes (100 blocks).
    Volume number 1
    Date of backup: Wed Dec 17 11:05:58 2014
    Files backed up by name
    User root

[...USELESS OUTPUT SURPRESSED...]

    total size: 7735916130
    files restored: 17517

target# lsvg -l datavg
datavg:
LV NAME             TYPE       LPs     PPs     PVs  LV STATE      MOUNT POINT
lv00                jfs2       48      48      1    open/syncd    /jfs/mount
loglv02             jfs2log    1       1       1    open/syncd    N/A
fslv00              jfs2       64      64      1    open/syncd    /home/db2inst1
fslv01              jfs2       24      24      1    open/syncd    /db2/backup
fslv04              jfs2       24      24      1    open/syncd    /db2/log

HOORAY, YOU ARE DONE! You have your files restore on this new system and all filesystems which were previousy jfs as jfs2.


X. This part is ONLY if you need special modifications of datavg.data and filesystems files.


Edit the file /tmp/datavg/datavg.data and modify all that you need. In my example, I just modified jfs filesystems to jfs2:
- replaced all TYPE= jfs with TYPE= jfs2;
- replaced all FS_TAG= log=/dev/loglv01 with FS_TAG= vfs=jfs2:log=/dev/loglv02.
- delete the jfslog lv stanza because you won't need it anymore.
- edit at the end of the file the stanza(s) for jfs filesystem(s) as in the example below:
from:
fs_data:
        FS_NAME= /jfs/mount
        FS_SIZE= 6291456
        FS_MIN_SIZE= 4433864
        FS_LV= /dev/lv00
        FS_FS= 4096
        FS_NBPI= 4096
        FS_COMPRESS= no
        FS_BF= false
        FS_AGSIZE= 8

to:
fs_data:
        FS_NAME= /jfs/mount
        FS_SIZE= 6291456
        FS_MIN_SIZE= 4433864
        FS_LV= /dev/lv00
        FS_JFS2_BS= 4096
        FS_JFS2_SPARSE= yes
        FS_JFS2_INLINELOG= no
        FS_JFS2_SIZEINLINELOG= 0
        FS_JFS2_EAFORMAT= v1
        FS_JFS2_QUOTA= no
        FS_JFS2_DMAPI= no
        FS_JFS2_VIX= no

- modify all entries related to jfs filesystem in /tmp/datavg/filesystems like in the example below:
from:
/jfs/mount:
        dev             = /dev/lv00
        vfs             = jfs
        log             = /dev/loglv01
        mount           = true
        options         = rw
        account         = false

to:
/jfs/mount:
        dev             = /dev/lv00
        vfs             = jfs2
        log             = /dev/loglv02
        mount           = true
        options         = rw
        account         = false

- If you need to create the filesystems as small as possible, you can modify SHRINK= no to SHRINK= yes.
- In case your source vg was on mirrored VG and you want to restore it on a simple one, modify on ALL LVs COPIES value to 1, and the PP value equal to the LPs value:
- COPIES = 2 to COPIES = 1
- PP= with the exact number of LPs=

Extra TIP:


If during the restoration progress you found out something is not as you want, you can simply remove datavg and start all over:
target# for i in $(lsvg -l datavg | grep -vE "datavg|MOUNT|N/A" | awk '{print $7}'); do umount $i; done
target# varyoffvg datavg
target# exportvg datavg

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself!
Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.