Introduction
Creating a compressed backup of a website or server directory is an important part of a reliable maintenance routine. On Linux, a combination of tar, pv, and pigz can create a compressed archive while showing progress and using multiple CPU cores for faster compression.
This guide demonstrates how to back up a www directory and save the result as www-backup.tar.gz.
1. Install the Required Tools
Update the package list and install pigz and pv:
sudo apt update
sudo apt install pigz pvpigzis a parallel implementation of gzip that can use multiple CPU cores.pvdisplays the progress and transfer rate of data moving through a pipeline.taris commonly available on Linux systems and is used to create the archive.
2. Go to the Backup Directory
Move to the folder where you want to save the backup archive:
cd /mnt/c/Server/NovemberThe path above is an example of a mounted Windows drive in WSL. Use the correct destination path for your own Linux server or WSL environment.
3. Run the Backup Command
Run the following command:
sudo tar -cf - www | pv | pigz > www-backup.tar.gzThis command creates the archive and compresses it through a pipeline. The original www folder remains intact.
4. Understand the Command
tar -cf - www
tar -cf - wwwThis creates an archive from the www directory and sends the archive to standard output instead of writing an intermediate .tar file to disk.
pv
pvpv passes the archive data through while displaying useful information such as progress, transfer speed, and the amount of data processed.
pigz
pigzpigz compresses the incoming archive using multiple CPU cores. This can be faster than traditional single-threaded gzip, depending on the server hardware and the files being compressed.
> www-backup.tar.gz
> www-backup.tar.gzThe redirection operator writes the compressed output to a file named www-backup.tar.gz.
5. Verify the Backup File
After the command finishes, check that the archive exists and inspect its size:
ls -lh www-backup.tar.gzA successful result should show the backup filename, file permissions, owner, timestamp, and human-readable file size.
Optional: Test the Archive Contents
You can list the contents of the archive without extracting it:
tar -tzf www-backup.tar.gzTo test the archive's gzip and tar integrity without extracting files, use:
tar -tzf www-backup.tar.gz > /dev/nullIf the command completes without an error, the archive can be read successfully by tar.
Important Backup Notes
- Make sure the destination has enough free disk space.
- Avoid saving the only copy of a backup on the same disk as the original data.
- Consider copying completed backups to external storage or another server.
- Check file ownership and permissions before restoring files.
- Do not interrupt the command while the archive is being written.
- For production data, schedule regular backups and periodically test restoration.
Conclusion
The tar, pv, and pigz combination provides a practical way to create a compressed Linux backup while monitoring progress. The workflow creates www-backup.tar.gz, leaves the original www directory unchanged, and can be adapted for other folders and backup destinations.
Source: BRR NETWORK

Be the first to comment.