Compress directory for backup

Id like to compress var/www/all sites for backup. What would the command line be to compress them and all sub folders. thanks


Solution 1:

You can do this with tar and a few convenient options:

tar -zcvf backup.tar.gz /var/www

The -zcvf option list breaks down like this:

  • -z: Gzip the archive
  • -c: create archive
  • -v: verbose mode (show you what’s happening)
  • -f: set the file name

If you choose to automate this, you can include the current date in the file name like this:

tar -zcvf backup-$(date '+%Y-%m-%d').tar.gz /var/www