Partclone provides utilities to backup a partition smartly and it is designed for higher compatibility of the file system by using existing library. For more information please check partclone.org.
Usage: https://github.com/Thomas-Tsai/partclone/wiki
Source Code: https://github.com/Thomas-Tsai/partclone