Make sure the if
value is correct! If doing this over SSH then open a TMUX session first... or else...
dd if=/dev/YOUR-DEVICE conv=sync,noerror bs=64K | gzip -c > /home/portaj/macbook.img.gz
NOTE: You might not want to compress the image. It just means you have to uncompress it later to mount it. If you're planning to access the data soon, or frequently, don't compress it.
Save it in the same directory as the compressed image so later on if you decide you want to mount or extract data from the image you can see the partition structure without having to decompress the whole image. There might be some other ways to mount a compressed image.