Clone backup USB disk containing snapshots

naser66

Cadet
Joined
Sep 8, 2020
Messages
2
Hello

I have two freenas server. Both are FreeNAS-11.3-U4.1.

Live nas
- Performs daily snapshots. Retention time is 30 days.
- Performs daily replication to backup nas to the internal disks (Dataset: Backup)
- Performs daily replication to backup nas to the usb disk (Dataset: USB)

Backup nas
- Contains only the snapshots from the live nas
- These snapshots are on the internal disks (Dataset: Backup)
- These snapshots are also on the usb disk (Dataset: USB)
- In reality there are two usb disks but only one of them is connected for 28 days to the backup nas. After 28 days the usb disk will be replaced by the other usb disk. Then the missing 28 snapshots will automatically replicate from the live nas.

These works great as long the admin (me) swaps the usb disks not later than the snapshot retention time of the live nas (30 days). Unfortunately today i missed to swap the usb disks by one day. The replication from the live nas to the backup nas to the usb disk works great but since there is a hole of one day, the replication process created a new base on the usb disk and replicated the last 30 days.

Long story short: I lost all the data of the last two years on this specific usb disk and have only the last 30 days.

This is not especially bad, because the snapshots oft he last two years are also on the internal disks of the backup nas and also on the other usb disk of the backup nas.

I need a way to copy/duplicate the data from the internal backup dataset or the usb disk to the usb disk wich lost the data.

The dataset name of both usb disks is “USB”. But they have different pool ids. So cloning the good usb disk to the bad usb disk with a cloning tool will create problems as long I don’t know where to alter the pool id on the cloned disk.

Replication from the backup nas (good usb disk) to the backup nas (bad usb disk) wants to created a new replication base. This is not helpful. The replication after the restore should still be from live nas to backup nas.

Has anone an idea how to populate the usb disk which lost the snapshots with the snapshots of the internal disks or the snapshot of the other usb disk?

Kind Regards

Naser66
 

naser66

Cadet
Joined
Sep 8, 2020
Messages
2
- Connect the GOOD usb disk to the system.
- Import the pool.
- Identify the partition of the zfs system. da0 is the usb disk.

Code:
root@freenas-backup[~]# gpart show
=>        40  1953525088  ada0  GPT  (932G)
          40        1024     1  freebsd-boot  (512K)
        1064  1953524064     2  freebsd-zfs  (932G)

=>        40  7814037088  ada1  GPT  (3.6T)
          40          88        - free -  (44K)
         128     4194304     1  freebsd-swap  (2.0G)
     4194432  7809842696     2  freebsd-zfs  (3.6T)

=>        40  7814037088  ada2  GPT  (3.6T)
          40          88        - free -  (44K)
         128     4194304     1  freebsd-swap  (2.0G)
     4194432  7809842696     2  freebsd-zfs  (3.6T)

=>        40  7813969840  da0  GPT  (3.6T)
          40          88       - free -  (44K)
         128     4194304    1  freebsd-swap  (2.0G)
     4194432  7809775448    2  freebsd-zfs  (3.6T)
   
root@freenas-backup[~]# 


- get the gptid of the zfs partition of the usb disk. da0p2 ist the zfs partition

Code:
root@freenas-backup[~]# glabel status
                                      Name  Status  Components
gptid/a794eaae-0d1f-11e9-a0cc-001999af2455     N/A  ada0p1
gptid/f0c65bb3-10d2-11e9-ba98-001999af2455     N/A  ada1p2
gptid/f1abad91-10d2-11e9-ba98-001999af2455     N/A  ada2p2
gptid/68b36675-6401-11e9-ac68-001999af2455     N/A  da0p2

root@freenas-backup[~]#

- Connect the usb disk with the lost data to the system.
- Identify the partition of the zfs system of the second connected usb disk. da1 is the second usb disk.

Code:
root@freenas-backup[~]# gpart show
=>        40  1953525088  ada0  GPT  (932G)
          40        1024     1  freebsd-boot  (512K)
        1064  1953524064     2  freebsd-zfs  (932G)

=>        40  7814037088  ada1  GPT  (3.6T)
          40          88        - free -  (44K)
         128     4194304     1  freebsd-swap  (2.0G)
     4194432  7809842696     2  freebsd-zfs  (3.6T)

=>        40  7814037088  ada2  GPT  (3.6T)
          40          88        - free -  (44K)
         128     4194304     1  freebsd-swap  (2.0G)
     4194432  7809842696     2  freebsd-zfs  (3.6T)

=>        40  7813969840  da0  GPT  (3.6T)
          40          88       - free -  (44K)
         128     4194304    1  freebsd-swap  (2.0G)
     4194432  7809775448    2  freebsd-zfs  (3.6T)

=>        40  7813969840  da1  GPT  (3.6T)
          40          88       - free -  (44K)
         128     4194304    1  freebsd-swap  (2.0G)
     4194432  7809775448    2  freebsd-zfs  (3.6T)

root@freenas-backup[~]#


- get the gptid of the zfs partition of the second usb disk. da1p2 ist the zfs partition.


Code:
root@freenas-backup[~]# glabel status
                                      Name  Status  Components
gptid/a794eaae-0d1f-11e9-a0cc-001999af2455     N/A  ada0p1
gptid/f0c65bb3-10d2-11e9-ba98-001999af2455     N/A  ada1p2
gptid/f1abad91-10d2-11e9-ba98-001999af2455     N/A  ada2p2
gptid/68b36675-6401-11e9-ac68-001999af2455     N/A  da0p2
gptid/687dd7a1-6401-11e9-ac68-001999af2455     N/A  da0p1
gptid/753cb8e2-6bf2-11e9-90fe-001999af2455     N/A  da1p1
gptid/75730b52-6bf2-11e9-90fe-001999af2455     N/A  da1p2
root@freenas-backup[~]#


- Add the second usb disk as a mirror

IMPORTANT: zpool attach needs the origin disk and the target disk as parameters. The sequence of both parameters is FIRST the ORIGIN disk then the TARGET disk. So the command knows in which direction to mirror -> From origin to target. If you use the disk with the lost data as origin you end up with two useless disks.

Code:
zpool attach -f USB gptid/68b36675-6401-11e9-ac68-001999af2455 gptid/75730b52-6bf2-11e9-90fe-001999af2455


- Wait until the resilver process is terminated. Depending of the amount of data this can take hours / days.
- After the resilver process is terminated split the mirror into two pools. The imported pool of the origin disk is USB. The pool name for the target disk is USB2.

Code:
zpool split USB USB2


- export the USB pool. The USB2 pool should not be imported at this stage. If it is, export it also.

Code:
zpool export USB


zpool export USB2 (if it is imported)

- Import the disk with the new pool and rename it with the original pool name. In my case from USB2 to USB.

Code:
zpool import USB2 USB


Starting from this moment you have two usb disks with the same content on the zfs partition. Each disk represents the USB pool. This setup is what I needed. Its only for the use case you see at the beginning of the thread.

OFF TOPIC:
- If you have an empty TARGET disk then first you have to create the partitions I guess.
- It's not possible to have both usb disks imported at the same time, because both disks have the same pool name. For my use case it's what I need so the replication process from master nas to backup nas is working flawlessly.
 
Top