ddrescue is the better option.
it has an option to specify a log file that saves its state in the event the system shuts down, or if you happen to hit a bad area of the disk that causes the controller to stall.
may wanna check to see if your mobo supports sata hotplugging and make sure its enabled, or if you’ve got a usb enclosure or dock that is an option as well.
i don’t wanna bother with looking up the syntax but ive done it enough to have muscle memory for it, checking the manpages wouldn’t hurt, it may have useful options for your use case.
sudo ddrescue -P -f /dev/sd(x) /path/to/image/or/output/disk recovery.log
P shows a data preview so you know if its stalled, or gotten close to the end of the disk and is just copying zeros if you wanna cut it off short. If i remember correctly f is force overwrite if the destination file exists already
if the drive stalls, disconnect power , wait ~10 seconds ddrescue will exit due to input disappearing.
then replug the drive, wait a few seconds for the device node to pop back up, then re-run the ddrescue command
if you have multiple drives in your system that aren’t always mounted, or if you happen to plug in a flashdrive or something while its running you might wanna check your device node (sda,sdb,sdc) to make sure when it enumerates the drive after hotplugging it has the same node before hitting enter - if not update it to whatever the new node is, (previously sdd, now its sdf) gnome-disk-utility is a easy gui to check (lists drive model/capacity/serial and node /dev/sd(x))
repeat until dd has rescued 99.99% of the drive, or until the drive wont wake up after hotplugging or just starts clicking ( if its a platter drive)
Then run testdisk/photorec against the cloned image or output disk.
ssds don’t actually self scrub as often as youd think, due to having a finite number of writes. you can still recover stuff from SSDs - but deleting and then overwriting is a lot more damaging on a SSD because it cant erase a partial block only the entire block - so smaller files will get steamrolled quicklly.
trimming the drive essentially just updates the firmwares internal “map” of allocated blocks to match up with the MFT.
the fact that the drive disconnects when it gets to recup_dir.10 is either the drive having a issue - or the drive is fine and you’re running out of space on your recovery directory. -also- you should be saving the recovered data to a physically different drive (or partition) than the one your recovering it from - if not you’re just overwriting stuff you’re hoping to recover
cloning only free space “is” possible, but in most pratical cases isn’t. disks don’t write from start to finish, especially SSDs.
say for example you’re writing a 500MB file, the drive is going to lay it down on in the first spot where there is 500MB of free space.
because files are created and deleted at different times (temp files/etc)- you end up with fragmentation.
on ssds it gets more complicated because the firmware on the drive tries to “wear” the flash cells evenly, so it sort of does try to start at the beginning and go to the end - and wraps around. but again files are created and deleted in different orders so its not guaranteed that free space lies after the last file written to disk.
if the drive were defragmented offline and compacted or made contiguous beforehand, you totally could just clone the free space on the drive with regular DD. there are tools for vms/multiboot/odd use cases that can pack a filesystem down to where everything is laid out with no gaps and then just a big block of free space at the end of the drive… but running a tool like that after an accidental deletion/filesystem corruption/“bad event” is almost going to guarantee you aren’t going to recover anything useful.
on that thought though- photorec, if dealing with a filesystem it knows how to work with well enough will offer an option to try to recover files only from free space on the drive.
testdisk/photorec support a lot of “optional” stuff depending on what development libraries are installed at build time. IIRC most debian/ubuntu builds of testdisk/photorec don’t support hfs all that well - install the dev packages and then build testdisk from source - may wanna check the package recommends for hints or the testdisk wiki.