I used the following alias to back up my root directory on Ubuntu 22.04 LTS to an external flash drive
alias backup='sudo rsync -aAXHS --info=progress2 --delete --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*", "/USBDrive", "/lost+found"} / /USBDrive && notify-send -t 10000 "Backup complete"'
The file system on my usb drive is ext4.
I realize this probably isn't the best way but I was running into some issues and needed to reinstall to see if I could correct the issues.
I came across the following articles and will probably try them in the future as they appear much easier
Copy the entire root directory (/) for transferring OS to new computer?
Backup and restore of root file system (Ubuntu 20.04)
So my question is, what is recommended with the backup I have currently? From what I've read, it looks like a lot of hassle to restore the root directory. Unless someone knows of a fairly easy way to do so, I think I'll just restore the home directory. I'm looking for a way to backup and restore the home directory on any linux distribution (preferably without having to install anything else: this was the motivation for using the rsync command). Is it really just as easy as reversing the source and destination in the rsync command to restore after reinstalling the same OS on the same computer and what if I'm transferring to a new distribution that doesn't have the same parent, e.g. Debian vs Arch Linux? I also have git repositories that I cloned to my home directory. I'm not sure if this makes any difference and if this is normal practice with repositories. I'm also unsure if I will retain the packages installed with apt package manager from my backup if restoring on Ubuntu 22.04 LTS.
Update:
roaima's answer worked for me using a live disk after mounting the target disk. This didn't retain the packages installed with the apt package manager but I expected this. Therefore, you will have to rebuild programs from git repositories. If moving to another OS with a different parent, ex. Arch Linux, the root directory tree is different so I'm not sure if you're restoring more than the home directory.