
XZ COMPRESSION 7Z ARCHIVE

Please note that we removed the J option here because –use-compress-program already sets the compression program.ĭecompressing a tar archive with xz is also a single step and identical to gzip (except for the different file extension): tar xvf Here, we specify the minimum compression level 1: tar cvf -use-compress-program='xz -1' *.csv We use this option to set the compression level, too. Tar allows setting the compression program through the –use-compress-program option. Which xz compression level does tar pick? It depends on our version of tar, but it probably is the default compression level 6. Unlike xz and gzip, tar doesn’t delete the input files after it creates the archive.Because of the v option, tar shows which files are added to the archive.The J option enables compression with xz.We compress all files with a csv extension in the current directory into the compressed archive,.Shrinking the filesystem also allows you to decompress it for loop-mounting without needing as large a drive, so you can access the files in the image and test the validity of the backup without needing to restore it. If the source drive is an SSD, mounting it temporarily to run fstrim prior to taking the image should zero-fill unused areas of the filesystem, making it easier to compress as well. If you do this, be sure to resize it back once you're done backing it up or restoring the image. resize2fs -M /dev/nvme0n1p3), then dd only the actual length of the filesystem (e.g. To further shrink the resulting image, you can shrink the underlying filesystem (e.g. Note that xz -z9e requires about 1 GB of memory per thread, so you might want to use fewer threads. The above assumes that the source partition is nvme0n1p3 and the system has 16 hardware threads (as in an 8C/16T processor) replace these values as appropriate. This is what I do: dd if=/dev/nvme0n1p3 | xz -z9eT16 > Also, adding bs=32M or with some other non-default values may significantly speed up the process. Sudo dd if=/dev/sda1 bs=32M | 7z a -si /data/$(date +%Y%m%d_%H%M%S)_sda1-backup.tar.7zħz utilizes all CPU cores.

dd is a very dangerous command, use of instead of if and you end up overwriting what you are trying to backup!! Notice how the keys o and i are next to each other? So be very very very careful.Do you really need an image of the partition, there might be better backup strategies?.Take also a look at the other answer by andreas But you should do your own testing, as performance is influenced by many factors. Here is a link to someone who did some speed benchmarks with different block sizes.

Or, use root to create a folder in /media/disk which you have permissions for.Īnalogous to a buffer. If you want it to apply to the redirection, then run the shell as root so all the children process are root as well: sudo bash -c "dd if=/dev/sda2 | gzip > /media/disk/sda2-backup-10august09.gz"Īlternatively, you could mount the disk with the uid / gid mount options (assuming ext3) so you have write permissions as whatever user you are. Do you have access to the sda2-backup.gz file? Sudo only works with the command after it, and doesn't apply to the redirection.
