Clone or Backup with Rsync

  • Hi


    First let me thank VolKer for the wonderful project. I am using for a while omv and i am very impressed. The only thing that is missing was backup and restore.
    So i was searching for a way to backup and easily restore in case that my cf card was crashing. I saw an article in google that i can mirror a hard disk with rsync. I tried it and it is working very good until now. Let me say that i am not a linux expert and so i am waiting for suggestions or improvements. I am testing this in virtualbox with two disk 2GB each
    So how did i do it. We assume that the omv is installed it in /dev/sda disk and the new disk is /dev/sdb. You will have to change the disks accordingly your setup. I advise everyone to remove the storage disks before doing anything and make a full bakup.


    We plugin the second disk to the computer


    We copy the partition table from the first disk to the new one for example.

    Zitat

    sfdisk -d /dev/sda | sfdisk /dev/sdb --force


    Format the root partition on the new disk

    Zitat

    mkfs.ext4 /dev/sdb1


    Format the swap partition on the new disk

    Zitat

    mkswap /dev/sdb5


    make a directory /mirror

    Zitat

    mkdir /mirror


    We find the uuid for the disk /dev/sdb1 with the following command. We are going to use the uuid from the second disk to mount it in the mirror directory

    Zitat

    blkid


    The output of the above command should be

    Zitat

    /dev/sda1: UUID="e950ee97-27fd-4596-b0ce-b85d8480eacd" TYPE="ext4"
    /dev/sda5: UUID="93d5cd61-cc4f-4251-8d8d-060adb500b5e" TYPE="swap"
    /dev/sdb1: UUID="5b11c396-d08f-4b24-a2ac-081f0a65a7dd" TYPE="ext4"
    /dev/sdb5: UUID="eed9ce7f-b2f4-47db-88ae-42e5eeea7b1d" TYPE="swap"



    edit fstab and right before

    Zitat

    # >>> [openmediavault]

    add the following

    Zitat

    UUID=5b11c396-d08f-4b24-a2ac-081f0a65a7dd /mirror ext4 errors=remount-ro 0 1


    Be sure that you change the uuid with yours.


    mount the second disk

    Zitat

    mount -a


    we make a file excudes.cfg in root directory with the name excudes.cfg. This is the file that we are going to use to exclude some directories in the rsync process.

    Zitat

    vi /excludes.cfg


    Zitat

    /mirror/
    /tmp/
    /sys/
    /proc/
    /mnt/


    sync the disks with the following command

    Zitat

    rsync -ax --exclude-from=/excludes.cfg --delete / /mirror/


    make the directories that we have excluded in the excludes.cfg

    Zitat

    mkdir /mirror/tmp
    mkdir /mirror/sys
    mkdir /mirror/proc
    mkdir /mirror/mnt


    Edit the fstab file in the mirror disk

    Zitat

    vi /mirror/etc/fstab


    and change the uuid to much the uuid for sdb1 and sdb5 and remove the mount point that we have created for the /mirror in my case the fstab looked like this


    after the changes looked like this




    Now we have to make some changes to grub2 so we can boot from the other disk


    Code
    grub-mkdevicemap


    We edit /etc/grub.d/40_custom to add a menu list in grub

    Zitat

    vi /etc/grub.d/40_custom


    and we add at the bottom the following. Be careful and change this statement set root=(hd1,1) and uuids accordingly with your setup. You can see the device map if you edit the /boot/grub/device.map.



    Then update grub2

    Zitat

    update-grub2


    After that edit again the excludes.cfg and add the following in the bottom

    Zitat

    /etc/grub.d/
    /boot/grub/grub.cfg


    in the end excludes.cfg should be like this


    Now we should be able to reboot and boot from the backup disk


    After you boot from the backup disk you will make the following changes so the backup disk should work even if the first disk is destroyed complete and you have to boot the backup disk without the first disk.


    edit the 40_custom file

    Zitat

    vi /etc/grub.d/40_custom


    and change the statement set root=(hd1,1) to set root=(hd0,1)
    Again change this accordingly your setup


    Last thing update the grub2 on the backup disk

    Zitat

    grub-mkdevicemap
    update-grub
    grub2-install /dev/sdb


    Now you should be able to boot from your backup device even if you remove your primary disk. You could also make cron job in your primary setup to sync your setups.


    One thing is missing if you make a change in omv that involves the fstab you will have to manual edit the fstab in the mirror disk and add the values. I hope that someone gives us a script that we can include with rsync and make it fully automated. ;)
    I don t know if i am asking to much and if this possible but it could be a nice if someone could make a plugin that does the same thing.


    Thanks an sorry if my English are bad

  • chente

    Hat das Thema geschlossen.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!