6.5 Archives and Compression: tar, gzip, zip
tar -czvf site-backup.tar.gz /var/www/html # create gzip archive (c=create z=gzip v=verbose f=file)
tar -tzvf site-backup.tar.gz # list contents
mkdir -p /tmp/restore
tar -xzvf site-backup.tar.gz -C /tmp/restore # extract into a folder
tar -cJvf logs.tar.xz /var/log/nginx # xz compression (smaller, slower)
gzip big.log # -> big.log.gz gunzip big.log.gz
zip -r site.zip mysite/ # install package 'zip' if missing
unzip site.zip -d /var/www/html/ # install package 'unzip' if missing
Why this matters for security
Backups are your last defence against ransomware and mistakes – but a site-backup.tar.gz left inside the web root can be downloaded by anyone who guesses the name. Directory brute-forcing tools (Gobuster, Part 10) look for exactly such files.
Ravindra Bagale's Tip
tar -xzvf karnyapurvi khup students -tzvf ne aat kay aahe te baghat nahit aani files chukichya jaagi pasartat. Aadhi list kara, mag -C ne folder deun extract kara. Aani backup kadhi web root madhe thevu naka.
Practice task
Archive ~/labs into labs.tar.gz, list its contents, and extract it into /tmp/restore.