Replacing a failed drive in a zfs pool

So I can look it up later:

When a drive that is part of a zfs pool fails and has already been physicall replaced in the server. zpool status looks like this:

user@server:~$ zpool status
  pool: main
 state: DEGRADED
status: One or more devices could not be used because the label is missing or
        invalid.  Sufficient replicas exist for the pool to continue
        functioning in a degraded state.
action: Replace the device using 'zpool replace'.
   see: https://openzfs.github.io/openzfs-docs/msg/ZFS-8000-4J
  scan: scrub in progress since Sun Feb 12 23:59:02 2023
        68.2T scanned at 1.47G/s, 64.7T issued at 205M/s, 96.1T total
        0B repaired, 67.31% done, 1 days 20:34:16 to go
config:

        NAME                                   STATE     READ WRITE CKSUM
        main                                   DEGRADED     0     0     0
          raidz2-0                             DEGRADED     0     0     0
            ata-ST18000NM000J-2TV103_WR501JXR  ONLINE       0     0     0
            ata-ST18000NM000J-2TV103_WR501JJR  ONLINE       0     0     0
            ata-ST18000NM000J-2TV103_WR501KYR  ONLINE       0     0     0
            11816660365291793896               UNAVAIL      0     0     0  was /dev/disk/by-id/ata-ST18000NM000J-2T03_WR5008VR-part1
            ata-ST18000NM000J-2TV103_WR501JZR  ONLINE       0     0     0
            ata-ST18000NM000J-2TV103_ZR5BTZGR  ONLINE       0     0     0
            ata-ST18000NM000J-2TV103_WR501LDR  ONLINE       0     0     0
            ata-ST18000NM000J-2TV103_WR501L9R  ONLINE       0     0     0

Logically replacing that failed (and removed) disk with the a new one is done with zpool replace:

user@server:~$ sudo zpool replace main 11816660365291793896 /dev/disk/by-id/ata-ST18000NM000J-2TV103_ZR5BTZHR

Where the long number is the one given in that status for the missing disk.
Make sure that the new device given is actually the new disk.

Once that is done, resilvering the pool will start automatically and zpool status will show something like this:

user@server:~$ zpool status
  pool: main
 state: DEGRADED
status: One or more devices is currently being resilvered.  The pool will
        continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
  scan: resilver in progress since Wed Feb 15 11:19:16 2023
        916G scanned at 2.67G/s, 2.94G issued at 8.78M/s, 96.1T total
        0B resilvered, 0.00% done, no estimated completion time
config:

        NAME                                     STATE     READ WRITE CKSUM
        main                                     DEGRADED     0     0     0
          raidz2-0                               DEGRADED     0     0     0
            ata-ST18000NM000J-2TV103_WR501JXR    ONLINE       0     0     0
            ata-ST18000NM000J-2TV103_WR501JJR    ONLINE       0     0     0
            ata-ST18000NM000J-2TV103_WR501KYR    ONLINE       0     0     0
            replacing-3                          DEGRADED     0     0     0
              11816660365291793896               UNAVAIL      0     0     0  was /dev/disk/by-id/ata-ST18000NM000J-2TV103_WR5008VR-part1
              ata-ST18000NM000J-2TV103_ZR5BTZHR  ONLINE       0     0     0
            ata-ST18000NM000J-2TV103_WR501JZR    ONLINE       0     0     0
            ata-ST18000NM000J-2TV103_ZR5BTZGR    ONLINE       0     0     0
            ata-ST18000NM000J-2TV103_WR501LDR    ONLINE       0     0     0
            ata-ST18000NM000J-2TV103_WR501L9R    ONLINE       0     0     0

errors: No known data errors

Once resilvering has finished, the “replacing-3” multiline entry will be changed into a normal drive list entry with the new drive.